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

constants-enums.mddocs/reference/

Constants and Enumerations Reference

Complete reference for all SimpleITK constants, enumerations, and symbolic values.

Pixel Type Constants

Scalar Integer Types

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 integer

Scalar Floating Point Types

sitkFloat32 = 9   # 32-bit float (single precision)
sitkFloat64 = 10  # 64-bit float (double precision)

Complex Types

sitkComplexFloat32 = 11  # Complex 32-bit float
sitkComplexFloat64 = 12  # Complex 64-bit float

Vector Types

sitkVectorUInt8 = 13
sitkVectorInt8 = 14
sitkVectorUInt16 = 15
sitkVectorInt16 = 16
sitkVectorUInt32 = 17
sitkVectorInt32 = 18
sitkVectorUInt64 = 19
sitkVectorInt64 = 20
sitkVectorFloat32 = 21
sitkVectorFloat64 = 22

Label Types

sitkLabelUInt8 = 23   # Label type, 8-bit
sitkLabelUInt16 = 24  # Label type, 16-bit
sitkLabelUInt32 = 25  # Label type, 32-bit
sitkLabelUInt64 = 26  # Label type, 64-bit

Unknown Type

sitkUnknown = -1  # Unknown or unspecified type

Interpolator Constants

sitkNearestNeighbor = 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 Selection Guide

InterpolatorSpeedQualityUse Case
NearestNeighborFastestBlockyLabel images, binary masks
LinearFastGoodGeneral purpose
BSplineMediumExcellentHigh-quality resampling
GaussianSlowSmoothAnti-aliasing
LabelGaussianMediumGoodLabel images with smoothing
Windowed SincSlowestBestPublication-quality

Kernel Type Constants (Structuring Elements)

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 polygon

Kernel Shape Visualization

Ball (sitkBall):        Box (sitkBox):         Cross (sitkCross):
    ●●●                     █████                   █
  ●●●●●                     █████                  ███
  ●●●●●                     █████                 █████
  ●●●●●                     █████                  ███
    ●●●                     █████                   █

Event Type Constants

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 change

Event Usage

def 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)

Transform Type Constants

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 Selection Guide

TransformDOFPreservesUse Case
Translation2-3Shape, size, anglesSimple alignment
Euler6Shape, sizeRigid registration
Similarity7Shape, anglesWith scale difference
Affine12Parallel linesGeneral linear
BSplineManyTopologyDeformable registration
DisplacementField3×pixelsTopologyDense deformation

Metric Sampling Strategy Constants

# Available as ImageRegistrationMethod attributes
registration.NONE     # Use all pixels
registration.REGULAR  # Regular grid sampling
registration.RANDOM   # Random sampling

Optimizer Scale Estimation Methods

# Available as ImageRegistrationMethod methods
registration.SetOptimizerScalesFromPhysicalShift()
registration.SetOptimizerScalesFromIndexShift()
registration.SetOptimizerScalesFromJacobian()

Boundary Condition Constants

# 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

Distance Map Constants

# Sign conventions for distance maps
insideIsPositive = True   # Positive inside object
insideIsPositive = False  # Negative inside object (default)

File Format Constants

Supported ImageIO Types

# 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

Noise Model Constants

# For PatchBasedDenoisingImageFilter
sitkNoModel = 0
sitkGaussian = 1
sitkRician = 2
sitkPoisson = 3

Optimizer Constants

Gradient Descent Learning Rate Estimation

# SetOptimizerAsGradientDescent estimateLearningRate parameter
sitkNever = 0           # Never estimate
sitkOnce = 1            # Estimate once at start
sitkEachIteration = 2   # Estimate every iteration

Constant Usage Patterns

Type Checking

def 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"

Interpolator Selection

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.sitkLinear

Kernel Selection

def 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

Constant Groups

Registration-Related

# 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

Morphology-Related

# Kernel types for morphological operations
sitkBall   # Most common, isotropic
sitkBox    # Rectangular, faster
sitkCross  # Minimal connectivity

I/O-Related

# 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 compression

Usage Examples

Type Constants

import 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)

Interpolator Constants

# 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)

Kernel Constants

# 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
)

Event Constants

# 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)

Constant Lookup Functions

Get Constant Name

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})')

Constant Validation

Validate Constant Values

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 True

See Also

  • Type System Reference - Complete type documentation
  • Architecture Reference - System architecture
  • Filter API Reference - Filter-specific constants

Install with Tessl CLI

npx tessl i tessl/pypi-simpleitk

docs

index.md

tile.json