[Scipy-svn] r6578 - in trunk/scipy/misc: . tests

scipy-svn@scip... scipy-svn@scip...
Tue Jun 29 11:06:45 CDT 2010


Author: oliphant
Date: 2010-06-29 11:06:45 -0500 (Tue, 29 Jun 2010)
New Revision: 6578

Modified:
   trunk/scipy/misc/pilutil.py
   trunk/scipy/misc/tests/test_pilutil.py
Log:
Remove duplicate imresize in pilutil.py and merge functionality.

Modified: trunk/scipy/misc/pilutil.py
===================================================================
--- trunk/scipy/misc/pilutil.py	2010-06-28 23:14:49 UTC (rev 6577)
+++ trunk/scipy/misc/pilutil.py	2010-06-29 16:06:45 UTC (rev 6578)
@@ -254,16 +254,6 @@
     im = im.rotate(angle,resample=func[interp])
     return fromimage(im)
 
-def imresize(arr,newsize,interp='bilinear',mode=None):
-    newsize=list(newsize)
-    newsize.reverse()
-    newsize = tuple(newsize)
-    arr = asarray(arr)
-    func = {'nearest':0,'bilinear':2,'bicubic':3,'cubic':3}
-    im = toimage(arr,mode=mode)
-    im = im.resize(newsize,resample=func[interp])
-    return fromimage(im)
-
 def imshow(arr):
     """Simple showing of an image through an external viewer.
     """
@@ -284,7 +274,7 @@
     if status != 0:
         raise RuntimeError('Could not execute image viewer.')
 
-def imresize(arr,size):
+def imresize(arr, size, interp='bilinear', mode=None):
     """
     Resize an image.
 
@@ -298,6 +288,12 @@
         * float - Fraction of current size.
         * tuple - Size of the output image.
 
+    interp : string
+        interpolation to use for re-sizing ('nearest', 'bilinear', 'bicubic' or 'cubic')
+
+    mode :
+        mode is the PIL image mode ('P', 'L', etc.)
+
     Returns
     -------
 
@@ -305,7 +301,7 @@
         The resized array of image.
 
     """
-    im = toimage(arr)
+    im = toimage(arr, mode=mode)
     ts = type(size)
     if issubdtype(ts,int):
         size = size / 100.0
@@ -313,7 +309,8 @@
         size = (array(im.size)*size).astype(int)
     else:
         size = (size[1],size[0])
-    imnew = im.resize(size)
+    func = {'nearest':0,'bilinear':2,'bicubic':3,'cubic':3}
+    imnew = im.resize(size, resample=func[interp])
     return fromimage(imnew)
 
 

Modified: trunk/scipy/misc/tests/test_pilutil.py
===================================================================
--- trunk/scipy/misc/tests/test_pilutil.py	2010-06-28 23:14:49 UTC (rev 6577)
+++ trunk/scipy/misc/tests/test_pilutil.py	2010-06-29 16:06:45 UTC (rev 6578)
@@ -23,6 +23,16 @@
             im1 = pilutil.imresize(im,T(1.1))
             assert_equal(im1.shape,(11,22))
 
+    def test_imresize2(self):
+        im = np.random.random((20,30))
+        im2 = pilutil.imresize(im, (30,40), interp='bicubic')
+        assert_equal(im2.shape, (30,40))
+
+    def test_imresize3(self):
+        im = np.random.random((15,30))
+        im2 = pilutil.imresize(im, (30,60), interp='nearest')
+        assert_equal(im2.shape, (30,60))
+
     def test_bytescale(self):
         x = np.array([0,1,2],np.uint8)
         y = np.array([0,1,2])



More information about the Scipy-svn mailing list