PIL 1.1.6 can't convert 16-bit (I; 16) to 8-bit ('L')--Windows 32-bit

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

PIL 1.1.6 can't convert 16-bit (I; 16) to 8-bit ('L')--Windows 32-bit

Karl Garsha-2
Greetings,

I'm reading in a 16-bit monochrome image using PIL on windows and can't seem to work with the resulting image object.

I've confirmed the image data is good..I can open and view it with ImageJ and the dimensions are correct.

I'm using PIL 1.1.6 as part of the Enthought Python distribution...I'm stumped. I've appended relevant code I'm trying with my interpreter below:

I'm hoping perhaps someone can help...I need to take 16-bit monochrome images (*.tiff in this case) and get them into 8-bit space...thanks in advance for any insight into what I can do to solve this.

print im.mode,im.size
I;16 (832, 656)

print im.getextrema()
None # this doesn't seem right....can PIL 1.1.6 apply this method to 16-bit unsigned int image objects?

lut=[]
len(lut)
0
for i in range (65536):
    lut.append(int(i/256))
   
len(lut)
65536

im3=im.point(lut,'L')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Python26\lib\site-packages\PIL\Image.py", line 1109, in point
    return self._new(self.im.point(lut, mode))
ValueError: wrong number of lut entries

_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: PIL 1.1.6 can't convert 16-bit (I; 16) to 8-bit ('L')--Windows 32-bit

Edward Cannon-2
How I would convert the image is im.convert("L") I have had success
using this method for a variety of less common formats, and it handles
all the conversion for you.
Edward

On Sun, Feb 28, 2010 at 7:50 PM, Karl Garsha <[hidden email]> wrote:

> Greetings,
>
> I'm reading in a 16-bit monochrome image using PIL on windows and can't seem
> to work with the resulting image object.
>
> I've confirmed the image data is good..I can open and view it with ImageJ
> and the dimensions are correct.
>
> I'm using PIL 1.1.6 as part of the Enthought Python distribution...I'm
> stumped. I've appended relevant code I'm trying with my interpreter below:
>
> I'm hoping perhaps someone can help...I need to take 16-bit monochrome
> images (*.tiff in this case) and get them into 8-bit space...thanks in
> advance for any insight into what I can do to solve this.
>
> print im.mode,im.size
> I;16 (832, 656)
>
> print im.getextrema()
> None # this doesn't seem right....can PIL 1.1.6 apply this method to 16-bit
> unsigned int image objects?
>
> lut=[]
> len(lut)
> 0
> for i in range (65536):
>     lut.append(int(i/256))
>
> len(lut)
> 65536
>
> im3=im.point(lut,'L')
> Traceback (most recent call last):
>   File "<input>", line 1, in <module>
>   File "C:\Python26\lib\site-packages\PIL\Image.py", line 1109, in point
>     return self._new(self.im.point(lut, mode))
> ValueError: wrong number of lut entries
>
> _______________________________________________
> Image-SIG maillist  -  [hidden email]
> http://mail.python.org/mailman/listinfo/image-sig
>
>
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: PIL 1.1.6 can't convert 16-bit (I; 16) to 8-bit ('L')--Windows 32-bit

Fredrik Lundh
In reply to this post by Karl Garsha-2
PIL has very limited support for the I;16 and I;16L modes; it's
usually best to convert them to mode I (or F) and move on from there.
Try doing:

  im = im.convert("I")

before applying getextrema and point(lut, "L") to the image.

</F>

On Mon, Mar 1, 2010 at 4:50 AM, Karl Garsha <[hidden email]> wrote:

> Greetings,
>
> I'm reading in a 16-bit monochrome image using PIL on windows and can't seem
> to work with the resulting image object.
>
> I've confirmed the image data is good..I can open and view it with ImageJ
> and the dimensions are correct.
>
> I'm using PIL 1.1.6 as part of the Enthought Python distribution...I'm
> stumped. I've appended relevant code I'm trying with my interpreter below:
>
> I'm hoping perhaps someone can help...I need to take 16-bit monochrome
> images (*.tiff in this case) and get them into 8-bit space...thanks in
> advance for any insight into what I can do to solve this.
>
> print im.mode,im.size
> I;16 (832, 656)
>
> print im.getextrema()
> None # this doesn't seem right....can PIL 1.1.6 apply this method to 16-bit
> unsigned int image objects?
>
> lut=[]
> len(lut)
> 0
> for i in range (65536):
>     lut.append(int(i/256))
>
> len(lut)
> 65536
>
> im3=im.point(lut,'L')
> Traceback (most recent call last):
>   File "<input>", line 1, in <module>
>   File "C:\Python26\lib\site-packages\PIL\Image.py", line 1109, in point
>     return self._new(self.im.point(lut, mode))
> ValueError: wrong number of lut entries
>
> _______________________________________________
> Image-SIG maillist  -  [hidden email]
> http://mail.python.org/mailman/listinfo/image-sig
>
>
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig