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
Complete reference for all SimpleITK constants, enumerations, and symbolic values.
sitkUInt8 = 1 # Unsigned 8-bit integer (0-255)
sitkInt8 = 2 # Signed 8-bit integer (-128 to 127)
sitkUInt16 = 3 # Unsigned 16-bit integer (0-65535)
sitkInt16 = 4 # Signed 16-bit integer (-32768 to 32767)
sitkUInt32 = 5 # Unsigned 32-bit integer
sitkInt32 = 6 # Signed 32-bit integer
sitkUInt64 = 7 # Unsigned 64-bit integer
sitkInt64 = 8 # Signed 64-bit integersitkFloat32 = 9 # 32-bit float (single precision)
sitkFloat64 = 10 # 64-bit float (double precision)sitkComplexFloat32 = 11 # Complex 32-bit float
sitkComplexFloat64 = 12 # Complex 64-bit floatsitkVectorUInt8 = 13
sitkVectorInt8 = 14
sitkVectorUInt16 = 15
sitkVectorInt16 = 16
sitkVectorUInt32 = 17
sitkVectorInt32 = 18
sitkVectorUInt64 = 19
sitkVectorInt64 = 20
sitkVectorFloat32 = 21
sitkVectorFloat64 = 22sitkLabelUInt8 = 23 # Label type, 8-bit
sitkLabelUInt16 = 24 # Label type, 16-bit
sitkLabelUInt32 = 25 # Label type, 32-bit
sitkLabelUInt64 = 26 # Label type, 64-bitsitkUnknown = -1 # Unknown or unspecified typesitkNearestNeighbor = 1 # Nearest neighbor (no interpolation)
sitkLinear = 2 # Linear interpolation
sitkBSpline = 23 # Cubic B-spline (alias for sitkBSpline3)
sitkGaussian = 4 # Gaussian interpolation
sitkLabelGaussian = 5 # Gaussian for label images
sitkHammingWindowedSinc = 6 # Hamming windowed sinc
sitkCosineWindowedSinc = 7 # Cosine windowed sinc
sitkWelchWindowedSinc = 8 # Welch windowed sinc
sitkLanczosWindowedSinc = 9 # Lanczos windowed sinc
sitkBlackmanWindowedSinc = 10 # Blackman windowed sinc
sitkBSpline1 = 21 # Linear B-spline
sitkBSpline2 = 22 # Quadratic B-spline
sitkBSpline3 = 23 # Cubic B-spline
sitkBSpline4 = 24 # Quartic B-spline
sitkBSpline5 = 25 # Quintic B-spline
sitkLabelLinear = 26 # Linear for label images| Interpolator | Speed | Quality | Use Case |
|---|---|---|---|
| NearestNeighbor | Fastest | Blocky | Label images, binary masks |
| Linear | Fast | Good | General purpose |
| BSpline | Medium | Excellent | High-quality resampling |
| Gaussian | Slow | Smooth | Anti-aliasing |
| LabelGaussian | Medium | Good | Label images with smoothing |
| Windowed Sinc | Slowest | Best | Publication-quality |
sitkAnnulus = 0 # Ring/annulus shape
sitkBall = 1 # Ball/sphere (circular in 2D, spherical in 3D)
sitkBox = 2 # Box/rectangle (square in 2D, cubic in 3D)
sitkCross = 3 # Cross/plus shape
sitkPolygon3 = 4 # 3-sided polygon
sitkPolygon4 = 5 # 4-sided polygon (square)
sitkPolygon5 = 6 # 5-sided polygon (pentagon)
sitkPolygon6 = 7 # 6-sided polygon (hexagon)
sitkPolygon7 = 8 # 7-sided polygon
sitkPolygon8 = 9 # 8-sided polygon (octagon)
sitkPolygon9 = 10 # 9-sided polygonBall (sitkBall): Box (sitkBox): Cross (sitkCross):
●●● █████ █
●●●●● █████ ███
●●●●● █████ █████
●●●●● █████ ███
●●● █████ █sitkAnyEvent = 0 # Any event
sitkAbortEvent = 1 # Execution aborted
sitkDeleteEvent = 2 # Object deleted
sitkEndEvent = 3 # Execution completed
sitkIterationEvent = 4 # Iteration completed
sitkProgressEvent = 5 # Progress update
sitkStartEvent = 6 # Execution started
sitkUserEvent = 7 # User-defined event
sitkMultiResolutionIterationEvent = 8 # Multi-resolution level changedef setup_callbacks(filter):
"""Setup event callbacks for filter."""
def on_start():
print("Filter started")
def on_progress():
print(f"Progress: {filter.GetProgress()*100:.1f}%")
def on_iteration():
print(f"Iteration {filter.GetOptimizerIteration()}")
def on_end():
print("Filter completed")
filter.AddCommand(sitk.sitkStartEvent, on_start)
filter.AddCommand(sitk.sitkProgressEvent, on_progress)
filter.AddCommand(sitk.sitkIterationEvent, on_iteration)
filter.AddCommand(sitk.sitkEndEvent, on_end)sitkIdentity = 0 # Identity (no transformation)
sitkTranslation = 1 # Pure translation
sitkScale = 2 # Scaling
sitkScaleLogarithmic = 3 # Logarithmic scaling
sitkEuler = 4 # Euler angles (rigid)
sitkSimilarity = 5 # Similarity (rigid + uniform scale)
sitkQuaternionRigid = 6 # Quaternion rigid
sitkVersor = 7 # Versor (quaternion rotation)
sitkVersorRigid = 8 # Versor rigid (rotation + translation)
sitkScaleSkewVersor = 9 # Scale, skew, and versor
sitkComposeScaleSkewVersor = 10 # Composed scale-skew-versor
sitkScaleVersor = 11 # Scale and versor
sitkAffine = 12 # General affine
sitkComposite = 13 # Composite of transforms
sitkDisplacementField = 14 # Dense displacement field
sitkBSplineTransform = 15 # B-spline deformable| Transform | DOF | Preserves | Use Case |
|---|---|---|---|
| Translation | 2-3 | Shape, size, angles | Simple alignment |
| Euler | 6 | Shape, size | Rigid registration |
| Similarity | 7 | Shape, angles | With scale difference |
| Affine | 12 | Parallel lines | General linear |
| BSpline | Many | Topology | Deformable registration |
| DisplacementField | 3×pixels | Topology | Dense deformation |
# Available as ImageRegistrationMethod attributes
registration.NONE # Use all pixels
registration.REGULAR # Regular grid sampling
registration.RANDOM # Random sampling# Available as ImageRegistrationMethod methods
registration.SetOptimizerScalesFromPhysicalShift()
registration.SetOptimizerScalesFromIndexShift()
registration.SetOptimizerScalesFromJacobian()# For padding and boundary handling
sitkZeroFluxNeumann = 0 # Replicate edge values
sitkConstant = 1 # Use constant value
sitkPeriodic = 2 # Wrap around (periodic)
sitkMirror = 3 # Mirror at boundary# Sign conventions for distance maps
insideIsPositive = True # Positive inside object
insideIsPositive = False # Negative inside object (default)# Query available formats
ios = sitk.GetRegisteredImageIOs()
# Common ImageIO names:
# - 'GDCMImageIO' # DICOM
# - 'NiftiImageIO' # NIfTI
# - 'NrrdImageIO' # NRRD
# - 'MetaImageIO' # MetaImage
# - 'PNGImageIO' # PNG
# - 'JPEGImageIO' # JPEG
# - 'TIFFImageIO' # TIFF
# - 'BMPImageIO' # BMP
# - 'HDF5ImageIO' # HDF5
# - 'VTKImageIO' # VTK# For PatchBasedDenoisingImageFilter
sitkNoModel = 0
sitkGaussian = 1
sitkRician = 2
sitkPoisson = 3# SetOptimizerAsGradientDescent estimateLearningRate parameter
sitkNever = 0 # Never estimate
sitkOnce = 1 # Estimate once at start
sitkEachIteration = 2 # Estimate every iterationdef check_type_category(image):
"""Check which type category image belongs to."""
pixel_id = image.GetPixelIDValue()
# Integer types
integer_types = [
sitk.sitkUInt8, sitk.sitkInt8,
sitk.sitkUInt16, sitk.sitkInt16,
sitk.sitkUInt32, sitk.sitkInt32,
sitk.sitkUInt64, sitk.sitkInt64
]
# Float types
float_types = [sitk.sitkFloat32, sitk.sitkFloat64]
# Vector types
vector_types = [
sitk.sitkVectorUInt8, sitk.sitkVectorInt8,
sitk.sitkVectorUInt16, sitk.sitkVectorInt16,
sitk.sitkVectorFloat32, sitk.sitkVectorFloat64
]
# Label types
label_types = [
sitk.sitkLabelUInt8, sitk.sitkLabelUInt16,
sitk.sitkLabelUInt32, sitk.sitkLabelUInt64
]
if pixel_id in integer_types:
return "integer"
elif pixel_id in float_types:
return "float"
elif pixel_id in vector_types:
return "vector"
elif pixel_id in label_types:
return "label"
else:
return "unknown"def select_interpolator(image_type, quality='balanced'):
"""Select appropriate interpolator."""
pixel_id = image_type.GetPixelIDValue()
# Label images: Use nearest neighbor or label-specific
if pixel_id in [sitk.sitkLabelUInt8, sitk.sitkLabelUInt16,
sitk.sitkLabelUInt32, sitk.sitkLabelUInt64]:
return sitk.sitkNearestNeighbor
# Quality-based selection for scalar images
if quality == 'fast':
return sitk.sitkLinear
elif quality == 'balanced':
return sitk.sitkBSpline
elif quality == 'best':
return sitk.sitkLanczosWindowedSinc
return sitk.sitkLineardef select_kernel_type(operation, dimension):
"""Select appropriate kernel type for operation."""
# For isotropic operations: Ball
if operation in ['erosion', 'dilation', 'opening', 'closing']:
return sitk.sitkBall
# For directional operations: Cross
if operation in ['edge_detection']:
return sitk.sitkCross
# For rectangular regions: Box
if operation in ['local_statistics']:
return sitk.sitkBox
return sitk.sitkBall # Default# Metric sampling strategies
ImageRegistrationMethod.NONE # No sampling (all pixels)
ImageRegistrationMethod.REGULAR # Regular grid
ImageRegistrationMethod.RANDOM # Random sampling
# Transform initializer modes
CenteredTransformInitializerFilter.GEOMETRY # Use image geometry
CenteredTransformInitializerFilter.MOMENTS # Use image moments# Kernel types for morphological operations
sitkBall # Most common, isotropic
sitkBox # Rectangular, faster
sitkCross # Minimal connectivity# Compression levels
compressionLevel = -1 # Default
compressionLevel = 0 # No compression
compressionLevel = 9 # Maximum compression
# Common compressors
compressor = 'JPEG' # JPEG compression
compressor = 'LZW' # Lossless LZW
compressor = 'ZLib' # ZLib compressionimport SimpleITK as sitk
# Create image with specific type
image = sitk.Image(256, 256, sitk.sitkFloat32)
# Check type
if image.GetPixelIDValue() == sitk.sitkFloat32:
print("Image is Float32")
# Cast to different type
uint8_image = sitk.Cast(image, sitk.sitkUInt8)# Resample with specific interpolator
resampled = sitk.Resample(
image,
transform,
sitk.sitkLinear, # Interpolator constant
0.0,
image.GetPixelID()
)
# Set in registration
registration = sitk.ImageRegistrationMethod()
registration.SetInterpolator(sitk.sitkBSpline)# Binary erosion with ball kernel
eroded = sitk.BinaryErode(
binary_image,
kernelRadius=[3, 3, 3],
kernelType=sitk.sitkBall
)
# Grayscale dilation with box kernel
dilated = sitk.GrayscaleDilate(
image,
kernelRadius=[2, 2, 2],
kernelType=sitk.sitkBox
)# Add progress callback
def progress_callback():
print(f"Progress: {filter.GetProgress()*100:.1f}%")
filter = sitk.DiscreteGaussianImageFilter()
filter.AddCommand(sitk.sitkProgressEvent, progress_callback)
# Add iteration callback
def iteration_callback():
print(f"Iteration: {registration.GetOptimizerIteration()}")
registration = sitk.ImageRegistrationMethod()
registration.AddCommand(sitk.sitkIterationEvent, iteration_callback)def get_pixel_type_name(pixel_id):
"""Get human-readable name for pixel type constant."""
type_names = {
sitk.sitkUInt8: 'UInt8',
sitk.sitkInt8: 'Int8',
sitk.sitkUInt16: 'UInt16',
sitk.sitkInt16: 'Int16',
sitk.sitkUInt32: 'UInt32',
sitk.sitkInt32: 'Int32',
sitk.sitkFloat32: 'Float32',
sitk.sitkFloat64: 'Float64',
sitk.sitkVectorFloat32: 'VectorFloat32',
sitk.sitkLabelUInt8: 'LabelUInt8',
sitk.sitkLabelUInt16: 'LabelUInt16',
}
return type_names.get(pixel_id, f'Unknown({pixel_id})')
def get_interpolator_name(interp_id):
"""Get human-readable name for interpolator constant."""
interp_names = {
sitk.sitkNearestNeighbor: 'NearestNeighbor',
sitk.sitkLinear: 'Linear',
sitk.sitkBSpline: 'BSpline',
sitk.sitkGaussian: 'Gaussian',
}
return interp_names.get(interp_id, f'Unknown({interp_id})')def validate_pixel_type_constant(pixel_id):
"""Validate pixel type constant."""
valid_types = [
sitk.sitkUInt8, sitk.sitkInt8,
sitk.sitkUInt16, sitk.sitkInt16,
sitk.sitkUInt32, sitk.sitkInt32,
sitk.sitkUInt64, sitk.sitkInt64,
sitk.sitkFloat32, sitk.sitkFloat64,
sitk.sitkComplexFloat32, sitk.sitkComplexFloat64,
sitk.sitkVectorUInt8, sitk.sitkVectorInt8,
sitk.sitkVectorUInt16, sitk.sitkVectorInt16,
sitk.sitkVectorUInt32, sitk.sitkVectorInt32,
sitk.sitkVectorFloat32, sitk.sitkVectorFloat64,
sitk.sitkLabelUInt8, sitk.sitkLabelUInt16,
sitk.sitkLabelUInt32, sitk.sitkLabelUInt64
]
if pixel_id not in valid_types:
raise ValueError(f"Invalid pixel type constant: {pixel_id}")
return True
def validate_interpolator_constant(interp_id):
"""Validate interpolator constant."""
valid_interps = [
sitk.sitkNearestNeighbor, sitk.sitkLinear,
sitk.sitkBSpline, sitk.sitkGaussian,
sitk.sitkLabelGaussian, sitk.sitkLabelLinear,
sitk.sitkHammingWindowedSinc, sitk.sitkCosineWindowedSinc,
sitk.sitkWelchWindowedSinc, sitk.sitkLanczosWindowedSinc,
sitk.sitkBlackmanWindowedSinc
]
if interp_id not in valid_interps:
raise ValueError(f"Invalid interpolator constant: {interp_id}")
return TrueInstall with Tessl CLI
npx tessl i tessl/pypi-simpleitk