CerebNet.data_loader.data_utils

CerebNet.data_loader.data_utils.create_weight_mask2d(label_map, class_wise_weights, max_edge_weight=5)[source]

Function to create weighted mask - with median frequency balancing and edge-weighting.

Parameters:
label_mapnp.ndarray

A 2D array representing the label map.

class_wise_weightsnp.ndarray

A 1D array where each element is the weight corresponding to a class in the label map.

max_edge_weightfloat, default=5

The maximum weight to be applied at the edges in the label map to emphasize boundaries.

CerebNet.data_loader.data_utils.filter_blank_slices_thick(data_dict, img_key='img', lbl_key='label', threshold=10)[source]

Function to filter blank slices from the volume using the label volume.

Parameters:
data_dictdict

A dictionary containing all volumes that need to be filtered.

img_keystr, default=”img”

Name of the key with the image.

lbl_keystr, default=”label”

Name of the key with the target label.

thresholdint, default=10

Threshold for number of voxels so this slice is included (or filtered).

CerebNet.data_loader.data_utils.get_aseg_cereb_mask(aseg_map)[source]

Get a boolean mask of the cerebellum from a segmentation image.

Parameters:
aseg_mapnp.ndarray

A segmentation image.

Returns:
np.ndarray

A boolean mask of the cerebellum.

CerebNet.data_loader.data_utils.map_prediction_sagittal2full(prediction_sag, lbl_type)[source]

Function to remap the prediction on the sagittal network to full label space used by coronal and axial networks.

Parameters:
prediction_sagnp.ndarray

Sagittal prediction (labels).

lbl_typestr

Type of label.

Returns:
np.ndarray

Remapped prediction.

CerebNet.data_loader.data_utils.map_sag2label(lbl_data, label_type='cereb_subseg')[source]

Mapping right ids to left and relabeling.

Parameters:
lbl_datanp.ndarray

An array of label data.

label_typestr, default=”cereb_subseg”

A string identifier for the type of labels to map to.

Returns:
np.ndarray

The remapped label array with continuous labels.

CerebNet.data_loader.data_utils.slice_lia2ras(plane, data, /, thick_slices=False)[source]

Maps the data from LIA to RAS orientation.

Parameters:
planePlane

The slicing direction (usually moved into batch dimension).

datanp.ndarray

The data array of shape [plane, Channels, H, W].

thick_slicesbool, default = False

Whether the channels are thick slices and should also be flipped.

Returns:
np.ndarray

Data reoriented from LIA to RAS of [plane, Channels, H, W] (plane: ‘sagittal’ or ‘coronal’) or [plane, Channels, W, H] (plane: ‘axial’).

CerebNet.data_loader.data_utils.slice_ras2lia(plane, data, /, thick_slices=False)[source]

Maps the data from RAS to LIA orientation.

Parameters:
planePlane

The slicing direction (usually moved into batch dimension).

datanp.ndarray

The data array of shape [plane, Channels, H, W].

thick_slicesbool, default=False

Whether the channels are thick slices and should also be flipped.

Returns:
np.ndarray

Data reoriented from RAS to LIA of [plane, Channels, H, W] (plane: ‘sagittal’ or ‘coronal’) or [plane, Channels, W, H] (plane: ‘axial’). The dtype of the array is the same as data.

CerebNet.data_loader.data_utils.transform_axial(vol, coronal2axial=True)[source]

Function to transform volume into Axial axis and back.

Parameters:
volnp.ndarray

Image volume to transform.

coronal2axialbool, default = True

If True (default), transforms from coronal to axial. If False, transforms from axial to coronal.

Returns:
np.ndarray

Transformed image volume.

CerebNet.data_loader.data_utils.transform_axial2sagittal(vol, axial2sagittal=True)[source]

Transform a volume into the Sagittal axis and back.

Parameters:
volnp.ndarray

The image volume to transform.

axial2sagittalbool, default=True

If True (default), transforms from axial to sagittal. If False, transforms from sagittal to axial.

Returns:
np.ndarray

The transformed image volume.

CerebNet.data_loader.data_utils.transform_coronal(vol, axial2coronal=True)[source]

Transform a volume into the coronal axis and back.

Parameters:
volnp.ndarray

The image volume to transform.

axial2coronalbool, default=True

If True (default), transforms from axial to coronal. If False, transforms from coronal to axial.

Returns:
np.ndarray

The transformed image volume.

CerebNet.data_loader.data_utils.transform_sagittal(vol, coronal2sagittal=True)[source]

Transform a volume into the Sagittal axis and back.

Parameters:
volnp.ndarray

The image volume to transform.

coronal2sagittalbool, default = True

If True (default), transforms from coronal to sagittal. If False, transforms from sagittal to coronal.

Returns:
np.ndarray

The transformed image volume.