Transforms

This module holds all the transforms associated with NIfTI dataset

niftidataset.transforms

transformations to apply to images in dataset

Author: Jacob Reinhold (jacob.reinhold@jhu.edu)

Created on: Oct 24, 2018

class niftidataset.transforms.RandomCrop2D(output_size: Union[int, tuple, list], axis: Optional[int] = 0, include_neighbors: bool = False, threshold: Optional[float] = None)

Randomly crop a 2d slice/patch from a 3d image

Parameters:
  • output_size (tuple or int) – Desired output size. If int, cube crop is made.
  • axis (int or None) – along which axis should the patch/slice be extracted provide None for random axis
  • include_neighbors (bool) – extract 3 neighboring slices instead of just 1
class niftidataset.transforms.RandomCrop3D(output_size: Union[tuple, int, list], threshold: Optional[float] = None, pct: Tuple[float, float] = (0.0, 1.0), axis=0)

Randomly crop a 3d patch from a (pair of) 3d image

Parameters:output_size (tuple or int) – Desired output size. If int, cube crop is made.
class niftidataset.transforms.RandomCrop(output_size: Union[tuple, int], threshold: Optional[float] = None)

Randomly crop a 2d patch from a 2d image

Parameters:output_size (tuple or int) – Desired output size. If int, square crop is made.
class niftidataset.transforms.RandomSlice(axis: int = 0, div: float = 2)

take a random 2d slice from an image given a sample axis

Parameters:
  • axis (int) – axis on which to take a slice
  • div (float) – divide the mean by this value in the calculation of mask the higher this value, the more background will be “valid”
class niftidataset.transforms.ToTensor(color=False)

Convert images in sample to Tensors

class niftidataset.transforms.ToPILImage(color=False)

convert 2D image to PIL image

class niftidataset.transforms.AddChannel

Add empty first dimension to sample

class niftidataset.transforms.FixIntensityRange(scale: float = 1)

put data in range of 0 to 1

class niftidataset.transforms.Normalize(mean=None, std=None, tfm_x: bool = True, tfm_y: bool = False, is_3d: bool = False)

Implement a normalize function for input two images. It computes std and mean for each input Tensor if mean and std equal to None,

then the function normalizes Tensor using the computed values.
Parameters:
  • mean – mean of input Tensor. if None passed, mean of each Tensor will be computed and normalization will be performed based on computed mean.
  • std – standard deviation of input Tensor. if None passed, std of each Tensor will be computed and normalization will be performed based on computed std.
  • tfm_x (bool) – transform x or not
  • tfm_y (bool) – transform y or not
  • is_3d (bool) – is the Tensor 3d or not. this causes to normalize the Tensor on each channel.
class niftidataset.transforms.Digitize(tfm_x=False, tfm_y=True, int_range=(1, 100), step=1)

digitize a sample of images

class niftidataset.transforms.MedianFilter(tfm_x=True, tfm_y=False)

median filter the sample

class niftidataset.transforms.RandomBlock(p, sz_range, thresh=None, int_range=None, tfm_x=True, tfm_y=False, is_3d=False)

add random blocks of random intensity to a sample of images

class niftidataset.transforms.RandomGamma(p, tfm_y=False, gamma: float = 0.0, gain: float = 0.0)

apply random gamma transformations to a sample of images

class niftidataset.transforms.RandomNoise(p, tfm_x=True, tfm_y=False, std: float = 0)

add random gaussian noise to a sample of images

class niftidataset.transforms.TrimIntensity(min_val: float, max_val: float, new_min: float = -1.0, new_max: float = 1.0, tfm_x: bool = True, tfm_y: bool = False)

Trims intensity to given interval [new_min, new_max]. Trim intensities that are outside range [min_val, max_val], then scale to [new_min, new_max].

niftidataset.transforms.get_transforms(p: Union[list, float], tfm_x: bool = True, tfm_y: bool = False, degrees: float = 0, translate: float = None, scale: float = None, vflip: bool = False, hflip: bool = False, gamma: float = 0, gain: float = 0, noise_pwr: float = 0, block: Optional[Tuple[int, int]] = None, thresh: Optional[float] = None, is_3d: bool = False, mean: Optional[Tuple[float]] = None, std: Optional[Tuple[float]] = None, color: bool = False, segmentation: bool = False)

get many desired transforms in a way s.t. can apply to nifti/tiffdatasets