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

  • Thread starter Hans Georg Schaathun
  • Start date
H

Hans Georg Schaathun

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 )-:

TIA
:-- Hans Georg
 
X

xstgavin124

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 )-:

TIA
:-- 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.

_ST
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top