[Image-SIG] manipulate 16 bits Grey matrix

Alex Clark aclark at aclark.net
Tue Jan 29 16:14:16 CET 2013


On 2013-01-28 16:53:44 +0000, Jean-Baptiste BUTET said:

> Hi all,
> 
> I have a 1394 cam that has a 16 bit greyscale output.
> 
> How can I handle this under PIL ?
> 
> Matrix has this shape : [ [  ][  ] [  ]...] and come frome libdc1394
> wrapper. 8 bit is well recognise and treated :
> ---------8 Bits----------
> 
> matrix = cam0.current_image
> i = Image.fromarray(matrix)
> 
> i.save("mypicture.jpg") (or png, or bmp ...)
> 
> ---------16 bits----------
> (code found somewhere)
>     matrix = cam0.current_image
>     if j ==0 :
>         print matrix.size, len(matrix[0]),type(matrix)
> 
>     ## 'F' correspond au mode de conversion : F pour Float, bien sûr
> ## [667,800] est la taille de l'image à créer, dans mon cas
> 
>         img = Image.fromstring('F',[480,640], matrix)
>         nom = "t"+str(j)+".tif"
>         tiff = nom
>         fim = open(tiff, 'wb')
> 
> ## Et conversion en entiers, en précisant le nombre de couleurs...
>         img = img.convert('I', colors=65536)
> 
> ## Sauvegarde au format TIFF. BMP, JPEG, PNG ne sont pas compatibles
> ## avec le format des données
>         img.save(fim, 'tiff')
> 
>         fim.close()
> ----------------------------
> ---> result
> Mode: 640x480_Y16    <- 16 bits OK for cam !
> Framerate:  30
> 307200 640 <class 'pydc1394.camera.Image'>   <-  lenght of string, width
> Traceback (most recent call last):
>   File "16save_image.py", line 78, in <module>
>     img = Image.fromstring('F',[481,641], matrix)
>   File "/usr/lib/python2.7/site-packages/PIL/Image.py", line 1797, in 
> fromstring
>     im.fromstring(data, decoder_name, args)
>   File "/usr/lib/python2.7/site-packages/PIL/Image.py", line 594, in fromstring
>     raise ValueError("not enough image data")
> ValueError: not enough image data
> 
> 
> I really don't see what the problem...
> 
> Thanks for response.


Does it happen with Pillow too? If so, please report the issue here: 
https://github.com/python-imaging/Pillow/issues


> 
> JB
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig


-- 
Alex Clark · https://www.gittip.com/aclark4life/




More information about the Image-SIG mailing list