Skip to content

ldctbench.data.LDCTMayo

LDCTMayo(mode, args)

Bases: Dataset

Dataset class for the LDCT dataset

Parameters:

  • mode (str) –

    Which subset to use. Must be train, val, or test.

  • args (Namespace) –

    Command line argumetns passed to the dataset class.

Attributes:

  • seed (int) –

    Random seed to use

  • path (str) –

    Root path to datafolder

  • patchsize (int) –

    Patchsize to use for training.

  • eval_patchsize (int) –

    Patchsize to use for validation.

  • data_subset (float) –

    Subset of the data to use.

  • data_norm (str) –

    Normalization of the data, must be meanstd or minmax.

  • info (dict) –

    Dictionary of info.yml associated with the dataset.

  • samples (list) –

    List of all image slices

  • weights (list) –

    List of weights associated with each slice. Slices of each patient having n_slices are weighted with 1/n_slices.

Examples:

Create a training dataset

>>> from argparse import Namespace
>>> from ldctbench.data import LDCTMayo
>>> args = Namespace(seed=1332, path='/path/to/dataset/root', data_norm='meanstd', data_subset=1.0, patchsize=128)
>>> train_data = LDCTMayo('train', args)

Create a validation dataset

>>> from argparse import Namespace
>>> from ldctbench.data import LDCTMayo
>>> args = Namespace(seed=1332, path='/path/to/dataset/root', data_norm='meanstd', data_subset=1.0, eval_patchsize=128)
>>> train_data = LDCTMayo('val', args)

__getitem__(idx)

Given an index, get slice, perform random cropping, normalize and return

__len__()

Length of dataset

_idx2filename(idx, n_slices) staticmethod

Get filename for a patient of LDCT data given slice and number of slices in the scan.

Parameters:

  • idx (int) –

    Slice idx for which to return filename

  • n_slices (int) –

    Number of slices of the scan necessary to figure out number of trailing zeros

Returns:

  • str

    Filename

_normalize(X)

Normalize samples with precomputed mean/std or min/max

Parameters:

  • X (ndarray) –

    Array to normalize

Returns:

  • ndarray

    Normalized array

Raises:

  • ValueError

    If normalization method self.data_norm is neither meanstd nor minmax

_random_crop(images)

Randomly crop the same patch from images (e.g. ground truth and input)

Parameters:

  • images (List[ndarray]) –

    List of images to crop in same position for

Returns:

  • List[ndarray]

    List of cropped images

denormalize(X)

Denormalize samples with precomputed mean/std or min/max

Parameters:

  • X (ndarray) –

    Array to denormalize

Returns:

  • ndarray

    Denormalized array

Raises:

  • ValueError

    If normalization method self.data_norm is neihter meanstd nor minmax

reset_seed()

Reset random seeds

to_torch(X) staticmethod

Convert input image to torch tensor and unsqueeze