python打开mat图像文件,在Python上显示Matlab mat文件中的图像

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

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

pjuWO.png

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

Thank you very much in advance!

解决方案

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

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

which gives:

sXV2j.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值