Simplified interface to the Insight Toolkit for medical image analysis and processing.
npx @tessl/cli install tessl/pypi-simpleitk@2.5.0SimpleITK is a comprehensive image analysis toolkit that provides a simplified interface to the powerful Insight Segmentation and Registration Toolkit (ITK). This Python library offers extensive functionality for medical and scientific image processing, including filtering operations, image segmentation, and registration algorithms.
pip install SimpleITKimport SimpleITK as sitkCommon for working with NumPy arrays:
import SimpleITK as sitk
import numpy as npimport SimpleITK as sitk
# Read an image
image = sitk.ReadImage('input.nii.gz')
# Apply Gaussian smoothing
smoothed = sitk.SmoothingRecursiveGaussian(image, sigma=2.0)
# Write the result
sitk.WriteImage(smoothed, 'output.nii.gz')
# NumPy integration
array = sitk.GetArrayFromImage(image)
processed_array = array * 2 # Simple processing
result_image = sitk.GetImageFromArray(processed_array)
result_image.CopyInformation(image) # Copy spacing, origin, directionSimpleITK provides both procedural and object-oriented interfaces:
The toolkit supports 2D, 3D, and 4D images with various pixel types and provides language bindings for Python, R, Java, C#, Lua, TCL, and Ruby.
Basic image I/O, NumPy integration, and fundamental image manipulations including creation, copying, and format conversion.
def ReadImage(fileName, outputPixelType=sitkUnknown, imageIO=""): ...
def WriteImage(image, fileName, useCompression=False, compressionLevel=-1): ...
def GetArrayFromImage(image): ...
def GetImageFromArray(arr, isVector=None): ...
def GetArrayViewFromImage(image): ...Comprehensive filtering operations including smoothing, edge detection, noise reduction, mathematical operations, and morphological processing.
def SmoothingRecursiveGaussian(image, sigma=[1]*3, normalizeAcrossScale=False): ...
def DiscreteGaussian(image, variance=[1]*3, maximumKernelWidth=32): ...
def BinaryThreshold(image, lowerThreshold=0, upperThreshold=255): ...
def CannyEdgeDetection(image, lowerThreshold=0, upperThreshold=0): ...Advanced segmentation algorithms including threshold-based, region growing, watershed, and level set methods for extracting regions of interest.
def ConnectedThreshold(image, seedList, lower=0, upper=255): ...
def RegionGrowing(image, seedList, multiplier=2.5, numberOfIterations=5): ...
def Watershed(image, level=0, markWatershedLine=True): ...
def FastMarchingImageFilter(): ...Image registration algorithms and geometric transformations for aligning images and correcting spatial distortions.
def Resample(image, referenceImage=None, transform=Transform()): ...
class ImageRegistrationMethod: ...
class Transform: ...
class AffineTransform: ...
class BSplineTransform: ...Mathematical morphology operations including erosion, dilation, opening, closing, and distance transforms for shape analysis.
def BinaryErode(image, kernelRadius=[1]*3, kernelType=sitkBall): ...
def BinaryDilate(image, kernelRadius=[1]*3, kernelType=sitkBall): ...
def BinaryOpening(image, kernelRadius=[1]*3, kernelType=sitkBall): ...
def BinaryClosing(image, kernelRadius=[1]*3, kernelType=sitkBall): ...Advanced feature detection algorithms including corner detection, blob detection, and texture analysis for image analysis.
def LaplacianRecursiveGaussian(image, sigma=1.0): ...
def HessianRecursiveGaussian(image, sigma=1.0): ...
def LaplacianImageFilter(): ...
def HoughTransform(): ...class Image:
def __init__(size, pixelType, numberOfComponents=1): ...
def GetSize(): ...
def GetOrigin(): ...
def GetSpacing(): ...
def GetDirection(): ...
def GetPixelIDValue(): ...
def CopyInformation(sourceImage): ...
class Transform:
def __init__(): ...
def SetParameters(parameters): ...
def GetParameters(): ...
class ImageFileReader:
def SetFileName(fileName): ...
def Execute(): ...
class ImageFileWriter:
def SetFileName(fileName): ...
def Execute(image): ...