or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

data-structures.mdfiltering.mdfinite-difference.mdgpu-computing.mdimage-adaptors.mdimage-functions.mdindex.mdio.mdmesh.mdnumpy-integration.mdregistration.mdsegmentation.mdspatial-objects.mdtransforms.md
tile.json

tessl/pypi-itk

The Insight Toolkit (ITK) - a comprehensive open-source library for N-dimensional scientific image processing, segmentation, and registration with extensive filtering algorithms, medical imaging I/O, and Python integration.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/itk@5.4.x

To install, run

npx @tessl/cli install tessl/pypi-itk@5.4.0

index.mddocs/

ITK - The Insight Toolkit

A comprehensive open-source toolkit for N-dimensional scientific image processing, segmentation, and registration. ITK provides hundreds of algorithms and data structures for medical image analysis, computer vision, and scientific computing applications, with extensive Python bindings, cross-platform compatibility, and high-performance implementations optimized for research and clinical workflows.

Package Information

  • Package Name: itk
  • Package Type: PyPI
  • Language: C++ with Python bindings
  • Installation: pip install itk

Core Imports

import itk

For specific components:

# Core data structures
from itk import Image, Point, Vector, Matrix

# I/O operations
from itk import imread, imwrite, ImageFileReader, ImageFileWriter

# Filtering operations (functional interface)
from itk import median_image_filter, gaussian_blur_image_filter
from itk import binary_threshold_image_filter, otsu_threshold_image_filter

# Registration and transforms
from itk import AffineTransform, registration_method_v4
from itk import mutual_information_image_to_image_metric_v4

# Segmentation
from itk import watershed_image_filter, connected_threshold_image_filter

# Mesh processing
from itk import Mesh, QuadEdgeMesh, PointSet

# NumPy integration
from itk import array_from_image, image_from_array

Basic Usage

import itk
import numpy as np

# Read and write images (most common operations)
image = itk.imread('input.png')
itk.imwrite(image, 'output.png')

# Convert between ITK and NumPy (seamless integration)
array = itk.array_from_image(image)
new_image = itk.image_from_array(array)

# Image filtering (modern functional interface)
# Smooth an image with median filter
smoothed = itk.median_image_filter(image, radius=2)

# Threshold an image
binary = itk.binary_threshold_image_filter(
    image, lower_threshold=100, upper_threshold=255
)

# Advanced filtering with automatic parameter deduction
blurred = itk.gaussian_blur_image_filter(image, variance=2.0)

# Registration example
fixed_image = itk.imread('fixed.png')
moving_image = itk.imread('moving.png')

# Simple registration using functional interface
result = itk.registration_method_v4(
    fixed_image=fixed_image,
    moving_image=moving_image,
    metric='mutual_information',
    transform='affine'
)

# Segmentation example
segments = itk.watershed_image_filter(image, threshold=0.01, level=0.3)

# Traditional object-oriented interface (still available)
image_type = itk.Image[itk.F, 3]
image = image_type.New()
size = itk.Size[3]([100, 100, 50])
region = itk.ImageRegion[3]()
region.SetSize(size)
image.SetRegions(region)
image.Allocate()

Architecture

ITK follows a modular, template-heavy C++ design exposed through comprehensive Python bindings:

  • Modular Design: ITK is organized into specialized modules (Core, Filtering, IO, Registration, Segmentation, Numerics)
  • Template System: Extensive templates for pixel types and dimensions, with automatic instantiation for Python
  • Dual Interface: Modern functional snake_case API (itk.median_image_filter()) alongside traditional object-oriented interface
  • Pipeline Architecture: Filters and data objects form efficient processing pipelines with lazy evaluation
  • Smart Pointers: Reference-counted smart pointers provide automatic memory management
  • Multi-dimensional Support: Native N-dimensional data structures and algorithms (1D to 6D+)
  • Cross-platform: Runs on Windows, macOS, Linux with extensive CI/CD testing

ITK's architecture enables both high-performance C++ execution and Pythonic ease of use, making it suitable for research prototyping and production medical imaging applications.

Capabilities

Core Data Structures

Fundamental N-dimensional containers for images, geometric primitives, matrices, and arrays that form the backbone of all ITK operations.

