def intensity(self, x): transform = tio.OneOf([ tio.RandomMotion(translation=1), tio.RandomBlur(), tio.RandomGamma(), tio.RandomSpike(intensity=[0.2, 0.5]), tio.RandomBiasField() ]) x = transform(x.unsqueeze(0)).squeeze(0) return x
def __init__(self, X, Y, mixup=0, aug=False): self.X = X.astype('float32') self.Y = Y.astype('float32') self.aug = aug if self.aug: self.intensity = [ tio.RandomMotion(translation=1), tio.RandomBlur(), tio.RandomGamma(), tio.RandomSpike(intensity=[0.2, 0.5]), tio.RandomBiasField() ] else: self.intensity = None self.mixup = mixup
$ torchio-transform ~/Dropbox/MRI/t1.nii.gz RandomMotion /tmp/t1_motion.nii.gz --seed 42 --kwargs "degrees=10 translation=10 num_transforms=3 proportion_to_augment=1" """ from pprint import pprint from torchio import Image, ImagesDataset, transforms, INTENSITY, LABEL, Subject subject = Subject( Image('label', '~/Dropbox/MRI/t1_brain_seg.nii.gz', LABEL), Image('t1', '~/Dropbox/MRI/t1.nii.gz', INTENSITY), ) subjects_list = [subject] dataset = ImagesDataset(subjects_list) sample = dataset[0] transform = transforms.RandomMotion( seed=42, degrees=10, translation=10, num_transforms=3, ) transformed = transform(sample) pprint(transformed['t1']['random_motion_times']) pprint(transformed['t1']['random_motion_degrees']) pprint(transformed['t1']['random_motion_translation']) dataset.save_sample(transformed, dict(t1='/tmp/t1_motion.nii.gz')) dataset.save_sample(transformed, dict(label='/tmp/t1_brain_seg_motion.nii.gz'))
subject = Subject(dic_suj) subject = Subject( t1 = Image('/data/romain/HCPdata/suj_100307/T1w_1mm.nii.gz', INTENSITY), label = Image('/data/romain/HCPdata/suj_100307/T1w_1mm.nii.gz', LABEL), ) subjects_list = [subject] dataset = ImagesDataset(subjects_list) sample = dataset[0] transform = transforms.RandomMotion( seed=2, degrees=0, translation=100, num_transforms=1, verbose=True, proportion_to_augment=1, ) transformed = transform(sample) _, random_parameters = transformed.history[0] pprint(random_parameters['t1']['times']) pprint(random_parameters['t1']['degrees']) pprint(random_parameters['t1']['translation']) dataset.save_sample(transformed, dict(t1='/tmp/t1_motion.nii.gz')) dataset.save_sample(transformed, dict(label='/tmp/t1_brain_seg_motion.nii.gz'))
$ torchio-transform ~/Dropbox/MRI/t1.nii.gz RandomMotion /tmp/t1_motion.nii.gz --seed 42 --kwargs "degrees=10 translation=10 num_transforms=3 proportion_to_augment=1" """ from pprint import pprint from torchio import Image, ImagesDataset, transforms, INTENSITY, LABEL, Subject subject = Subject( Image('label', '~/Dropbox/MRI/t1_brain_seg.nii.gz', LABEL), Image('t1', '~/Dropbox/MRI/t1.nii.gz', INTENSITY), ) subjects_list = [subject] dataset = ImagesDataset(subjects_list) sample = dataset[0] transform = transforms.RandomMotion( seed=42, degrees=10, translation=10, num_transforms=3, proportion_to_augment=1, ) transformed = transform(sample) pprint(transformed['t1']['random_motion_times']) pprint(transformed['t1']['random_motion_degrees']) pprint(transformed['t1']['random_motion_translation']) dataset.save_sample(transformed, dict(t1='/tmp/t1_motion.nii.gz')) dataset.save_sample(transformed, dict(label='/tmp/t1_brain_seg_motion.nii.gz'))
from pprint import pprint from torchio import ImagesDataset, transforms, INTENSITY paths = [{ 't1': dict(path='~/Dropbox/MRI/t1.nii.gz', type=INTENSITY), 'colin': dict(path='/tmp/colin27_t1_tal_lin.nii.gz', type=INTENSITY), }] dataset = ImagesDataset(paths) sample = dataset[0] transform = transforms.RandomMotion( seed=42, degrees=20, translation=15, num_transforms=3, verbose=True, ) transformed = transform(sample) pprint(transformed['t1']['random_motion_times']) dataset.save_sample(transformed, dict(t1='/tmp/t1_motion.nii.gz')) dataset.save_sample(transformed, dict(colin='/tmp/colin_motion.nii.gz'))