manipulate 16 bits Grey matrix

Jean-Baptiste BUTET <[email protected]> Mon, 28 Jan 2013 17:53:44 +0100
Newsgroups gmane.comp.python.image
Message-ID <CANYxx=wGfVjG0ctxmM+coMDWmwvsukRv3eD+PrB9oSc_KLoXJw@mail.gmail.com>
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 froms=
tring
    im.fromstring(data, decoder_name, args)
  File "/usr/lib/python2.7/site-packages/PIL/Image.py", line 594, in fromst=
ring
    raise ValueError("not enough image data")
ValueError: not enough image data


I really don't see what the problem...

Thanks for response.

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