Jagadeesh Dondeti
Jagadeesh Dondeti

Reputation: 404

Rotating an Image in Python

`

import numpy 
import skimage.io
from skimage.transform import rotate
tr_1 = numpy.random.rand(5,300)
training_inputs = [numpy.reshape(tr_1[x,:], (3,10,10)) for x in range(len(tr_1))]
f = rotate(training_inputs[1], 90, resize=True)

The above code is giving an output of size (10,4,10). But image should be rotated and it's size should be of (3,10,10).

Any Suggestions and how to proceed with the code?

Upvotes: 1

Views: 1363

Answers (1)

Francesco Nazzaro
Francesco Nazzaro

Reputation: 2926

skimage.rotate cannot rotate a 3 bands image. You have to rotate a band at a time.

import numpy as np
import skimage.io
from skimage.transform import rotate
tr_1 = numpy.random.rand(5,300)
training_inputs = [np.reshape(tr_1[x,:], (3,10,10)) for x in range(len(tr_1))]
f0 = rotate(training_inputs[1][0], 90, resize=True)
f1 = rotate(training_inputs[1][1], 90, resize=True)
f2 = rotate(training_inputs[1][2], 90, resize=True)
f = np.rollaxis(np.dstack((f0, f1, f2)), 2, 0)

the shape of f will be (3, 10, 10)

Upvotes: 1

Related Questions