首先導入相關的包
import scipy.io as sio
import os
filepath = os.path.join('../Denoising/Datasets/test/', 'ValidationNoisyBlocksRaw.mat')
print(filepath)
##導入mat文件
img=sio.loadmat(filepath)
導入mat文件返回是一個字典對象。
# print(type(img))
for i in img.keys():
print(i)
輸出結果
__header__
__version__
__globals__
ValidationNoisyBlocksRaw
aa=img['ValidationNoisyBlocksRaw']
print(type(aa))
print(aa.shape)
b=aa[0,1,:,:]
print(b.shape)
print(type(b))
輸出
<class 'numpy.ndarray'>
(40, 32, 256, 256)
(256, 256)
<class 'numpy.ndarray'>
from matplotlib import pyplot as plt
plt.imshow(b)
print(b)
plt.show()