医学图像的数据预处理

Posted Mario cai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了医学图像的数据预处理相关的知识,希望对你有一定的参考价值。

import numpy as np
import torchio as tio
from torch.utils.data import DataLoader
import torch
import nibabel as nib
from torchio.transforms import (
    RandomFlip,
    RandomAffine,
    RandomElasticDeformation,
    RandomNoise,
    RandomMotion,
    RandomBiasField,
    RescaleIntensity,
    Resample,
    ToCanonical,
    ZNormalization,
    CropOrPad,
RandomSpike,
RandomBlur,
RandomSwap,
    HistogramStandardization,
    OneOf,
    Clamp,
    Compose,
    RandomGhosting,
)

landmarks = r'C:\\Users\\Admin\\SIAT\\model\\caihaihua2d\\nrrddatatotal.npy'
z=0

while z<99999:
    z = z+1

    subject = tio.Subject(
        chest_ct=tio.ScalarImage(fr'C:\\Users\\Admin\\Desktop\\EGFR total\\EGFRzhong\\EGFRzhong\\data\\1\\z.nrrd'),
        # chest_ct=tio.ScalarImage(fr'C:\\Users\\Admin\\PycharmProjects\\pythonProject14\\z.nii.gz'),
        # chest_ct=tio.ScalarImage(fr'C:\\Users\\Admin\\Desktop\\EGFR total\\EGFRzhong\\new\\EGFRdata\\0data\\00C1108863_HU  JIAN  TING.nrrd'),

        heart_mask=tio.LabelMap(fr'C:\\Users\\Admin\\Desktop\\EGFR total\\EGFRzhong\\EGFRzhong\\mask\\1\\z.nrrd'),
        # heart_mask1=tio.LabelMap(fr'C:\\Users\\Admin\\Desktop\\EGFR total\\EGFRzhong\\EGFRzhong\\mask\\1\\z.nrrd'),
        # heart_mask=tio.LabelMap(fr'C:\\Users\\Admin\\Desktop\\EGFR total\\EGFRzhong\\new\\EGFRmask\\0mask\\00C1108863_HU  JIAN  TING.seg.nrrd'),

    )


    # transform = tio.HistogramStandardization('chest_ct': landmarks),


    subject.chest_ct.shape
    # subject.heart_mask.shape = subject.chest_ct.shape
    # subject.heart_mask.shape
    #
    # print(subject.heart_mask)
    #
    # print(subject.chest_ct)

    # transform = tio.CropOrPad(
    #     # (64, 64, 32),
    #     mask_name='heart_mask',
    # )
    # ti = tio.Resample(2)
    # subject = ti(subject)


    transform = Compose([
        tio.ToCanonical(),
        # tio.Resample(),

        # tio.Resample(include=['chest_ct']),
        # tio.Resample(target='chest_ct', exclude=['chest_ct']),

        tio.HistogramStandardization('chest_ct': landmarks),
        tio.Mask(masking_method='heart_mask'),
        tio.CropOrPad(
            # (64, 64, 64),
            mask_name='heart_mask',),
        # tio.HistogramStandardization('chest_ct': landmarks),

    ])


    transformed = transform(subject)
    transformed.chest_ct.shape
    # print(k)
    # transformed.heart_mask.shape
    # print(l)

    a = transformed.get_first_image()
    a = a.numpy()
    x = a[0]
    # a = a.reshape([64,64,64,1]) #将之转化为数组查看
    # x = a.type(torch.FloatTensor).cuda()
    print(a[0].shape)
    img_t1 = nib.Nifti1Image(x, np.eye(4))
    nib.save(img_t1, f'z.nii.gz')  # 将之保存为nii查看
    # sitk.WriteImage(dcms_series, filepath + subName + '.nrrd')

以上是关于医学图像的数据预处理的主要内容,如果未能解决你的问题,请参考以下文章

医学图像三维可视化和三维重建的区别

附源码医学图像分割入门实践

在线医学图像处理的巨大挑战[关闭]

数字图像处理基础笔记

数字图像处理基础笔记

常见医学图像处理深度学习方法与热点应用附参考文献