openlifu.seg.skinseg.compute_foreground_mask

openlifu.seg.skinseg.compute_foreground_mask(vol_array: ndarray, closing_radius: float = 9.0, lower_quantile_for_otsu_threshold: float = 0.02, upper_quantile_for_otsu_threshold: float = 0.99) ndarray[source]

Given a 3D image array, return a boolean mask representing the “foreground.”

Parameters:
  • vol_array – a 3D image array of shape (H,W,D)

  • closing_readius – the radius of the ball used in the morphological closing operation

  • lower_quantile_for_otsu_threshold – a number from 0 to 1. Before otsu thresholding, values below this quantile are omitted from the histogram as outliers.

  • upper_quantile_for_otsu_threshold – a number from 0 to 1. Before otsu thresholding, values above this quantile are omitted from the histogram as outliers.

Returns: a boolean array of shape (H,W,D) representing a foreground mask

This is essentially a port of the BRAINSTools automated foreground masking algorithm. - Original algorithm documentation: https://slicer.readthedocs.io/en/latest/user_guide/modules/brainsroiauto.html - Original algorithm code: https://github.com/BRAINSia/BRAINSTools/tree/7c37d9e8c238f66f8a83f997d9c9bb659c494c90/BRAINSROIAuto

The algorithm roughly works as follows: - step 1: otsu thresholding - step 2: keep only the largest connected component - step 3: morphological closing - step 4: hole filling

The default values of the parameters have been observed to work well for mm-spaced brain MRIs.