DeepBrainSeg.helpers package

Submodules

DeepBrainSeg.helpers.dcm2niftii module

DeepBrainSeg.helpers.dcm2niftii.convertDcm2nifti(path_json, output_dir, verbose=False)[source]

path_json: {‘key1’: path1, ‘key2’: path2} output_dir: nifty save dir path verbose: bool, to print logs

DeepBrainSeg.helpers.dcm2niftii.singleDicom2nifti(input_path, output_path, verbose=False)[source]

This function hepls in converting the .dcm slices together and create nii file

input_path: path to the folder containing .dcm files output_path: path to save .nii files verbose: bool, to print logs

DeepBrainSeg.helpers.helper_mask module

DeepBrainSeg.helpers.npanalysis module

DeepBrainSeg.helpers.npanalysis.npanalysis(path, predict_prefix, out_path, file_name='')[source]

DeepBrainSeg.helpers.postprocessing module

DeepBrainSeg.helpers.postprocessing.class_wise_cc(pred)[source]

Applies connected components on class wise slices

args
pred dimension: width, height, depth
returns
tensor of same size as logits (uint8)
DeepBrainSeg.helpers.postprocessing.connected_components(voxels, threshold=0.8)[source]

This clusters entire segmentations into multiple clusters and considers significant cluster for further analysis

args

voxels: np.uint8 height x width x depth threshold: number of pixels in cluster to

consider it as significant
returns
tensor with same size as voxels
DeepBrainSeg.helpers.postprocessing.densecrf(logits)[source]

applies coditional random fields on predictions The idea is consider the nbr voxels in making class prediction of current pixel

refer CRF and MRF papers for more theoretical idea

args
logits: Nb_classes x Height x Width x Depth
returns
tensor of size Height x Width x Depth

DeepBrainSeg.helpers.preprocessing module

DeepBrainSeg.helpers.preprocessing.clip(x, q=90)[source]

used to eliminate intensity outliers

q: percentile for max_value

DeepBrainSeg.helpers.preprocessing.normalize(img, mask=None)[source]
squeezes the intensity values between 0-1
(x - min(x)) / (max(x) - min(x))

img: ndarray, image used for analysis mask: ndarray, brain mask

DeepBrainSeg.helpers.preprocessing.resample3D(img, outputSize=None, interpolator=3)[source]

Resample 3D images Image, interpolates or subsamples the volume based on the arguments provided

img: ndarray, 3D volume outputSize: tuple (x,y,z), required dimension

of the image in output
interpolator: int (0, …, 5), type of interpolator

For Labels use nearest neighbour interpolation For image can use any:

sitkNearestNeighbor = 1, sitkLinear = 2, sitkBSpline = 3, sitkGaussian = 4, sitkLabelGaussian = 5,
DeepBrainSeg.helpers.preprocessing.standardize(img, mask=None, median=False)[source]

standardizes the volume by offsetting the intensities w.r.t mean or median on brain intensities and normalize with the standard deviation of intensity values

img: ndarray, image used for analysis mask: ndarray, brain mask median: boolean, arguments allowes us to use

median for offsetting intensity values

DeepBrainSeg.helpers.utils module

DeepBrainSeg.helpers.utils.adjust_classes(volume)[source]

readjusts class values in the form of brats data. Removes brain class and reassigns class 3 to class 4

args
volume: segmentaiton mask with Height x Width x Depth
returns
tensor with same dimension as input volume
DeepBrainSeg.helpers.utils.adjust_classes_air_brain_tumour(volume)[source]

Converts ABL classes to AL class as brain is introduced class, it is merged with air in this funciton

args
volume: segmentation mask (H x W x D)
returns
tensor with same dimension as volume
DeepBrainSeg.helpers.utils.apply_argmax_to_logits(logits)[source]

Applies argmax to logits along dimension 0

args
logits dimensions: nclasses x Height x Width x Depth
returns
tensor with dimension Height x Width x Depth (uint8)
DeepBrainSeg.helpers.utils.bbox(vol, pad=18)[source]

estimates closest bounding rect for the tumor