# Image containers
class Image[PixelType, Dimension]:
    def SetPixel(self, index: Index[Dimension], pixel: PixelType) -> None: ...
    def GetPixel(self, index: Index[Dimension]) -> PixelType: ...
    def GetRegion(self) -> ImageRegion[Dimension]: ...
    def SetSpacing(self, spacing: SpacingType) -> None: ...
    def GetSpacing(self) -> SpacingType: ...

# Geometric primitives
class Point[CoordType, Dimension]:
    def GetElement(self, i: int) -> CoordType: ...
    def SetElement(self, i: int, value: CoordType) -> None: ...
    def EuclideanDistanceTo(self, other: Point[CoordType, Dimension]) -> CoordType: ...

class Vector[CoordType, Dimension]:
    def GetNorm(self) -> CoordType: ...
    def Normalize(self) -> Vector[CoordType, Dimension]: ...
    def GetElement(self, i: int) -> CoordType: ...

# Matrix operations
class Matrix[T, NRows, NColumns]:
    def GetElement(self, row: int, col: int) -> T: ...
    def SetElement(self, row: int, col: int, value: T) -> None: ...
    def GetInverse(self) -> Matrix[T, NRows, NColumns]: ...

Core Data Structures

Geometric Transforms

Comprehensive framework for spatial transformations including rigid, affine, and non-linear deformations used in image registration and resampling.

class Transform[ScalarType, InputDimension, OutputDimension]:
    def TransformPoint(self, point: Point[ScalarType, InputDimension]) -> Point[ScalarType, OutputDimension]: ...
    def TransformVector(self, vector: Vector[ScalarType, InputDimension]) -> Vector[ScalarType, OutputDimension]: ...
    def GetParameters(self) -> ParametersType: ...
    def SetParameters(self, parameters: ParametersType) -> None: ...

class AffineTransform[T, NDimensions]:
    def GetMatrix(self) -> Matrix[T, NDimensions, NDimensions]: ...
    def SetMatrix(self, matrix: Matrix[T, NDimensions, NDimensions]) -> None: ...
    def GetOffset(self) -> Vector[T, NDimensions]: ...
    def SetOffset(self, offset: Vector[T, NDimensions]) -> None: ...

Geometric Transforms

Mesh Processing

3D mesh data structures including traditional and half-edge representations for surface modeling and analysis.

class Mesh[PixelType, Dimension, MeshTraits]:
    def SetPoint(self, id: PointIdentifier, point: Point[CoordType, Dimension]) -> None: ...
    def GetPoint(self, id: PointIdentifier) -> Point[CoordType, Dimension]: ...
    def SetCell(self, id: CellIdentifier, cell: CellAutoPointer) -> None: ...
    def GetCell(self, id: CellIdentifier) -> CellType: ...
    def GetNumberOfPoints(self) -> PointsContainer.ElementIdentifier: ...

class QuadEdgeMesh[PixelType, Dimension, Traits]:
    def AddFace(self, points: list[PointIdentifier]) -> QEType: ...
    def DeleteFace(self, face: QEType) -> None: ...
    def FindEdge(self, point1: PointIdentifier, point2: PointIdentifier) -> QEType: ...

Mesh Processing

Image Functions

Interpolation, analysis, and processing functions that operate on image data including various interpolation schemes and neighborhood operations.

class InterpolateImageFunction[InputImageType, CoordRep]:
    def Evaluate(self, point: Point[CoordRep, ImageDimension]) -> OutputType: ...
    def EvaluateAtIndex(self, index: Index[ImageDimension]) -> OutputType: ...
    def EvaluateAtContinuousIndex(self, index: ContinuousIndex[CoordRep, ImageDimension]) -> OutputType: ...

class LinearInterpolateImageFunction[InputImageType, CoordRep]:
    def SetInputImage(self, image: InputImageType) -> None: ...

class BSplineInterpolateImageFunction[InputImageType, CoordRep, CoefficientType]:
    def SetSplineOrder(self, order: int) -> None: ...
    def GetSplineOrder(self) -> int: ...

Image Functions

Image Adaptors

View adaptors that provide different pixel interpretations and mathematical transformations of existing images without copying data.

class ImageAdaptor[TImage, TAccessor]:
    def SetPixelAccessor(self, accessor: TAccessor) -> None: ...
    def GetPixelAccessor(self) -> TAccessor: ...

