【问题标题】:Display image from Matlab mat file on Python在 Python 上显示来自 Matlab mat 文件的图像
【发布时间】:2020-05-04 11:08:05
【问题描述】:

我目前正在尝试显示从 site 下载的 Mat 文件中的图像。

这是一个 .mat 文件,所以我尝试使用辣味.io 的加载垫功能加载它,但我似乎无法绘制图像。 我做错了什么?

import scipy
import sklearn
from sklearn.feature_extraction import image
from scipy.io import loadmat
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
images = loadmat('IMAGES.mat',variable_names='IMAGES',appendmat=True).get('IMAGES')

imgplot = plt.imshow(images[0])

plt.show()

我得到的是这个而不是图像

顺便说一下,images[0]的输出是

array([[ 0.34344572,  0.12458728, -0.16325758, ...,  0.66119415,
         0.10742886,  0.45598051],
       [ 0.20327842,  0.12588207,  0.14950003, ...,  0.74659014,
        -0.04141214,  0.39051244],
       [ 0.27077097, -0.01716869,  0.27221447, ...,  0.83127338,
        -0.16380881,  0.42533499],
       ...,
       [-0.5974496 , -0.85362321, -0.30514711, ...,  0.41944146,
        -0.00949729,  0.49504656],
       [-0.58272219, -0.89612395,  0.22482066, ...,  0.31972334,
        -0.02557803,  0.47179163],
       [ 0.19115125, -0.68936276,  0.04859381, ...,  0.41277626,
        -0.08376407,  0.56580657]])

非常感谢您!

【问题讨论】:

    标签: python matlab matplotlib


    【解决方案1】:

    您需要一个完整的 3D 切片,因此您应该使用images[:,:,0]。即

    imgplot = plt.imshow(images[:,:,0])
    

    给出:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 2021-12-08
      • 2014-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-22
      相关资源
      最近更新 更多