3

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.