hferaidon
hferaidon

Reputation: 29

Rotate a image that's processed by numpy array

I'm working on a similar dataset to that of the famous MNIST, execept this dataset deals with arabic characters. The data I have currently is in the form of numpy 2D array. It looks like array([[0, 0, 0, ..., 0, 0, 0] ,..., [0, 0, 0, ..., 0, 0, 0]]) And has a shape of (3360, 1024), 3360 instances with 1024 features.

To display the image, I reshape an instance's features to a 32x32 array and draw a cmap using matplotlib. However, the way my data was given, the images are rotated and I want to rotate it counter-clockwise by 90' degrees.

Any suggestions on what to do? I assume I will have to manipulate each instances features. However, is there a simple way to do this, such as an existing function.

Upvotes: 1

Views: 1197

Answers (1)

cs95
cs95

Reputation: 402992

Step 1: Reshape
Step 2: Rotate

data_rot90 = np.rot90(data.reshape(-1, 32, 32), k=-1, axes=(-2, -1))

This reshapes the data and then rotates it 90' degrees anticlockwise along the last two axes.

Upvotes: 1

Related Questions