从旋转的数据集构建的图像

Images constructed from dataset rotated

我对 python 绘图不是很有经验。我想使用 YaleB_32x32 数据集 (https://github.com/flatironinstitute/online_psp/blob/master/datasets/YaleB_32x32.mat)。这是我的代码:

imgData = scipy.io.loadmat('/path/YaleB_32x32.mat')
matX = imgData['fea']
plt.figure(figsize = (6,6))
gs1 = gridspec.GridSpec(6, 6)
gs1.update(wspace=0.01, hspace=0.01)
for i in range(36):
    vecX = matX[i,:].reshape(32,32)
    ax1 = plt.subplot(gs1[i])
    plt.imshow(vecX, cmap = 'gray')
    plt.axis('off')

This 是输出。 如您所见,图像已旋转。有人可以帮我解决我哪里错了吗?

您可以使用 rot90 通过 numpy 库旋转面部。使用axes=(1, 0)顺时针旋转:

vecX = np.rot90(matX[i,:].reshape(32, 32), axes=(1, 0))

编辑 通过@bitastap 评论,我意识到 reshape 操作需要 Fortan style order :

vecX = matX[i,:].reshape((32, 32), order='F')