[Scipy-svn] r2939 - in trunk/Lib/misc: . tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Wed Apr 25 18:51:40 EDT 2007
Author: stefan
Date: 2007-04-25 17:51:23 -0500 (Wed, 25 Apr 2007)
New Revision: 2939
Modified:
trunk/Lib/misc/pilutil.py
trunk/Lib/misc/tests/test_pilutil.py
Log:
Fix dtype comparison.
Modified: trunk/Lib/misc/pilutil.py
===================================================================
--- trunk/Lib/misc/pilutil.py 2007-04-24 22:16:11 UTC (rev 2938)
+++ trunk/Lib/misc/pilutil.py 2007-04-25 22:51:23 UTC (rev 2939)
@@ -16,13 +16,11 @@
# Returns a byte-scaled image
def bytescale(data, cmin=None, cmax=None, high=255, low=0):
- if data.dtype is uint8:
+ if data.dtype == uint8:
return data
high = high - low
- if cmin is None:
- cmin = amin(ravel(data))
- if cmax is None:
- cmax = amax(ravel(data))
+ if cmin is None: cmin = data.min()
+ if cmax is None: cmax = data.max()
scale = high *1.0 / (cmax-cmin or 1)
bytedata = ((data*1.0-cmin)*scale + 0.4999).astype(uint8)
return bytedata + cast[uint8](low)
Modified: trunk/Lib/misc/tests/test_pilutil.py
===================================================================
--- trunk/Lib/misc/tests/test_pilutil.py 2007-04-24 22:16:11 UTC (rev 2938)
+++ trunk/Lib/misc/tests/test_pilutil.py 2007-04-25 22:51:23 UTC (rev 2939)
@@ -12,5 +12,11 @@
im1 = pilutil.imresize(im,T(1.1))
assert_equal(im1.shape,(11,22))
+ def check_bytescale(self):
+ x = N.array([0,1,2],N.uint8)
+ y = N.array([0,1,2])
+ assert_equal(pilutil.bytescale(x),x)
+ assert_equal(pilutil.bytescale(y),[0,127,255])
+
if __name__ == "__main__":
NumpyTest().run()
More information about the Scipy-svn
mailing list