Insight Toolkit for N-dimensional image processing, segmentation, and registration in medical and scientific applications
—
Level set methods for segmentation including geodesic active contours, shape detection, and threshold-based approaches.
class GeodesicActiveContourLevelSetImageFilter:
"""
Geodesic active contour level set segmentation.
Template parameters:
- input_image_type: Input image type (feature image)
- output_image_type: Output image type (level set)
"""
def SetFeatureImage(self, image):
"""Set the feature image (edge potential)."""
def SetPropagationScaling(self, scaling):
"""
Set propagation scaling.
Parameters:
- scaling: float - Propagation weight
"""
def SetCurvatureScaling(self, scaling):
"""Set curvature scaling (smoothness)."""
def SetAdvectionScaling(self, scaling):
"""Set advection scaling."""
def SetNumberOfIterations(self, iterations):
"""Set number of iterations."""
def SetMaximumRMSError(self, error):
"""Set convergence criterion."""class ShapeDetectionLevelSetImageFilter:
"""
Shape detection level set filter.
Template parameters:
- input_image_type: Input image type
- output_image_type: Output image type
"""
def SetFeatureImage(self, image):
"""Set the feature image."""
def SetPropagationScaling(self, scaling):
"""Set propagation scaling."""
def SetCurvatureScaling(self, scaling):
"""Set curvature scaling."""
def SetNumberOfIterations(self, iterations):
"""Set number of iterations."""class ThresholdSegmentationLevelSetImageFilter:
"""
Threshold-based level set segmentation.
Template parameters:
- input_image_type: Input image type
- feature_image_type: Feature image type
"""
def SetFeatureImage(self, image):
"""Set the feature image."""
def SetUpperThreshold(self, threshold):
"""Set upper intensity threshold."""
def SetLowerThreshold(self, threshold):
"""Set lower intensity threshold."""
def SetCurvatureScaling(self, scaling):
"""Set curvature scaling."""
def SetPropagationScaling(self, scaling):
"""Set propagation scaling."""
def SetNumberOfIterations(self, iterations):
"""Set number of iterations."""class CannySegmentationLevelSetImageFilter:
"""
Canny edge-based level set segmentation.
Template parameters:
- input_image_type: Input image type
- feature_image_type: Feature image type
"""
def SetFeatureImage(self, image):
"""Set the feature image."""
def SetThreshold(self, threshold):
"""Set Canny edge threshold."""
def SetVariance(self, variance):
"""Set Gaussian smoothing variance."""
def SetCurvatureScaling(self, scaling):
"""Set curvature scaling."""
def SetPropagationScaling(self, scaling):
"""Set propagation scaling."""import itk
# Load image
image = itk.imread('input.png', itk.F)
# Compute edge potential (feature image)
gradient = itk.gradient_magnitude_recursive_gaussian_image_filter(image, sigma=1.0)
sigmoid = itk.sigmoid_image_filter(gradient, alpha=-1.0, beta=128.0, output_minimum=0.0, output_maximum=1.0)
# Create initial level set (e.g., from seeds)
initial = itk.imread('initial_contour.png', itk.F)
# Set up level set filter
ImageType = itk.Image[itk.F, 2]
level_set = itk.GeodesicActiveContourLevelSetImageFilter[ImageType, ImageType].New()
level_set.SetInput(initial)
level_set.SetFeatureImage(sigmoid)
level_set.SetPropagationScaling(1.0)
level_set.SetCurvatureScaling(1.0)
level_set.SetAdvectionScaling(1.0)
level_set.SetNumberOfIterations(100)
level_set.SetMaximumRMSError(0.02)
level_set.Update()
result = level_set.GetOutput()
# Threshold level set to get binary result
binary = itk.binary_threshold_image_filter(result, lower_threshold=0.0, inside_value=255, outside_value=0)
itk.imwrite(binary, 'segmented.png')Install with Tessl CLI
npx tessl i tessl/pypi-itk@5.4.1docs
guides
reference