Resize RGB image?

Alasdair McAndrew amca01 at
Sat Nov 24 12:14:24 CET 2012

I can resize a 2d image "im" with a command something like:

r,c = shape(im)
im2 = resize(im,(r//2,c//2))

However, resize doesn't seem to work with an RGB image:

r,c,n = shape(im)  # returns, say 500 600 3 

I then need to take each band separately, resize it, and put them all back together with dstack:

imr = im[:,:,0]
img = im[:,:,1]
imb = im[:,:,2]
imr2 = resize(imr,(r//2,c//2))
img2 = resize(img,(r//2,c//2))
imb2 = resize(imb,(r//2,c//2))
im2 = dstack((imr2,img2,imb2))

This works fine, but seems a little clumsy.  Of course this could be done in one command:

im2 = dstack([resize(im[:,:,i],(r//2,c//2)) for i in range(3)])

What I want to know is: is there a version of resize which can be applied directly to multi-band images, without having to apply to each band separately?


More information about the Python-list mailing list