import numpy as np
import scipy.io as sio
def get_mat(file, types):
"""
从mat文件中提取所需类型名称
:param file: 文件地址
:param types: 传递元组,所需数据种类('pixelSpacing', 'maskBody', 'water', 'fat', 'IP', 'OP', 'sCT', 'ctNAC', 'atMR'等其他任何数据)
:return:types所含数据种类
"""
img = sio.loadmat(file)
nums = len(types)
all = []
for type in types:
if img[type].ndim == 2:
all.append(np.array(img[type]))
elif img[type].ndim == 3:
all.append(np.array(img[type]).transpose((2, 0, 1)))
return tuple(all)
python使用技巧(三)——python读取mat文件
最新推荐文章于 2024-06-26 22:52:12 发布