class RGBToLuminanceImageAdaptor[TImage]:
    def SetImage(self, image: TImage) -> None: ...

class NthElementImageAdaptor[TImage, TOutputPixelType]:
    def SelectNthElement(self, nth: int) -> None: ...

Image Adaptors

Finite Difference Framework

PDE-based image processing framework for level set methods, segmentation, and deformable models.

class FiniteDifferenceImageFilter[TInputImage, TOutputImage]:
    def SetNumberOfIterations(self, iterations: int) -> None: ...
    def SetTimeStep(self, time_step: float) -> None: ...
    def GetElapsedIterations(self) -> int: ...

class LevelSetFunction[TImageType]:
    def ComputeSpeedImage(self) -> None: ...
    def ComputeAdvectionImage(self) -> None: ...
    def SetAdvectionWeight(self, weight: ScalarValueType) -> None: ...

Finite Difference Framework

GPU Computing

GPU-accelerated computing support using OpenCL for high-performance image processing operations.

class GPUImage[TPixel, VImageDimension]:
    def GetGPUDataManager(self) -> GPUDataManager: ...
    def UpdateGPUBuffer(self) -> None: ...
    def UpdateCPUBuffer(self) -> None: ...

class GPUImageDataManager[ImageType]:
    def SetCPUBufferPointer(self, ptr: PixelType) -> None: ...
    def SetGPUDirtyFlag(self, isDirty: bool) -> None: ...

GPU Computing

Spatial Objects

Geometric object representations for modeling anatomical structures and regions of interest.

class SpatialObject[TDimension]:
    def IsInside(self, point: Point[ScalarType, TDimension]) -> bool: ...
    def ComputeLocalBoundingBox(self) -> BoundingBoxType: ...
    def SetObjectToParentTransform(self, transform: TransformType) -> None: ...

class EllipseSpatialObject[TDimension]:
    def SetRadius(self, radius: ArrayType) -> None: ...
    def GetRadius(self) -> ArrayType: ...

Spatial Objects

NumPy Integration

Seamless integration utilities for converting between ITK images and NumPy arrays, enabling interoperability with the Python scientific computing ecosystem.

def array_from_image(image: Image) -> numpy.ndarray: ...
def image_from_array(array: numpy.ndarray, is_vector: bool = False) -> Image: ...
def array_view_from_image(image: Image) -> numpy.ndarray: ...
def image_view_from_array(array: numpy.ndarray, is_vector: bool = False) -> Image: ...

# Type instantiation helpers
def template(template_class): ...
def auto_pipeline(*args, **kwargs): ...
def size(sequence) -> Size: ...
def index(sequence) -> Index: ...

NumPy Integration

Image Filtering

Extensive collection of image processing algorithms including smoothing, enhancement, morphological operations, and feature detection with both traditional and modern functional interfaces.

# Modern functional interface (preferred)
def median_image_filter(input_image, radius: int | Sequence[int]) -> Image: ...
def gaussian_blur_image_filter(input_image, variance: float | Sequence[float]) -> Image: ...
def binary_threshold_image_filter(input_image, lower_threshold, upper_threshold, inside_value=255, outside_value=0) -> Image: ...
def otsu_threshold_image_filter(input_image, inside_value=255, outside_value=0) -> Image: ...
def watershed_image_filter(input_image, threshold: float, level: float) -> Image: ...
def gradient_magnitude_image_filter(input_image) -> Image: ...
def binary_dilate_image_filter(input_image, kernel_radius: int | Sequence[int]) -> Image: ...
def binary_erode_image_filter(input_image, kernel_radius: int | Sequence[int]) -> Image: ...

# Traditional object-oriented interface
class MedianImageFilter[InputImageType, OutputImageType]:
    def SetRadius(self, radius: int | Sequence[int]) -> None: ...
    def GetRadius(self) -> Sequence[int]: ...

Image Filtering

Registration Framework

Comprehensive image registration system supporting multiple transform types, similarity metrics, and optimization methods for medical image alignment.

# Modern registration interface
def registration_method_v4(fixed_image, moving_image, metric: str = 'mutual_information', 
                          transform: str = 'affine', optimizer: str = 'gradient_descent') -> dict: ...

