I am not very experienced with python plotting. I want to work with YaleB_32x32 dataset (https://github.com/flatironinstitute/online_psp/blob/master/datasets/YaleB_32x32.mat). This is my code :
JavaScript
x
11
11
1
imgData = scipy.io.loadmat('/path/YaleB_32x32.mat')
2
matX = imgData['fea']
3
plt.figure(figsize = (6,6))
4
gs1 = gridspec.GridSpec(6, 6)
5
gs1.update(wspace=0.01, hspace=0.01)
6
for i in range(36):
7
vecX = matX[i,:].reshape(32,32)
8
ax1 = plt.subplot(gs1[i])
9
plt.imshow(vecX, cmap = 'gray')
10
plt.axis('off')
11
This is the output. As you can see that images are rotated. Could someone please help me with where am I going wrong?
Advertisement
Answer
You can use rot90
to rotate faces with numpy
lib. Use axes=(1, 0)
to rotate clockwise:
JavaScript
1
2
1
vecX = np.rot90(matX[i,:].reshape(32, 32), axes=(1, 0))
2
Edit
With @bitastap comment, I realize that reshape
operation needs Fortan style order
:
JavaScript
1
2
1
vecX = matX[i,:].reshape((32, 32), order='F')
2