liom_toolkit.segmentation.plane_segmentation module

liom_toolkit.segmentation.plane_segmentation.erode_mask(mask: ndarray, disk_size: int = 30) ndarray

Erode the outer edge of a mask

Parameters:
  • mask (np.ndarray) – The mask to erode

  • disk_size (int) – The size of the disk to use for erosion

Returns:

The eroded mask

Return type:

np.ndarray

liom_toolkit.segmentation.plane_segmentation.estimate_tissue_mask(img: ndarray) ndarray

Estimate the tissue mask from an image. Based on function found here: https://github.com/joe-from-mtl/sbhassisant-2d-3d-registration

Parameters:

img (np.ndarray) – The image to estimate the mask from

Returns:

The tissue mask

Return type:

np.ndarray

liom_toolkit.segmentation.plane_segmentation.frangi_filter(img: ndarray, sigma_range: tuple, black_ridges: bool = False) ndarray

Apply the Frangi filter to an image

Parameters:
  • img (np.ndarray) – The image to apply the filter to

  • sigma_range (tuple) – The range of sigmas to use (start, stop, step)

  • black_ridges (bool) – Whether to detect black ridges

Returns:

The filtered image

Return type:

np.ndarray

liom_toolkit.segmentation.plane_segmentation.li_threshold_image(img: ndarray) ndarray

Apply the Li thresholding algorithm to an image

Parameters:

img (np.ndarray) – The image to apply the thresholding to

Returns:

The thresholded image

Return type:

np.ndarray

liom_toolkit.segmentation.plane_segmentation.remove_small_structures(img: ndarray, mask: ndarray) ndarray

Remove small structures from a mask

Parameters:
  • img (np.ndarray) – The image with which the mask was generated

  • mask (np.ndarray) – The mask to remove small structures from

Returns:

The mask with small structures removed

Return type:

np.ndarray

liom_toolkit.segmentation.plane_segmentation.sauvola_threshold_image(img: ndarray, window_size: int = 15) ndarray

Apply the Sauvola thresholding algorithm to an image

Parameters:
  • img (np.ndarray) – The image to apply the thresholding to

  • window_size (int) – The size of the window to use for thresholding

Returns:

The thresholded image

Return type:

np.ndarray

liom_toolkit.segmentation.plane_segmentation.segment_2d_image(output_dir: str, image: ndarray, name: str, frangi_sigma_range: tuple = (2, 16, 2), frangi_black_ridges: bool = False, local_threshold: bool = False, local_threshold_size: int = 15) None

Segment 2D images. Finished files are not returned due to memory concerns, but are saved to disk.

Parameters:
  • output_dir (str) – The directory to save the results to

  • image (np.ndarray) – The image to segment

  • name (str) – The name of the image

  • frangi_sigma_range (tuple) – The range of sigmas to use for the Frangi filter

  • frangi_black_ridges (bool) – Whether to detect black ridges

  • local_threshold (bool) – Whether to use local thresholding

  • local_threshold_size (int) – The size of the local thresholding window, must be odd

liom_toolkit.segmentation.plane_segmentation.subtract_background(img: ndarray, radius: int = 70) ndarray

Subtract background from image using rolling ball algorithm

Parameters:
  • img (np.ndarray) – The image to subtract the background from

  • radius (int) – The radius of the rolling ball

Returns:

The background subtracted image

Return type:

np.ndarray