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)

版权声明:本文为weixin_42201701原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_42201701/article/details/106109465