# Registration components
class ImageRegistrationMethodv4[TFixedImage, TMovingImage]:
    def SetFixedImage(self, image: TFixedImage) -> None: ...
    def SetMovingImage(self, image: TMovingImage) -> None: ...
    def SetMetric(self, metric: MetricType) -> None: ...
    def SetOptimizer(self, optimizer: OptimizerType) -> None: ...
    def SetTransform(self, transform: TransformType) -> None: ...

class MutualInformationImageToImageMetricv4[TFixedImage, TMovingImage]:
    def SetNumberOfHistogramBins(self, bins: int) -> None: ...
    def GetValue(self) -> float: ...

class GradientDescentOptimizerv4:
    def SetLearningRate(self, rate: float) -> None: ...
    def SetNumberOfIterations(self, iterations: int) -> None: ...

Registration Framework

Segmentation Algorithms

Advanced segmentation methods including level sets, region growing, clustering, and watershed algorithms for extracting anatomical structures.

# Functional segmentation interface
def connected_threshold_image_filter(input_image, seed_points: Sequence, lower: float, upper: float) -> Image: ...
def confidence_connected_image_filter(input_image, seed_points: Sequence, multiplier: float = 2.5) -> Image: ...
def watershed_image_filter(input_image, threshold: float, level: float) -> Image: ...
def geodesic_active_contour_level_set_image_filter(input_image, feature_image, seeds) -> Image: ...

# Level set segmentation
class GeodesicActiveContourLevelSetImageFilter[TInputImage, TFeatureImage, TOutputImage]:
    def SetFeatureImage(self, image: TFeatureImage) -> None: ...
    def SetAdvectionScaling(self, scaling: float) -> None: ...
    def SetCurvatureScaling(self, scaling: float) -> None: ...
    def SetPropagationScaling(self, scaling: float) -> None: ...

# Region growing
class ConnectedThresholdImageFilter[TInputImage, TOutputImage]:
    def SetSeed(self, seed: Index) -> None: ...
    def AddSeed(self, seed: Index) -> None: ...
    def SetLower(self, threshold: PixelType) -> None: ...
    def SetUpper(self, threshold: PixelType) -> None: ...

Segmentation

Comprehensive I/O Support

Extensive file format support for medical imaging, computer vision, and scientific data with automatic format detection and metadata preservation.

# High-level I/O functions
def imread(filename: str, pixel_type=None, fallback_only: bool = False) -> Image: ...
def imwrite(image: Image, filename: str, compression: bool = False, use_streaming: bool = False) -> None: ...
def meshread(filename: str) -> Mesh: ...
def meshwrite(mesh: Mesh, filename: str) -> None: ...
def transformread(filename: str) -> Transform: ...
def transformwrite(transform: Transform, filename: str) -> None: ...

# Format-specific readers/writers
class ImageFileReader[TOutputImage]:
    def SetFileName(self, filename: str) -> None: ...
    def GetFileName(self) -> str: ...
    def Update(self) -> None: ...
    def GetOutput(self) -> TOutputImage: ...

class ImageFileWriter[TInputImage]:
    def SetFileName(self, filename: str) -> None: ...
    def SetInput(self, image: TInputImage) -> None: ...
    def SetUseCompression(self, compression: bool) -> None: ...
    def Write(self) -> None: ...

# DICOM support
class GDCMImageIO:
    def SetLoadSequences(self, load: bool) -> None: ...
    def SetLoadPrivateTags(self, load: bool) -> None: ...
    def GetPatientName(self) -> str: ...
    def GetStudyDescription(self) -> str: ...

I/O Operations

Types

# Common type abbreviations
F = float    # 32-bit float
D = float    # 64-bit double
UC = int     # unsigned char
US = int     # unsigned short
UI = int     # unsigned int
UL = int     # unsigned long
SC = int     # signed char
SS = int     # signed short
SI = int     # signed int
SL = int     # signed long

# Template instantiation types
class Index[Dimension]: ...
class Size[Dimension]: ...
class ImageRegion[Dimension]: ...
class SpacingType: ...
class OriginType: ...
class DirectionType: ...
class ParametersType: ...
class PointIdentifier: ...
class CellIdentifier: ...