args

vol: segmentation mask (H x W X D) with tumor pad: int; number of zeros to be padded to the

estimated bounding box
returns
tuple(<int> of len 6):
xmin, xmax, ymin, ymax, zmin, zmax
DeepBrainSeg.helpers.utils.combine_logits_AM(x)[source]

Method to ensemble the predictions of multiple models considers AM over logits

estimates $$

rac{Sum x_i}{len(x)}$$

args
x: list of all predictions
returns
tensor of dimension same as x[0]
DeepBrainSeg.helpers.utils.combine_logits_GM(x)[source]

Method to ensemble the predictions of multiple models considers GM over logits

estimates $$(Prod x_i)^{1/len(x)}$$
args
x: list of all predictions
returns
tensor of dimension same as x[0]
DeepBrainSeg.helpers.utils.combine_mask_prediction(mask, pred)[source]

Conbines final inner class predictions with localized predictions

args
mask: localized prediction tensor pred: inner class prediction tensor
returns
tensor of same dimension as mask or pred
DeepBrainSeg.helpers.utils.combine_predictions_AM(x)[source]

Method to ensemble the predictions of multiple models considers AM over predictions

estimates $$

rac{Sum x_i}{len(x)}$$

args
x: list of all predictions
returns
tensor of dimension same as x[0]
DeepBrainSeg.helpers.utils.combine_predictions_GM(x)[source]

Method to ensemble the predictions of multiple models considers GM over predictions

estimates $$(Prod x_i)^{1/len(x)}$$
args
x: list of all predictions
returns
tensor of dimension same as x[0]
DeepBrainSeg.helpers.utils.convert5class_logitsto_4class(logits)[source]

Merges brain class with background

args
logits: 5 x H x W x D
returns
tensor of dim 4 x H x W x D
DeepBrainSeg.helpers.utils.convert_image(image)[source]

Rearranging image channels accordingly

args
image: W x H x C
returns
image: C x W x H
DeepBrainSeg.helpers.utils.get_brain_mask(t1)[source]

Provides an alternative for ANTs used to extract brain mask given raw image Does the task of skull stripping

t1: T1 MRI volume: height x width x depth

returns: boolean mask

DeepBrainSeg.helpers.utils.get_dice_score(prediction, ground_truth)[source]

Calculates dice coefficient for each class

calculates $$

rac{2*A cap B}{A cup B}$$

args
prediction: ndarray with predicted segmentation classes ground_truth: ndarray with expected segmentation classes
returns
tuple(<float> of len 3) whole tumor dice,
enhancing tumor dice, and tumor core dice
DeepBrainSeg.helpers.utils.get_enhancing_tumor(data)[source]

gets enhancing tumor region from a given segmentation mask

args
data: ndarray (uint8)
returns
boolean array with same dimension as data
DeepBrainSeg.helpers.utils.get_tumor_core(data)[source]

gets tumor core region from a given segmentation mask

args
data: ndarray (uint8)
returns
boolean array with same dimension as data
DeepBrainSeg.helpers.utils.get_whole_tumor(data)[source]

gets whole tumor region from a given segmentation mask

args
data: ndarray (uint8)
returns
boolean array with same dimension as data
DeepBrainSeg.helpers.utils.imshow(*args, **kwargs)[source]

Handy function to show multiple plots in on row, possibly with different cmaps and titles

Usage: imshow(img1, title=”myPlot”) imshow(img1,img2, title=[‘title1’,’title2’]) imshow(img1,img2, cmap=’hot’) imshow(img1,img2,cmap=[‘gray’,’Blues’])

DeepBrainSeg.helpers.utils.save_volume(volume, affine, path)[source]

saves given volume into nifty format based on given affine

args

volume: ndarray to be converted to nifty affine: orientation information usually

extracted from raw image

path: path to save nifty data

DeepBrainSeg.helpers.utils.scale_every_slice_between_0_to_255(x)[source]

renormalizes the intensity values between (0, 256)

args
x: ndarray
returns
tensor of same dimension as x with p2p (0, 256)

Module contents