f



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

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
0
10/31/2009 3:43:45 PM
comp.lang.python 77058 articles. 5 followers. Post Follow

1 Replies
1878 Views

Similar Articles

[PageSpeed] 18

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 )-:
> 
> 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
0
xstgavin124
2/12/2014 10:27:44 AM
Reply:

Similar Artilces:

""""""""""""""""""""""ADD ME""""""""""""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfo Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... We look forward to build a ve...

"""""""""ADD ME""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfoi Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... ...

Replacing "RADIO" with "RADIO" NAME="1" VALUE="1", etc..
I am running code below so that "RADIO" gets replaced by "RADIO" NAME="1" VALUE="1" etc. Actually there are 5 RADIO buttons for each question, and the initial web page I generate somehow dord not have NAME="1" VALUE="1", etc. after "RADIO". So I am using Perl to replace simple "RADIO" with "RADIO" NAME="1" VALUE="1", "2", "3", "4", and "5" and for the choices for the problem number 2, "RADIO" NAME="2" VALUE="1", &q...

a = [ "1", "2", "3" ] v/s a = new Array ( "1", "2", "3" ) identical in all ways?
Do these result in identical objects? a = [ "1", "2", "3" ] a = new Array ( "1", "2", "3" ) On Aug 25, 1:30=A0pm, okey wrote: > Do these result in identical objects? > > a =3D [ "1", "2", "3" ] > a =3D new Array ( "1", "2", "3" ) Yes, but:- a =3D [ 2 ]; a =3D new Array( 2 ); - do not. Richard. okey wrote: > Do these result in identical objects? > > a = [ "1", "2", "3" ] > a = new Array ( "1", "2"...

Urgent Requirement in """""""""""""NEW YORK""""""""""""""""
Hello Partners, Please find the requirement below. Please send the updated resume along with rate and contact no. REQ#1: Title : Java Developer ( Rating Project) Duration : 6 months Rate : open Location : NY strong java, WebLogic 9.2, Web Services, Oracle REQ#2: Title : Java Developer Duration : 4 months Rate : open Location : NY Strong java, SQL REQ#3: Title : VB.Net Consultant Location : NY Duration : 4 months Rate : open Primarily looking at someone who has Excel, VB.net a...

about "++" and "--"
why this program snippet display "8,7,7,8,-7,-8" the program is: main() { int i=8; printf("%d\n%d\n%d\n%d\n%d\n%d\n",++i,--i,i++,i--,-i++,-i--); } > why this program snippet display "8,7,7,8,-7,-8" Ask your compiler-vendor because this result is IMHO implementation-defined. Check this out: http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.15 http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.16 Regards, Irina Marudina fxc123@gmail.com wrote: > why this program snippet display "8,7,7,8,-7,-8&q...

"/a" is not "/a" ?
Hi everybody, while testing a module today I stumbled on something that I can work around but I don't quite understand. >>> a = "a" >>> b = "a" >>> a == b True >>> a is b True >>> c = "/a" >>> d = "/a" >>> c == d True # all good so far >>> c is d False # eeeeek! Why c and d point to two different objects with an identical string content rather than the same object? Manu Emanuele D'Arrigo wrote: >>>> c = "/a" >>>&...

"out" and "in out"
Hi i found the following explaination: In Ada, "in" parameters are similar to C++ const parameters. They are effectively read-only within the scope of the called subprogram. Ada "in out" parameters have a reliable initial value (that passed in from the calling subprogram) and may be modified within the scope of the called procedure. Ada "out" parameters have no reliable initial value, but are expected to be assigned a value within the called procedure. What does "have no reliable initial value" mean when considering the "out" parameter? By c...

"If then; if then;" and "If then; if;"
I have a raw data set which is a hierarchical file: H 321 s. main st P Mary E 21 F P william m 23 M P Susan K 3 F H 324 S. Main St I use the folowing code to read the data to creat one observation per detail(P) record including hearder record(H): data test; infile 'C:\Documents and Settings\retain.txt'; retain Address; input type $1. @; if type='H' then input @3 Address $12.; if type='P' then input @3 Name $10. @13 Age 3. @16 Gender $1.; run; but the output is not what I want: 1 321 s. main H 2 321 s. main P Mary E 21 F 3 321 s...

why "::", not "."
Why does the method of modules use a dot, and the constants a double colon? e.g. Math::PI and Math.cos -- Posted via http://www.ruby-forum.com/. On Oct 26, 2010, at 01:48 , Oleg Igor wrote: > Why does the method of modules use a dot, and the constants a double > colon? > e.g. > Math::PI and Math.cos For the same reason why inner-classes/modules use double colon, because = they're constants and that's how you look up via constant namespace. Math::PI and ActiveRecord::Base are the same type of lookup... it is = just that Base is a module and PI is a float....

"or" and "and"
Hi, I'm just getting to discover ruby, but I find it very nice programming language. I just still don't understand how the "or" and "and" in ruby... I was playing with ruby and for example made a def to print Stem and Leaf plot (for those who didn't have a statistics course or slept on it, e.g. http://cnx.org/content/m10157/latest/) Here is the Beta version of it: class Array def n ; self.size ; end def stem_and_leaf(st = 1) # if st != (2 or 5 or 10) then ; st = 1 ; end k = Hash.new(0) self.each {|x| k[x.to_f] += 1 } k = k.sort{|a, b| a[0].to_f <=&g...

"my" and "our"
Hi, while testing a program, I erroneously declared the same variable twice within a block, the first time with "my", the second time with "our": { my $fz = 'VTX_Link'; .... ( around 200 lines of code, all in the same block) our $fz = 'VTX_Linkset'; ... } So the initial contents of the $fz declared with "my" is lost, because "our" creates a lexical alias for the global $fz, thus overwriting the previous "my" declaration. It was my error, no question. But I wonder why Perl doesn't mention this - even with "use s...

Urgent Requirement for """""""""""""""INFORMATICA DEVELOPER"""""""""""""
Hello Partners, How are you ? Please find the requirements below. Title: Database/ETL Developer Duration: 6 months Location: NY Exp: 7+ Locals preferred Database/ETL requirements (Mandatory) Candidate must have worked with financial instruments, preferably Mutual Funds but, Equities are also ok. PL/SQL - packages, Stored procs, Functions, Aggregate functions, Pipelined Functions Informatica 8.6 - especially complex mappings, complex maplets, complex workflows, transformations Oracle 10g/11g Unix/Linux shell scripting ...

Urgent need """""""""""INFORMATICA DEVELOPER"""""""""""""
Hello Partners, How are you ? Please find the requirements below. Title: Database/ETL Developer Duration: 6 months Location: NY Exp: 7+ Locals preferred Database/ETL requirements (Mandatory) Candidate must have worked with financial instruments, preferably Mutual Funds but, Equities are also ok. PL/SQL - packages, Stored procs, Functions, Aggregate functions, Pipelined Functions Informatica 8.6 - especially complex mappings, complex maplets, complex workflows, transformations Oracle 10g/11g Unix/Linux shell scripting Database/ETL requirements (Optional) ...

Web resources about - PIL Image.fromarray( ... , mode="1" ) - comp.lang.python

Resources last updated: 2/2/2016 10:45:30 PM