CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-simpleitk

SimpleITK is a simplified interface to the Insight Toolkit (ITK) for image registration and segmentation

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

segmentation.mddocs/reference/filters/

Segmentation Filters

Filters for partitioning images into regions based on intensity, connectivity, or shape. Includes region growing, level set methods, watershed segmentation, connected components, and superpixel algorithms.

Capabilities

Region Growing Segmentation

class ConnectedThresholdImageFilter:
    """Region growing with intensity threshold."""

    def SetSeedList(self, seeds: list[tuple[int, ...]]) -> None:
        """
        Set seed point indices.

        Args:
            seeds: List of seed indices [(x1,y1,z1), (x2,y2,z2), ...]
        """

    def AddSeed(self, seed: tuple[int, ...]) -> None:
        """Add single seed point."""

    def ClearSeeds(self) -> None:
        """Clear all seeds."""

    def SetLower(self, threshold: float) -> None:
        """Set lower intensity threshold."""

    def SetUpper(self, threshold: float) -> None:
        """Set upper intensity threshold."""

    def SetReplaceValue(self, value: float) -> None:
        """Set output value for segmented region."""

    def Execute(self, image):
        """
        Grow region from seeds within intensity range.

        Returns:
            Binary segmentation
        """

def ConnectedThreshold(image, seedList: list[tuple[int, ...]], lower: float = 0,
                        upper: float = 1, replaceValue: float = 1):
    """Procedural: connected threshold segmentation."""

class ConfidenceConnectedImageFilter:
    """Region growing with automatic threshold from statistics."""

    def SetSeedList(self, seeds: list[tuple[int, ...]]) -> None:
        """Set seed points."""

    def SetMultiplier(self, multiplier: float) -> None:
        """
        Set threshold multiplier for standard deviation.

        Threshold = mean +/- multiplier * stddev

        Args:
            multiplier: Multiplier value
        """

    def SetNumberOfIterations(self, iterations: int) -> None:
        """Set number of iterations."""

    def SetInitialNeighborhoodRadius(self, radius: int) -> None:
        """Set initial neighborhood radius for statistics."""

    def SetReplaceValue(self, value: float) -> None:
        """Set output value."""

    def Execute(self, image):
        """Returns: binary segmentation"""

def ConfidenceConnected(image, seedList: list[tuple[int, ...]], numberOfIterations: int = 4,
                         multiplier: float = 2.5, initialNeighborhoodRadius: int = 1,
                         replaceValue: float = 1):
    """Procedural: confidence connected segmentation."""

class NeighborhoodConnectedImageFilter:
    """Region growing using neighborhood statistics."""

    def SetSeedList(self, seeds: list[tuple[int, ...]]) -> None:
        """Set seed points."""

    def SetLower(self, threshold: float) -> None:
        """Set lower threshold."""

    def SetUpper(self, threshold: float) -> None:
        """Set upper threshold."""

    def SetRadius(self, radius: int | tuple[int, ...]) -> None:
        """Set neighborhood radius."""

    def SetReplaceValue(self, value: float) -> None:
        """Set output value."""

    def Execute(self, image):
        """Returns: binary segmentation"""

class IsolatedConnectedImageFilter:
    """Segment region between two seed sets."""

    def SetSeed1(self, seed: tuple[int, ...]) -> None:
        """Set first seed (region to segment)."""

    def SetSeed2(self, seed: tuple[int, ...]) -> None:
        """Set second seed (region to avoid)."""

    def SetLower(self, threshold: float) -> None:
        """Set lower threshold."""

    def SetUpper(self, threshold: float) -> None:
        """Set upper threshold (will be adjusted)."""

    def SetIsolatedValueTolerance(self, tolerance: float) -> None:
        """Set tolerance for isolation."""

    def SetReplaceValue(self, value: float) -> None:
        """Set output value."""

    def Execute(self, image):
        """Returns: binary segmentation"""

    def GetIsolatedValue(self) -> float:
        """Get computed isolation threshold."""

class VectorConfidenceConnectedImageFilter:
    """Confidence connected for multi-component images."""

    def SetSeedList(self, seeds: list[tuple[int, ...]]) -> None:
        """Set seed points."""

    def SetMultiplier(self, multiplier: float) -> None:
        """Set threshold multiplier."""

    def SetNumberOfIterations(self, iterations: int) -> None:
        """Set iterations."""

    def SetReplaceValue(self, value: float) -> None:
        """Set output value."""

    def Execute(self, image):
        """Returns: binary segmentation"""

