Simplest way to resize an image-like array

J

John Ladasky

Hi folks,

I have 500 x 500 arrays of floats, representing 2D "grayscale" images,
that I need to resample at a lower spatial resolution, say, 120 x 120
(details to follow, if you feel they are relevant).

I've got the numpy, and scipy, and matplotlib. All of these packages
hint at the fact that they have the capability to resample an image-
like array. But after reading the documentation for all of these
packages, none of them make it straightforward, which surprises me.
For example, there are several spline and interpolation methods in
scipy.interpolate. They seem to return interpolator classes rather
than arrays. Is there no simple method which then calls the
interpolator, and builds the resampled array?

Yes, I can do this myself if I must -- but over the years, I've come
to learn that a lot of the code I want is already written, and that
sometimes I just have to know where to look for it.

Thanks!
 
J

Jon Clements

Hi folks,

I have 500 x 500 arrays of floats, representing 2D "grayscale" images,
that I need to resample at a lower spatial resolution, say, 120 x 120
(details to follow, if you feel they are relevant).

I've got the numpy, and scipy, and matplotlib. All of these packages
hint at the fact that they have the capability to resample an image-
like array.  But after reading the documentation for all of these
packages, none of them make it straightforward, which surprises me.
For example, there are several spline and interpolation methods in
scipy.interpolate.  They seem to return interpolator classes rather
than arrays.  Is there no simple method which then calls the
interpolator, and builds the resampled array?

Yes, I can do this myself if I must -- but over the years, I've come
to learn that a lot of the code I want is already written, and that
sometimes I just have to know where to look for it.

Thanks!

Is something like http://docs.scipy.org/doc/scipy/reference/generated/scipy..misc.imresize.html#scipy.misc.imresize
any use?
 
D

Dennis Lee Bieber

Hi folks,

I have 500 x 500 arrays of floats, representing 2D "grayscale" images,
that I need to resample at a lower spatial resolution, say, 120 x 120
(details to follow, if you feel they are relevant).
How difficult would it be to convert the "array" to a PIL image? I'm
fairly certain PIL has operations to rescale images.
 
J

John Ladasky

        How difficult would it be to convert the "array" to a PILimage? I'm
fairly certain PIL has operations to rescale images.

Yes, I considered this approach -- but I have a lot of arrays to
resample, and I didn't want to further slow what is likely to be an
already-slow process.
 
J

John Ladasky

There we go!  That's the kind of method I was seeking.  I didn't think
to look outside of scipy.interpolate.  Thanks, Jon.

Oh, grumble, scipy.misc.imresize bumps the array down to an 8-bit
integer array. I need to do some arithmetic with the arrays, and it
needs to be more precise than 8 bits. So I may have to rewrite the
function to yield a 16-bit integer at least.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top