[SciPy-User] Trying to use PIL and numpy - SOLVED-

alan@ajackso... alan@ajackso...
Wed Jan 13 21:32:04 CST 2010


>alan@ajackson.org wrote:
>> I'm having some issues trying to use PIL and numpy (for the first time).
>> It's probably something simple, it usually is.
>>
>> When I run the following, the output is all buggered up. It looks like
>> the array indicies got switched about somewhere.
>>
>> import Image
>> im = Image.open('test.ppm')
>> im2 = im.convert(mode='F')
>>
>> a = np.asarray(im2)
>> imback2 = Image.fromarray(a)
>>
>> imback = imback2.convert(mode='RGB')
>> imback.save('testout.png')
>>
>> I tried removing bits, and it is the asarray -> fromarray sequence that
>> messes stuff up.
>>
>> I'm running Karmic Koala with
>> Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15) 
>> numpy 1.3.0
>> Image 1.1.6
>>
>>
>>   
>I believe there is a logic error in the PIL 1.1.6 fromarray() procedure 
>(see 
>http://mail.scipy.org/pipermail/numpy-discussion/2006-December/024903.html) 
>that may be relevant.
>Try explicitly specifying the mode parameter in the fromarray(...) call.
> -- jv

Bingo! editing that line to

imback2 = Image.fromarray(a, mode='F')
fixes the problem.

-- 
-----------------------------------------------------------------------
| Alan K. Jackson            | To see a World in a Grain of Sand      |
| alan@ajackson.org          | And a Heaven in a Wild Flower,         |
| www.ajackson.org           | Hold Infinity in the palm of your hand |
| Houston, Texas             | And Eternity in an hour. - Blake       |
-----------------------------------------------------------------------


More information about the SciPy-User mailing list