preprocess module

class preprocess.preGlioma

Bases: object

This class is for preprocessing. Mainly wrote for gliomas but it is used in meningiomas too

bet(img)

Performing bet using another library

Parameters

img (nib.nifti) – Input image

Returns

Brain extracted image

Return type

[torch.tensor]

betfsl(segs, root='/cta/users/abas/Desktop/Meningiom/MeningiomData/preprocessed/')

Performing fsl-bet using python

Parameters
  • segs (torch.tensor) – segmentation paths. It is needed for finding the corresponding image

  • root (str, optional) – Root path of the images. Defaults to ‘/cta/users/abas/Desktop/Meningiom/MeningiomData/preprocessed/’.

Returns

Result situation

Return type

[str]

cut_tumor_image(seg)

Cutting the tumor image from the segmentation

Parameters

seg (segmentatiom) – [description]

Returns

[description]

Return type

[type]

normalize(img, typx='unit-variance', masked=False)

Normalization step of the image

Parameters
  • img (np.array) – image to be normalized

  • typx (str, optional) – Type of normalization [min-max, unit-variance]. Defaults to ‘unit-variance’.

  • masked (bool, optional) – Mask is for eliminate the zeroish voxels. Defaults to False.

Returns

Normalized image

Return type

[np.array]

patch_chopper(imgs, patch_size=256, dim=0)

This function is used to chop the image into patches

Parameters
  • imgs (list) – input images

  • patch_size (int, optional) – Defaults to 256.

  • dim (int, optional) – Defaults to 0.

Returns

list chopped images tensors

Return type

[list]

reconstruct(images, org_size, labels=None)

Reconstructing the image from the patches

Parameters
  • images (list) – List of patches

  • org_size (shape) – Not used in this version. Deprecated

  • labels (list ,optional) – Defaults to None. If it is not none it will reconstruct image with the labels gathered from the patches using classifier network

Returns

Reconstructed image

Return type

torch.tensor

reverse_pad(image, org_size)

Reverse padding of initialized class

Parameters
  • image (torch.tensor) – Reconstructed image with padding

  • org_size (org_size) – Original size of the image

Returns

Reverse padded image

Return type

torch.tensor

save_image(images, segs, image, seg, name, root='/cta/users/abas/Desktop/Meningiom/MeningiomData/preprocessed/')

Saving the tensors of images

Parameters
  • images (list) – Chopped images

  • segs (list) – Chopped segmentations

  • image (np.array) – Original image

  • seg (np.array) – Original segmentation

  • name (str) – Name of the image

  • root (str, optional) – Save path. Defaults to ‘/cta/users/abas/Desktop/Meningiom/MeningiomData/preprocessed/’.

slice_chopper(img, seg=None, slices=5, dim=- 1, phase='test')

This function is used to chop the image into slices (Not implemented in s100 project it is needed for the patch-wise projects)

Parameters
  • img (torch.tensor) – Image to be chopped

  • seg (torch.tensor, optional) – Segmentation mask . Defaults to None.

  • slices (int, optional) – Number of the slices. Defaults to 5.

  • dim (int, optional) – Dimension of the splitting occurs. Defaults to -1.

  • phase (str, optional) – Defaults to ‘test’.

Returns

List of torch tensors

Return type

[list]