Re: manipulate 16 bits Grey matrix

Alex Clark <[email protected]> Tue, 29 Jan 2013 10:14:16 -0500
Newsgroups gmane.comp.python.image
Organization ACLARK.NET, LLC
Message-ID <[email protected]>
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 =3D cam0.current_image
> i =3D Image.fromarray(matrix)
> =

> i.save("mypicture.jpg") (or png, or bmp ...)
> =

> ---------16 bits----------
> (code found somewhere)
>     matrix =3D cam0.current_image
>     if j =3D=3D0 :
>         print matrix.size, len(matrix[0]),type(matrix)
> =

>     ## 'F' correspond au mode de conversion : F pour Float, bien s=FBr
> ## [667,800] est la taille de l'image =E0 cr=E9er, dans mon cas
> =

>         img =3D Image.fromstring('F',[480,640], matrix)
>         nom =3D "t"+str(j)+".tif"
>         tiff =3D nom
>         fim =3D open(tiff, 'wb')
> =

> ## Et conversion en entiers, en pr=E9cisant le nombre de couleurs...
>         img =3D img.convert('I', colors=3D65536)
> =

> ## Sauvegarde au format TIFF. BMP, JPEG, PNG ne sont pas compatibles
> ## avec le format des donn=E9es
>         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 =3D 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 from=
string
>     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  -  [email protected]
> http://mail.python.org/mailman/listinfo/image-sig


-- =

Alex Clark =B7 https://www.gittip.com/aclark4life/


_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig