tbp.monty.frameworks.models.salience.segmentation#
tbp.monty.frameworks.models.salience.segmentation.slic_merge#
- class SlicMerge(n_seeds: int = 70, compactness: float = 10.0, max_iter: int = 10, sigma: float = 1.0, min_size_factor: float = 0.5, max_size_factor: float = 3.0, merge_threshold: float = 0.04) None[source]#
Bases:
SegmentationStrategyScikit-image SLIC superpixel segmentation with region merging.
Returned region encloses the central point of fixation. Merging strategy is a breadth-first merge around the central region.
See https://scikit-image.org/docs/stable/api/skimage.segmentation.html#skimage.segmentation.slic
- static build_adjacency_graph(region_image: NDArray[int64], n_regions: int) list[set[int]][source]#
Builds the adjency graph.
- static compute_superpixel_mean_colors(region_image: NDArray[int64], merge_image: NDArray[float32]) NDArray[float32][source]#
- Return type:
NDArray[single]
- static create_mask(region_image: NDArray[int64], accepted_regions: set[int]) NDArray[uint8][source]#
- Return type:
NDArray[ubyte]
- static extract_region_colors(rgb: NDArray[uint8], region_image: NDArray[int64]) NDArray[float32][source]#
Returns the mean color of each superpixel in LAB 0-1 color space.
- Return type:
NDArray[single]
- __init__(n_seeds: int = 70, compactness: float = 10.0, max_iter: int = 10, sigma: float = 1.0, min_size_factor: float = 0.5, max_size_factor: float = 3.0, merge_threshold: float = 0.04) None[source]#
Initialize the SLIC superpixel segmentation with region merging strategy.
- Parameters:
n_seeds (
int) – Number of superpixels to generate, though this is approximate. SLIC initializes seeds on a regular lattice, so the actual number of superpixels may be larger.compactness (
float) – Balances color proximity and space proximity. Higher values give more weight to space proximity, resulting in more square superpixels.max_iter (
int) – Maximum number of iterations for SLIC.sigma (
float) – Width of Gaussian smoothing kernel for pre-processing.min_size_factor (
float) – Minimum superpixel size, as a fraction of the nominal size image_pixels / n_seeds. Smaller connected fragments are merged into an adjacent superpixel.max_size_factor (
float) – Maximum superpixel size, as a fraction of the nominal size. Larger connected regions are split.merge_threshold (
float) – Color distance threshold for merging superpixels. Pertains to the LAB 0-1 space.