[Image-SIG] can't show png file with mode "I"
Fredrik Lundh
fredrik at pythonware.com
Sat Oct 8 21:19:02 CEST 2005
(stuck in the spam filter, due to excessive use of HTML. please
post plain text messages to this list if at all possible).
James Hu wrote:
> I captured image from digital camera and saved it to png file with:
>
> Image.fromstring("I", datasize, origFrame.pBuffer, 'raw', 'I;16')
>
> But when I open it with PIL.Image
>
> im=Image.open("*.png")
> Im.show()
>
> Got white image,
> What might be the problem?
I've answered this on comp.lang.python:
http://article.gmane.org/gmane.comp.python.general/424715
but here's the answer again, for the archives:
maybe all pixels in the PNG file are larger than 255 ?
show doesn't support 16-bit images, so it clamps the values down to
an 8-bit range. adding a
print im.getextrema()
will tell you what values you have in the image (it returns min and max).
to scale things down before you display it, you can use something like:
im = im.point(lambda x: x*(1.0/256))
or
lo, hi = im.getextrema()
if lo == hi:
im = im.point(lambda x: 128) # or something
else:
scale = 255.0 / (hi - lo)
offset = -lo * scale + 0.5
im = im.point(lambda x: x*scale + offset)
hope this helps!
</F>
More information about the Image-SIG
mailing list