Connected Component Labeling

class ConnectedComponentImageFilter:
    """Label connected components in binary image."""

    def SetFullyConnected(self, fullyConnected: bool) -> None:
        """
        Use full connectivity.

        Args:
            fullyConnected: If True, use face+edge+vertex connectivity.
                           If False, use face connectivity only.
        """

    def Execute(self, image):
        """
        Label connected components.

        Returns:
            Labeled image (each component has unique integer label)
        """

    def GetObjectCount(self) -> int:
        """Get number of labeled objects (call after Execute)."""

def ConnectedComponent(image, fullyConnected: bool = False):
    """Procedural: connected component labeling."""

class ScalarConnectedComponentImageFilter:
    """Label connected components based on intensity."""

    def SetDistanceThreshold(self, threshold: float) -> None:
        """Set maximum intensity difference for connectivity."""

    def SetFullyConnected(self, fullyConnected: bool) -> None:
        """Use full connectivity."""

    def Execute(self, image):
        """Returns: labeled image"""

    def GetObjectCount(self) -> int:
        """Get number of objects."""

class RelabelComponentImageFilter:
    """Relabel components by size (largest = 1)."""

    def SetMinimumObjectSize(self, size: int) -> None:
        """Set minimum size to keep (smaller components removed)."""

    def SetSortByObjectSize(self, sort: bool) -> None:
        """Sort by size (largest first)."""

    def Execute(self, labelImage):
        """
        Relabel by size.

        Returns:
            Relabeled image
        """

    def GetNumberOfObjects(self) -> int:
        """Get number of objects."""

    def GetSizeOfObjectsInPixels(self) -> tuple[int, ...]:
        """Get size of each object."""

def RelabelComponent(labelImage, minimumObjectSize: int = 0, sortByObjectSize: bool = True):
    """Procedural: relabel by size."""

Level Set Segmentation

class GeodesicActiveContourLevelSetImageFilter:
    """Geodesic active contour level set segmentation."""

    def SetPropagationScaling(self, scaling: float) -> None:
        """Set propagation term scaling."""

    def SetCurvatureScaling(self, scaling: float) -> None:
        """Set curvature term scaling."""

    def SetAdvectionScaling(self, scaling: float) -> None:
        """Set advection term scaling."""

    def SetMaximumRMSError(self, error: float) -> None:
        """Set maximum RMS error for convergence."""

    def SetNumberOfIterations(self, iterations: int) -> None:
        """Set maximum iterations."""

    def Execute(self, initialImage, featureImage):
        """
        Evolve level set.

        Args:
            initialImage: Initial level set (signed distance)
            featureImage: Feature image (e.g., edge map)

        Returns:
            Final level set
        """

class ShapeDetectionLevelSetImageFilter:
    """Shape detection level set."""

    def SetPropagationScaling(self, scaling: float) -> None:
        """Set propagation scaling."""

    def SetCurvatureScaling(self, scaling: float) -> None:
        """Set curvature scaling."""

    def SetMaximumRMSError(self, error: float) -> None:
        """Set convergence tolerance."""

    def SetNumberOfIterations(self, iterations: int) -> None:
        """Set iterations."""

    def Execute(self, initialImage, featureImage):
        """Returns: final level set"""

class ThresholdSegmentationLevelSetImageFilter:
    """Threshold-based level set."""

    def SetLowerThreshold(self, threshold: float) -> None:
        """Set lower intensity threshold."""

    def SetUpperThreshold(self, threshold: float) -> None:
        """Set upper intensity threshold."""

    def SetCurvatureScaling(self, scaling: float) -> None:
        """Set curvature scaling."""

    def SetPropagationScaling(self, scaling: float) -> None:
        """Set propagation scaling."""

    def SetMaximumRMSError(self, error: float) -> None:
        """Set convergence tolerance."""

    def SetNumberOfIterations(self, iterations: int) -> None:
        """Set iterations."""

    def Execute(self, initialImage, featureImage):
        """Returns: final level set"""

Watershed Segmentation

class WatershedImageFilter:
    """Traditional watershed segmentation."""

    def SetLevel(self, level: float) -> None:
        """Set flood level."""

    def SetThreshold(self, threshold: float) -> None:
        """Set threshold for merging."""

    def Execute(self, image):
        """
        Watershed segmentation.

        Returns:
            Labeled watershed basins
        """

