在Python上显示Matlab mat文件中的图像 [英] Display image from Matlab mat file on Python

查看:1381
本文介绍了在Python上显示Matlab mat文件中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试显示从此网站下载的Mat文件中的图像.

I'm currently trying to display an image from a Mat file downloaded from this site.

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

It's a .mat file so I tried loading it using spicy.io's load mat function but I can't seem to plot the image. What am I doing wrong?

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()

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

What I get is this instead of an image

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

By the way, the output of images[0] is

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]])

非常感谢您!

推荐答案

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

You need a complete 3D slice and hence you should be using images[:,:,0]. i.e

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

给出:

这篇关于在Python上显示Matlab mat文件中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