图像预处理

软件版本
问题描述:3Dslicer能够进行图像预处理么

2 Likes

怎样的预处理呢?

应用TorchIO Transforms模块可以对图像进行一些预处理。

https://download.pytorch.org/whl/torch_stable.html

请参阅:https://torchio.readthedocs.io/data/dataset.html

import torchio
from torchio.transforms import (
    RescaleIntensity,
    RandomAffine,
    RandomElasticDeformation,
    Compose,
)
from torch.utils.data import DataLoader

# Each instance of torchio.Subject is passed arbitrary keyword arguments.
# Typically, these arguments will be instances of torchio.Image
subject_a = torchio.Subject(
    t1=torchio.Image('subject_a.nii.gz', type=torchio.INTENSITY),
    label=torchio.Image('subject_a.nii', type=torchio.LABEL),
    diagnosis='positive',
)

# Images can be in any format supported by SimpleITK or NiBabel, including DICOM
subject_b = torchio.Subject(
    t1=torchio.Image('subject_b_dicom_folder', type=torchio.INTENSITY),
    label=torchio.Image('subject_b_seg.nrrd', type=torchio.LABEL),
    diagnosis='negative',
)
subjects_list = [subject_a, subject_b]

# Let's use one preprocessing transform and one augmentation transform
# This transform will be applied only to torchio.INTENSITY images:
rescale = RescaleIntensity((0, 1))

# As RandomAffine is faster then RandomElasticDeformation, we choose to
# apply RandomAffine 80% of the times and RandomElasticDeformation the rest
# Also, there is a 25% chance that none of them will be applied
spatial = OneOf(
    {RandomAffine(): 0.8, RandomElasticDeformation(): 0.2},
    p=0.75,
)

# Transforms can be composed as in torchvision.transforms
transforms = [rescale, spatial]
transform = Compose(transforms)

# ImagesDataset is a subclass of torch.data.utils.Dataset
subjects_dataset = torchio.ImagesDataset(subjects_list, transform=transform)

# Images are processed in parallel thanks to a PyTorch DataLoader
training_loader = DataLoader(subjects_dataset, batch_size=4, num_workers=4)

# Training epoch
for subjects_batch in training_loader:
    inputs = subjects_batch['t1'][torchio.DATA]
    target = subjects_batch['label'][torchio.DATA]