def Watershed(image, level: float = 0, threshold: float = 0):
    """Procedural: watershed."""

SLIC Superpixels

class SLICImageFilter:
    """SLIC superpixel segmentation."""

    def SetSuperGridSize(self, size: tuple[int, ...]) -> None:
        """
        Set approximate superpixel grid size.

        Args:
            size: Grid dimensions (determines number of superpixels)
        """

    def SetSpatialProximityWeight(self, weight: float) -> None:
        """
        Set spatial proximity weight (vs color similarity).

        Higher values emphasize spatial compactness.

        Args:
            weight: Spatial weight (typically 10-40)
        """

    def SetMaximumNumberOfIterations(self, iterations: int) -> None:
        """Set maximum iterations."""

    def SetInitializationPerturbation(self, perturbation: bool) -> None:
        """Enable initial perturbation to avoid edges."""

    def SetEnforceConnectivity(self, enforce: bool) -> None:
        """Enforce connectivity of superpixels."""

    def Execute(self, image):
        """
        Compute SLIC superpixels.

        Returns:
            Label image with superpixel labels
        """

def SLIC(image, superGridSize: tuple[int, ...] = (50, 50),
         spatialProximityWeight: float = 10.0, maximumNumberOfIterations: int = 5,
         enforceConnectivity: bool = True):
    """Procedural: SLIC superpixels."""

Voting and Consensus

class VotingBinaryImageFilter:
    """Binary voting filter for consensus segmentation."""

    def SetRadius(self, radius: int | tuple[int, ...]) -> None:
        """Set voting neighborhood radius."""

    def SetBirthThreshold(self, threshold: int) -> None:
        """Set threshold for pixel birth."""

    def SetSurvivalThreshold(self, threshold: int) -> None:
        """Set threshold for pixel survival."""

    def SetForegroundValue(self, value: float) -> None:
        """Set foreground value."""

    def SetBackgroundValue(self, value: float) -> None:
        """Set background value."""

    def Execute(self, image):
        """Returns: voted binary image"""

class VotingBinaryIterativeHoleFillingImageFilter:
    """Iterative hole filling using voting."""

    def SetRadius(self, radius: int | tuple[int, ...]) -> None:
        """Set neighborhood radius."""

    def SetMaximumNumberOfIterations(self, iterations: int) -> None:
        """Set maximum iterations."""

    def SetMajorityThreshold(self, threshold: int) -> None:
        """Set majority voting threshold."""

    def SetForegroundValue(self, value: float) -> None:
        """Set foreground value."""

    def SetBackgroundValue(self, value: float) -> None:
        """Set background value."""

    def Execute(self, image):
        """Returns: hole-filled image"""

class STAPLEImageFilter:
    """STAPLE consensus segmentation from multiple observers."""

    def SetForegroundValue(self, value: float) -> None:
        """Set foreground value in input segmentations."""

    def SetMaximumIterations(self, iterations: int) -> None:
        """Set maximum EM iterations."""

    def Execute(self, *segmentations):
        """
        Compute consensus segmentation.

        Args:
            segmentations: Multiple binary segmentation images

        Returns:
            Probabilistic consensus segmentation
        """

    def GetSensitivity(self, observer: int) -> float:
        """Get sensitivity for observer."""

    def GetSpecificity(self, observer: int) -> float:
        """Get specificity for observer."""

class MultiLabelSTAPLEImageFilter:
    """Multi-label STAPLE for consensus."""

    def Execute(self, *segmentations):
        """Returns: consensus label image"""

Common Patterns

Region Growing from Seeds

import SimpleITK as sitk

# Define seeds
seeds = [(128, 128, 64), (130, 130, 64)]

# Segment with threshold
segmentation = sitk.ConnectedThreshold(
    image,
    seedList=seeds,
    lower=100,
    upper=200
)

Connected Component Analysis

import SimpleITK as sitk

# Label components
labeled = sitk.ConnectedComponent(binary_image, fullyConnected=True)

# Sort by size and remove small objects
labeled = sitk.RelabelComponent(labeled, minimumObjectSize=100)

Superpixel Segmentation

import SimpleITK as sitk

# Generate superpixels
superpixels = sitk.SLIC(
    image,
    superGridSize=(20, 20, 20),
    spatialProximityWeight=10.0
)

Install with Tessl CLI

npx tessl i tessl/pypi-simpleitk

docs

index.md

tile.json