nispace.utils.utils.get_background_value

nispace.utils.utils.get_background_value(img, border_size=2)[source]

Auto-detect a volumetric image’s background value from its border voxels.

Adapted from nilearn.masking.compute_background_mask. Only implemented for 3D/volumetric input — for anything else (e.g. surface data), this silently returns None rather than raising. Used by Parcellater to resolve background_value="auto" (see [[project_parcellation_bg_handling]]).

Parameters:
  • img (image-like) – Input accepted by neuromaps.images.load_data.

  • border_size (int, default=2) – Border thickness (in voxels) sampled to estimate the background.

Returns:

The detected background value (border median), np.nan if any border voxel is NaN, or None if img is not 3D.

Return type:

float, np.nan, or None