[Numpy-discussion] Optimized half-sizing of images?

Christopher Barker Chris.Barker@noaa....
Thu Aug 6 17:34:34 CDT 2009


Christopher Barker wrote:
> Stéfan van der Walt wrote:
>> Are you willing to depend on SciPy?  We've got pretty fast zooming
>> code in ndimage.

> However, my thought is that for the special case of half-sizing, all 
> that spline stuff could be unneeded and slower. I'll see what we get.

I've given that a try. The docs are pretty sparse. I couldn't figure out 
a way to get it to do the whole image at once. Rather I had to do each 
band separately. It ended up about the same speed as my int accumulator 
method:

def test5(a):
     """
     using ndimage

     tested on 512x512 RGB image:
       time:  40 ms per loop

     """
     h = a.shape[0]/2
     w = a.shape[1]/2
     a2 = np.empty((h, w, 3), dtype=np.uint8)
     a2[:,:,0] = ndi.zoom(a[:,:,0], 0.5, order=1)
     a2[:,:,1] = ndi.zoom(a[:,:,1], 0.5, order=1)
     a2[:,:,2] = ndi.zoom(a[:,:,2], 0.5, order=1)
     return a2

Is there a way to get it to do all three colorbands at once?

NOTE: if I didn't set order to 1, it was MUCH slower, as one might expect.






-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: numpy_resize.py
Type: application/x-python
Size: 4236 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090806/a777104a/attachment-0001.bin 


More information about the NumPy-Discussion mailing list