Get data paths and labels

Data is divided into a train, valid and test dataset of different patients, which either have prostate cancer or are healthy. Each patient has three MRI sequences: T2, T1map and ADC. These sequences differ regarding the number of slices and resolution.

At first, the paths to the data are specified:

d = pd.read_csv('../data/radiopaedia_cases.csv')
d['label'] = ['Label A', 'Label A', 'Label A', 'Label B', 'Label B']

Raw pixel data for DICOM must sometimes undergo affine transformation (e.g. to be converted to Houndsfiel Units). PreProcessDicom is a convenience function which can perform a few frequently needed manipulations with the pixel data.

class PreprocessDicom[source]

PreprocessDicom(rescale=True, correct_spacing=True, spacing=1, clip_high_values=False, clipping_range=(-2000, 10000)) :: DisplayedTransform

Transforms a TensorDicom3D volume to float and normalizes the data

TensorDicom3D.scale_to[source]

TensorDicom3D.scale_to(t:TensorDicom3D, mean, std)

class AddChannel[source]

AddChannel(p=1.0) :: DisplayedTransform

Adds Channels dims, in case they went missing

ImageBlock3D[source]

ImageBlock3D(**kwargs)

A `TransformBlock` for images of `cls`. For possible kwargs see PreporcessDicom.

MaskBlock3D[source]

MaskBlock3D(codes=None)

A `TransformBlock` for images of `cls`. For possible kwargs see PreporcessDicom.

Dataloaders for image classification

class ImageDataLoaders3D[source]

ImageDataLoaders3D(*loaders, path='.', device=None) :: DataLoaders

Nearly identical to fastai `ImageDataLoaders` but adapted for 3D data with some preprocessing steps added

get_volumetric_files[source]

get_volumetric_files(path, recurse=True, folders=None)

Get medical volumetric files or video in `path` recursively, only in `folders`, if specified.
d
series masks label
0 ../data/series/radiopaedia_10_85902_1.nii.gz ../data/masks/radiopaedia_10_85902_1.nii.gz Label A
1 ../data/series/radiopaedia_10_85902_3.nii.gz ../data/masks/radiopaedia_10_85902_3.nii.gz Label A
2 ../data/series/radiopaedia_14_85914_0.nii.gz ../data/masks/radiopaedia_14_85914_0.nii.gz Label A
3 ../data/series/radiopaedia_27_86410_0.nii.gz ../data/masks/radiopaedia_27_86410_0.nii.gz Label B
4 ../data/series/radiopaedia_29_86490_1.nii.gz ../data/masks/radiopaedia_29_86490_1.nii.gz Label B
dls = ImageDataLoaders3D.from_df(d, 
                                 fn_col = 'series', 
                                 label_col = 'label',
                                 item_tfms = ResizeCrop3D(crop_by = (0., 0.1, 0.1), 
                                                          resize_to = (20, 150, 150), 
                                                          perc_crop = True),
                                 bs = 2, 
                                 )
from fastai.data.core import DataLoaders # for compatibility with show_docs

DataLoaders.show_batch_3d[source]

DataLoaders.show_batch_3d(dls:DataLoaders, with_mask=False, alpha_mask=0.3, figsize=(4, 4), viewer='widget', max_n=9, **kwargs)

Show batch of DataLoader either with simple moasik view or using the DICOM viewer widget
dls.show_batch_3d()
dls.show_batch_3d(viewer='mosaik', nrow = 15, figsize=(15, 15))
from torch import Tensor # for show_docs

Tensor.to_numpy[source]

Tensor.to_numpy(x:Tensor)

DataLoaders.show_hist[source]

DataLoaders.show_hist(dls:DataLoaders, bins=100, with_stats=False)

dls.show_hist(with_stats=True)
batch mean: 0.6159189939498901, std: 0.3389137089252472
px range: 0.0 - 1.0
skewness: -0.5420928597450256, kurtosis:-1.4813423156738281

Dataloaders for segmentation

class SegmentationDataLoaders3D[source]

SegmentationDataLoaders3D(*loaders, path='.', device=None) :: DataLoaders

Basic wrapper around several `DataLoader`s with factory methods for segmentation problems
dls = SegmentationDataLoaders3D.from_df(d, 
                                        fn_col='series',
                                        label_col = 'masks',
                                        batch_size = 4)
dls.show_batch_3d(with_mask=True)