SimpleITK is a simplified interface to the Insight Toolkit (ITK) for image registration and segmentation
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Filters for pixel-wise arithmetic operations, intensity transformations, comparisons, thresholding, and statistical computations. These filters operate on pixel intensities without considering spatial relationships.
Basic arithmetic operations between images or with constants.
class AddImageFilter:
"""Add two images pixel-wise."""
def Execute(self, image1, image2):
"""
Add images: output = image1 + image2
Returns:
Result image
"""
def Add(image1, image2):
"""Procedural: add two images."""
class SubtractImageFilter:
"""Subtract two images pixel-wise."""
def Execute(self, image1, image2):
"""Returns: image1 - image2"""
def Subtract(image1, image2):
"""Procedural: subtract images."""
class MultiplyImageFilter:
"""Multiply two images pixel-wise."""
def Execute(self, image1, image2):
"""Returns: image1 * image2"""
def Multiply(image1, image2):
"""Procedural: multiply images."""
class DivideImageFilter:
"""Divide two images pixel-wise."""
def Execute(self, image1, image2):
"""Returns: image1 / image2"""
def Divide(image1, image2):
"""Procedural: divide images."""
class AbsImageFilter:
"""Compute absolute value pixel-wise."""
def Execute(self, image):
"""Returns: |image|"""
def Abs(image):
"""Procedural: absolute value."""
class NegateImageFilter:
"""Negate pixel values."""
def Execute(self, image):
"""Returns: -image"""
def Negate(image):
"""Procedural: negate image."""
class SquareImageFilter:
"""Square pixel values."""
def Execute(self, image):
"""Returns: image^2"""
def Square(image):
"""Procedural: square image."""
class SqrtImageFilter:
"""Square root of pixel values."""
def Execute(self, image):
"""Returns: sqrt(image)"""
def Sqrt(image):
"""Procedural: square root."""Transcendental and trigonometric functions.
class ExpImageFilter:
"""Exponential function pixel-wise."""
def Execute(self, image):
"""Returns: exp(image)"""
def Exp(image):
"""Procedural: exponential."""
class LogImageFilter:
"""Natural logarithm pixel-wise."""
def Execute(self, image):
"""Returns: log(image)"""
def Log(image):
"""Procedural: natural log."""
class Log10ImageFilter:
"""Base-10 logarithm pixel-wise."""
def Execute(self, image):
"""Returns: log10(image)"""
def Log10(image):
"""Procedural: base-10 log."""
class PowImageFilter:
"""Raise to power pixel-wise."""
def SetConstant(self, exponent: float) -> None:
"""Set exponent value."""
def Execute(self, image):
"""Returns: image^exponent"""
def Pow(image, exponent: float):
"""Procedural: raise to power."""
class SinImageFilter:
"""Sine function pixel-wise."""
def Execute(self, image):
"""Returns: sin(image)"""
class CosImageFilter:
"""Cosine function pixel-wise."""
def Execute(self, image):
"""Returns: cos(image)"""
class TanImageFilter:
"""Tangent function pixel-wise."""
def Execute(self, image):
"""Returns: tan(image)"""
class AsinImageFilter:
"""Arcsine function pixel-wise."""
def Execute(self, image):
"""Returns: asin(image)"""
class AcosImageFilter:
"""Arccosine function pixel-wise."""
def Execute(self, image):
"""Returns: acos(image)"""
class AtanImageFilter:
"""Arctangent function pixel-wise."""
def Execute(self, image):
"""Returns: atan(image)"""Pixel-wise comparison operators producing binary output.
class EqualImageFilter:
"""Test equality pixel-wise."""
def Execute(self, image1, image2):
"""Returns: binary image where image1 == image2"""
def Equal(image1, image2):
"""Procedural: equality comparison."""
class NotEqualImageFilter:
"""Test inequality pixel-wise."""
def Execute(self, image1, image2):
"""Returns: binary image where image1 != image2"""
class GreaterImageFilter:
"""Greater than comparison."""
def Execute(self, image1, image2):
"""Returns: binary image where image1 > image2"""
def Greater(image1, image2):
"""Procedural: greater than."""
class GreaterEqualImageFilter:
"""Greater than or equal comparison."""
def Execute(self, image1, image2):
"""Returns: binary image where image1 >= image2"""
class LessImageFilter:
"""Less than comparison."""
def Execute(self, image1, image2):
"""Returns: binary image where image1 < image2"""
class LessEqualImageFilter:
"""Less than or equal comparison."""
def Execute(self, image1, image2):
"""Returns: binary image where image1 <= image2"""Bitwise logical operations on images.
class AndImageFilter:
"""Bitwise AND operation."""
def Execute(self, image1, image2):
"""Returns: image1 & image2"""
def And(image1, image2):
"""Procedural: bitwise AND."""
class OrImageFilter:
"""Bitwise OR operation."""
def Execute(self, image1, image2):
"""Returns: image1 | image2"""
def Or(image1, image2):
"""Procedural: bitwise OR."""
class XorImageFilter:
"""Bitwise XOR operation."""
def Execute(self, image1, image2):
"""Returns: image1 ^ image2"""
def Xor(image1, image2):
"""Procedural: bitwise XOR."""
class NotImageFilter:
"""Bitwise NOT operation."""
def Execute(self, image):
"""Returns: ~image"""
def Not(image):
"""Procedural: bitwise NOT."""Element-wise minimum and maximum.
class MaximumImageFilter:
"""Element-wise maximum of two images."""
def Execute(self, image1, image2):
"""Returns: max(image1, image2) pixel-wise"""
def Maximum(image1, image2):
"""Procedural: element-wise maximum."""
class MinimumImageFilter:
"""Element-wise minimum of two images."""
def Execute(self, image1, image2):
"""Returns: min(image1, image2) pixel-wise"""
def Minimum(image1, image2):
"""Procedural: element-wise minimum."""Transform intensity ranges and distributions.
class RescaleIntensityImageFilter:
"""Rescale intensities to new range."""
def SetOutputMinimum(self, minimum: float) -> None:
"""Set output minimum value."""
def SetOutputMaximum(self, maximum: float) -> None:
"""Set output maximum value."""
def Execute(self, image):
"""
Linearly rescale intensities to [outputMinimum, outputMaximum].
Returns:
Rescaled image
"""
def RescaleIntensity(image, outputMinimum: float = 0, outputMaximum: float = 255):
"""Procedural: rescale intensity range."""
class ShiftScaleImageFilter:
"""Shift and scale intensities: output = (input + shift) * scale."""
def SetShift(self, shift: float) -> None:
"""Set additive shift."""
def SetScale(self, scale: float) -> None:
"""Set multiplicative scale."""
def Execute(self, image):
"""Returns: (image + shift) * scale"""
def ShiftScale(image, shift: float = 0, scale: float = 1):
"""Procedural: shift and scale."""
class ClampImageFilter:
"""Clamp intensities to range."""
def SetLowerBound(self, lower: float) -> None:
"""Set lower bound."""
def SetUpperBound(self, upper: float) -> None:
"""Set upper bound."""
def Execute(self, image):
"""
Clamp values to [lowerBound, upperBound].
Returns:
Clamped image
"""
def Clamp(image, lowerBound: float, upperBound: float):
"""Procedural: clamp to range."""
class InvertIntensityImageFilter:
"""Invert intensity values."""
def SetMaximum(self, maximum: float) -> None:
"""Set maximum value for inversion."""
def Execute(self, image):
"""Returns: maximum - image"""
def InvertIntensity(image, maximum: float = None):
"""Procedural: invert intensities."""
class IntensityWindowingImageFilter:
"""Apply intensity windowing (like CT window/level)."""
def SetWindowMinimum(self, minimum: float) -> None:
"""Set window minimum (level - width/2)."""
def SetWindowMaximum(self, maximum: float) -> None:
"""Set window maximum (level + width/2)."""
def SetOutputMinimum(self, minimum: float) -> None:
"""Set output minimum."""
def SetOutputMaximum(self, maximum: float) -> None:
"""Set output maximum."""
def Execute(self, image):
"""
Map [windowMin, windowMax] to [outputMin, outputMax].
Returns:
Windowed image
"""
def IntensityWindowing(image, windowMinimum: float, windowMaximum: float,
outputMinimum: float = 0, outputMaximum: float = 255):
"""Procedural: intensity windowing."""
class NormalizeImageFilter:
"""Normalize to zero mean and unit variance."""
def Execute(self, image):
"""
Normalize: output = (input - mean) / stddev
Returns:
Normalized image
"""
def Normalize(image):
"""Procedural: normalize to mean=0, variance=1."""
class SigmoidImageFilter:
"""Apply sigmoid function for contrast enhancement."""
def SetAlpha(self, alpha: float) -> None:
"""Set alpha (controls steepness)."""
def SetBeta(self, beta: float) -> None:
"""Set beta (controls center point)."""
def SetOutputMinimum(self, minimum: float) -> None:
"""Set output minimum."""
def SetOutputMaximum(self, maximum: float) -> None:
"""Set output maximum."""
def Execute(self, image):
"""
Apply sigmoid: output = (max-min) / (1 + exp(-(input-beta)/alpha)) + min
Returns:
Sigmoid transformed image
"""
def Sigmoid(image, alpha: float = 1, beta: float = 0,
outputMinimum: float = 0, outputMaximum: float = 1):
"""Procedural: sigmoid transformation."""Convert images to binary based on intensity thresholds.
class BinaryThresholdImageFilter:
"""Binary thresholding with inside/outside values."""
def SetLowerThreshold(self, threshold: float) -> None:
"""Set lower threshold."""
def SetUpperThreshold(self, threshold: float) -> None:
"""Set upper threshold."""
def SetInsideValue(self, value: float) -> None:
"""Value for pixels within [lower, upper]."""
def SetOutsideValue(self, value: float) -> None:
"""Value for pixels outside range."""
def Execute(self, image):
"""
Binary threshold: insideValue if lower <= pixel <= upper, else outsideValue.
Returns:
Binary image
"""
def BinaryThreshold(image, lowerThreshold: float = 0, upperThreshold: float = 255,
insideValue: int = 1, outsideValue: int = 0):
"""Procedural: binary threshold."""
class ThresholdImageFilter:
"""Threshold with replacement values."""
def SetLower(self, lower: float) -> None:
"""Set lower threshold."""
def SetUpper(self, upper: float) -> None:
"""Set upper threshold."""
def SetOutsideValue(self, value: float) -> None:
"""Replacement value for pixels outside range."""
def Execute(self, image):
"""
Replace pixels outside [lower, upper] with outsideValue.
Returns:
Thresholded image
"""
def Threshold(image, lower: float, upper: float, outsideValue: float = 0):
"""Procedural: threshold with replacement."""Automatically determine threshold values using various algorithms.
class OtsuThresholdImageFilter:
"""Otsu's automatic threshold (minimizes within-class variance)."""
def SetNumberOfHistogramBins(self, bins: int) -> None:
"""Set histogram bins for threshold calculation."""
def SetInsideValue(self, value: float) -> None:
"""Value for pixels above threshold."""
def SetOutsideValue(self, value: float) -> None:
"""Value for pixels below threshold."""
def Execute(self, image):
"""
Compute Otsu threshold and apply binary thresholding.
Returns:
Binary thresholded image
"""
def GetThreshold(self) -> float:
"""Get computed threshold value (call after Execute)."""
def OtsuThreshold(image, insideValue: int = 1, outsideValue: int = 0,
numberOfHistogramBins: int = 128):
"""Procedural: Otsu threshold."""
class OtsuMultipleThresholdsImageFilter:
"""Multi-level Otsu thresholding."""
def SetNumberOfThresholds(self, n: int) -> None:
"""Set number of thresholds (creates n+1 classes)."""
def SetNumberOfHistogramBins(self, bins: int) -> None:
"""Set histogram bins."""
def Execute(self, image):
"""Returns: labeled image with n+1 classes"""
def GetThresholds(self) -> tuple[float, ...]:
"""Get computed thresholds."""
class HuangThresholdImageFilter:
"""Huang's fuzzy thresholding method."""
def Execute(self, image):
"""Returns: binary thresholded image"""
def GetThreshold(self) -> float:
"""Get computed threshold."""
class IntermodesThresholdImageFilter:
"""Intermode threshold (assumes bimodal histogram)."""
def Execute(self, image):
"""Returns: binary thresholded image"""
def GetThreshold(self) -> float:
"""Get computed threshold."""
class IsoDataThresholdImageFilter:
"""IsoData iterative threshold."""
def Execute(self, image):
"""Returns: binary thresholded image"""
def GetThreshold(self) -> float:
"""Get computed threshold."""
class KittlerIllingworthThresholdImageFilter:
"""Kittler-Illingworth minimum error threshold."""
def Execute(self, image):
"""Returns: binary thresholded image"""
def GetThreshold(self) -> float:
"""Get computed threshold."""
class LiThresholdImageFilter:
"""Li's iterative minimum cross entropy threshold."""
def Execute(self, image):
"""Returns: binary thresholded image"""
def GetThreshold(self) -> float:
"""Get computed threshold."""
class MaximumEntropyThresholdImageFilter:
"""Maximum entropy threshold."""
def Execute(self, image):
"""Returns: binary thresholded image"""
def GetThreshold(self) -> float:
"""Get computed threshold."""
class MomentsThresholdImageFilter:
"""Moments-based threshold (preserves moments of histogram)."""
def Execute(self, image):
"""Returns: binary thresholded image"""
def GetThreshold(self) -> float:
"""Get computed threshold."""
class RenyiEntropyThresholdImageFilter:
"""Renyi entropy threshold."""
def Execute(self, image):
"""Returns: binary thresholded image"""
def GetThreshold(self) -> float:
"""Get computed threshold."""
class ShanbhagThresholdImageFilter:
"""Shanbhag fuzzy entropy threshold."""
def Execute(self, image):
"""Returns: binary thresholded image"""
def GetThreshold(self) -> float:
"""Get computed threshold."""
class TriangleThresholdImageFilter:
"""Triangle threshold (good for skewed histograms)."""
def Execute(self, image):
"""Returns: binary thresholded image"""
def GetThreshold(self) -> float:
"""Get computed threshold."""
class YenThresholdImageFilter:
"""Yen's maximum correlation threshold."""
def Execute(self, image):
"""Returns: binary thresholded image"""
def GetThreshold(self) -> float:
"""Get computed threshold."""Compute statistical measures from images.
class StatisticsImageFilter:
"""Compute comprehensive image statistics."""
def Execute(self, image):
"""Compute statistics."""
def GetMean(self) -> float:
"""Get mean intensity."""
def GetSigma(self) -> float:
"""Get standard deviation."""
def GetVariance(self) -> float:
"""Get variance."""
def GetMinimum(self) -> float:
"""Get minimum pixel value."""
def GetMaximum(self) -> float:
"""Get maximum pixel value."""
def GetSum(self) -> float:
"""Get sum of all pixels."""
def Statistics(image):
"""Procedural: compute statistics (returns filter for access to stats)."""
class MinimumMaximumImageFilter:
"""Find minimum and maximum pixel values."""
def Execute(self, image):
"""Compute min and max."""
def GetMinimum(self) -> float:
"""Get minimum value."""
def GetMaximum(self) -> float:
"""Get maximum value."""
def MinimumMaximum(image) -> tuple[float, float]:
"""
Procedural: get (minimum, maximum) tuple.
Returns:
Tuple of (min, max) values
"""
class LabelStatisticsImageFilter:
"""Compute statistics per label in labeled image."""
def Execute(self, image, labelImage):
"""
Compute statistics for each label.
Args:
image: Intensity image
labelImage: Label image
"""
def GetNumberOfLabels(self) -> int:
"""Get number of unique labels."""
def GetLabels(self) -> tuple[int, ...]:
"""Get all label values."""
def GetMean(self, label: int) -> float:
"""Get mean for specific label."""
def GetSigma(self, label: int) -> float:
"""Get standard deviation for label."""
def GetMinimum(self, label: int) -> float:
"""Get minimum for label."""
def GetMaximum(self, label: int) -> float:
"""Get maximum for label."""
def GetCount(self, label: int) -> int:
"""Get pixel count for label."""
def GetSum(self, label: int) -> float:
"""Get sum for label."""
def GetBoundingBox(self, label: int) -> tuple[int, ...]:
"""Get bounding box for label."""Apply masks to images.
class MaskImageFilter:
"""Apply binary mask to image."""
def SetMaskingValue(self, value: float) -> None:
"""Set value in mask that indicates pixels to keep."""
def SetOutsideValue(self, value: float) -> None:
"""Set value for masked-out pixels."""
def Execute(self, image, maskImage):
"""
Apply mask: keep pixels where mask==maskingValue, else set to outsideValue.
Args:
image: Input image
maskImage: Binary mask
Returns:
Masked image
"""
def Mask(image, maskImage, outsideValue: float = 0, maskingValue: float = 1):
"""Procedural: apply mask."""
class MaskNegatedImageFilter:
"""Apply negated mask (keep where mask==0)."""
def Execute(self, image, maskImage):
"""Returns: masked image (inverted mask logic)"""
def MaskNegated(image, maskImage, outsideValue: float = 0):
"""Procedural: apply negated mask."""Convert between pixel types.
class CastImageFilter:
"""Cast image to different pixel type."""
def SetOutputPixelType(self, pixelType: int) -> None:
"""Set output pixel type."""
def Execute(self, image):
"""Returns: image with new pixel type"""
def Cast(image, pixelType: int):
"""
Procedural: cast to pixel type.
Args:
image: Input image
pixelType: Target pixel type (sitkFloat32, sitkUInt8, etc.)
Returns:
Casted image
"""import SimpleITK as sitk
# Read image
image = sitk.ReadImage('ct_scan.nii.gz')
# Clip outliers
image = sitk.Clamp(image, lowerBound=-1000, upperBound=2000)
# Rescale to [0, 1]
image = sitk.RescaleIntensity(image, outputMinimum=0, outputMaximum=1)
# Cast to float
image = sitk.Cast(image, sitk.sitkFloat32)import SimpleITK as sitk
image = sitk.ReadImage('cells.tif')
# Try different automatic methods
otsu = sitk.OtsuThreshold(image)
li = sitk.LiThreshold(image)
triangle = sitk.TriangleThreshold(image)
# Get threshold values
otsu_filter = sitk.OtsuThresholdImageFilter()
otsu_filter.Execute(image)
print(f"Otsu threshold: {otsu_filter.GetThreshold()}")import SimpleITK as sitk
image = sitk.ReadImage('data.nii')
# Compute statistics
stats = sitk.StatisticsImageFilter()
stats.Execute(image)
mean = stats.GetMean()
std = stats.GetSigma()
# Normalize based on statistics
normalized = sitk.ShiftScale(image, shift=-mean, scale=1.0/std)Install with Tessl CLI
npx tessl i tessl/pypi-simpleitk