[SciPy-dev] Fwd: should Int8 be UnsignedInt8 in misc/pilutil.py?

Albert Huang ashuang at gmail.com
Tue Jan 31 10:29:18 CST 2006


sending again

---------- Forwarded message ----------
From: Albert Huang <ashuang at gmail.com>
Date: Jan 22, 2006 11:39 PM
Subject: should Int8 be UnsignedInt8 in misc/pilutil.py?
To: scipy-dev at scipy.net

Hello,

pilutil.imread currently converts RGB images to arrays of signed integers.
I think it should be unsigned integers instead.  If you do an imshow(imread(
... ) ) on any brightly colored image, then all the RGB values > 127 get
whacked.

Also, it's probably not very intuitive to say that -1 is brighter than 127.

The attached patch fixes it for me.  I just changed all occurences of 'b' to
'B', but am not too sure what the effect is in toimage().

Regards,
Albert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-dev/attachments/20060131/90b53fc0/attachment.html 
-------------- next part --------------
Index: Lib/misc/pilutil.py
===================================================================
--- Lib/misc/pilutil.py	(revision 1581)
+++ Lib/misc/pilutil.py	(working copy)
@@ -68,7 +68,7 @@
         mode = 'L'
         adjust = 1
     str = im.tostring()
-    type = 'b'
+    type = 'B'
     if mode == 'F':
         type = 'f'
     if mode == 'I':
@@ -132,12 +132,12 @@
                 image.putpalette(asarray(pal,dtype=_UInt8).tostring())
                 # Becomes a mode='P' automagically.
             elif mode == 'P':  # default gray-scale
-                pal = arange(0,256,1,dtype='b')[:,NewAxis] * \
-                      ones((3,),dtype='b')[NewAxis,:]
+                pal = arange(0,256,1,dtype='B')[:,NewAxis] * \
+                      ones((3,),dtype='B')[NewAxis,:]
                 image.putpalette(asarray(pal,dtype=_UInt8).tostring())
             return image
         if mode == '1':  # high input gives threshold for 1
-            bytedata = ((data > high)*255).astype('b')
+            bytedata = ((data > high)*255).astype('B')
             image = Image.fromstring('L',shape,bytedata.tostring())   
             image = image.convert(mode='1')
             return image


More information about the Scipy-dev mailing list