Rotate a batch of images with `scipy.ndimage.interpolation.rotate`

Suppose X

is a tensor numpy.ndarray

that contains a set of color images. For example, a form X

(100, 3, 32, 32)

; that is, we have 100 32x32 rgb images (for example, data provided by the CIFAR dataset).

I want to rotate images in X

and I found out that it can be done using scipy.ndimage.interpolation.rotate scipy function .

However, I can only do it correctly for one image and one color channel at a time, while I would like to apply this function to all images and all color channels at the same time.

What I have tried and is working so far is the following:

import scipy.ndimage.interpolation

image = X[0,0,:,:]
rotated_image = scipy.ndimage.interpolation.rotate(input=image, angle=45, reshape=False)

      

but what i want to do, which might look like this:

X_rot = scipy.ndimage.interpolation.rotate(input=X, angle=45, reshape=False)

      

does not work.

Can it be applied scipy.ndimage.interpolation.rotate

for batch of images like tenside numpy.ndarray X

?

Anyway, is there a better way to effectively rotate a batch of images (stored in numpy.ndarray

)?

+3


source to share





All Articles