PIL Image.fromarray( ... , mode="1" )

xstgavin124 at gmail.com xstgavin124 at gmail.com
Wed Feb 12 11:27:44 CET 2014

On Saturday, 31 October 2009 23:43:45 UTC+8, Hans Georg Schaathun  wrote:
> Does anyone know how to save two-tone images represented as
> numpy arrays?  I handle grayscale images by converting to
> PIL Image objects (mode="L") and then use the PIL save method,
> but I cannot make this work with mode="1".
> I have tried both boolean arrays and uint8 arrays (mod 2).
> In both cases I get an image which is predominantly black,
> with thin white stripes (possibly for every 8 pixels).
> If, instead, multiply my (mod 2) image by 255, and then
> convert with mode="L", I get the expected random-noise-looking
> image.
> Does anyone have any ideas?  What do I do wrong?  What is the
> right/best way to save/convert two-tone images?
> I have not managed to find proper documentation for the 
> Image.fromarray() method; the docstring seems to be empty )-:
> :-- Hans Georg

Possibly because you forget to convert the data type to unit8:
" newtemp=np.uint8(TEMP*255) "

I have encountered the same problem as you stated. After change the date type to uint8, problem solved. Hope it works. 


More information about the Python-list mailing list