[Scipy-svn] r2926 - in trunk/Lib/misc: . tests

scipy-svn@scip... scipy-svn@scip...
Mon Apr 16 16:54:16 CDT 2007


Author: stefan
Date: 2007-04-16 16:54:00 -0500 (Mon, 16 Apr 2007)
New Revision: 2926

Added:
   trunk/Lib/misc/tests/
   trunk/Lib/misc/tests/test_pilutil.py
Modified:
   trunk/Lib/misc/pilutil.py
   trunk/Lib/misc/setup.py
Log:
Fix imresize, add test.


Modified: trunk/Lib/misc/pilutil.py
===================================================================
--- trunk/Lib/misc/pilutil.py	2007-04-16 17:03:07 UTC (rev 2925)
+++ trunk/Lib/misc/pilutil.py	2007-04-16 21:54:00 UTC (rev 2926)
@@ -5,7 +5,8 @@
 import tempfile
 
 from numpy import amin, amax, ravel, asarray, cast, arange, \
-     ones, newaxis, transpose, mgrid, iscomplexobj, sum, zeros, uint8
+     ones, newaxis, transpose, mgrid, iscomplexobj, sum, zeros, uint8, \
+     issubdtype, array
 
 import Image
 import ImageFilter
@@ -252,10 +253,10 @@
     """
     im = toimage(arr)
     ts = type(size)
-    if ts is types.IntType:
+    if issubdtype(ts,int):
         size = size / 100.0
-    if type(size) is types.FloatType:
-        size = (im.size[0]*size,im.size[1]*size)
+    elif issubdtype(type(size),float):
+        size = (array(im.size)*size).astype(int)
     else:
         size = (size[1],size[0])
     imnew = im.resize(size)

Modified: trunk/Lib/misc/setup.py
===================================================================
--- trunk/Lib/misc/setup.py	2007-04-16 17:03:07 UTC (rev 2925)
+++ trunk/Lib/misc/setup.py	2007-04-16 21:54:00 UTC (rev 2926)
@@ -3,6 +3,7 @@
     from numpy.distutils.misc_util import Configuration
     config = Configuration('misc',parent_package,top_path)
     config.add_data_files('lena.dat')
+    config.add_data_dir('tests')
     return config
 
 if __name__ == '__main__':

Added: trunk/Lib/misc/tests/test_pilutil.py
===================================================================
--- trunk/Lib/misc/tests/test_pilutil.py	2007-04-16 17:03:07 UTC (rev 2925)
+++ trunk/Lib/misc/tests/test_pilutil.py	2007-04-16 21:54:00 UTC (rev 2926)
@@ -0,0 +1,16 @@
+from numpy.testing import *
+set_package_path()
+import scipy.misc.pilutil as pilutil
+restore_path()
+
+import numpy as N
+
+class test_pilutil(NumpyTestCase):
+    def check_imresize(self):
+        im = N.random.random((10,20))
+        for T in N.sctypes['float'] + [float]:
+            im1 = pilutil.imresize(im,T(1.1))
+            assert_equal(im1.shape,(11,22))
+
+if __name__ == "__main__":
+    NumpyTest().run()



More information about the Scipy-svn mailing list