Question

I would like to resample a numpy array as suggested here Resampling a numpy array representing an image however this resampling will do so by a factor i.e.

x = np.arange(9).reshape(3,3)
print scipy.ndimage.zoom(x, 2, order=1)

Will create a shape of (6,6) but how can I resample an array to its best approximation within a (4,6),(6,8) or (6,10) shape for instance?

Was it helpful?

Solution

Instead of passing a single number to the zoom parameter, give a sequence:

scipy.ndimage.zoom(x, zoom=(1.5, 2.), order=1)
#array([[0, 0, 1, 1, 2, 2],
#       [2, 2, 3, 3, 4, 4],
#       [4, 4, 5, 5, 6, 6],
#       [6, 6, 7, 7, 8, 8]])

With the sequences (2., 2.75) and (2., 3.5) you will get output arrays with shapes (6, 8) and (6, 10), respectively.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top