0
# SimpleITK
1
2
SimpleITK is a simplified interface to the Insight Toolkit (ITK) for image analysis tasks including filtering, segmentation, and registration. Built on top of ITK, it provides a streamlined API for general filtering operations, image segmentation, and registration while supporting 2D, 3D, and 4D spatio-temporal images with n-dimensional vector voxels.
3
4
## Package Information
5
6
- **Package Name**: SimpleITK
7
- **Package Type**: CMake/C++ library with multi-language bindings
8
- **Version**: 1.2.4
9
- **Language**: C++ with multi-language bindings
10
- **License**: Apache License 2.0
11
- **Repository**: https://github.com/SimpleITK/SimpleITK
12
- **Documentation**: http://simpleitk.readthedocs.io/
13
- **Installation**:
14
- Python: `pip install SimpleITK`
15
- R: `install.packages("SimpleITK")`
16
- Java: Available through Maven Central `org.itk.simple:simpleitk`
17
- C#: Available through NuGet `SimpleITK`
18
- Lua: Build from source with Lua bindings enabled
19
- TCL: Build from source with TCL bindings enabled
20
- Ruby: Build from source with Ruby bindings enabled
21
- **Supported Languages**: C++, Python, R, Java, C#, Lua, TCL, Ruby
22
- **Supported Platforms**: Windows, macOS, Linux
23
- **Dependencies**: ITK (Insight Toolkit), SWIG (for language bindings)
24
25
## Core Imports
26
27
Python:
28
```python
29
import SimpleITK as sitk
30
```
31
32
R:
33
```r
34
library(SimpleITK)
35
```
36
37
Java:
38
```java
39
import org.itk.simple.*;
40
```
41
42
C#:
43
```csharp
44
using itk.simple;
45
```
46
47
## Basic Usage
48
49
```python
50
import SimpleITK as sitk
51
52
# Read an image
53
image = sitk.ReadImage('input.dcm')
54
55
# Apply Gaussian smoothing
56
smoothed = sitk.SmoothingRecursiveGaussian(image, 2.0)
57
58
# Apply thresholding
59
binary = sitk.BinaryThreshold(smoothed, 100, 255, 255, 0)
60
61
# Write result
62
sitk.WriteImage(binary, 'output.png')
63
64
# Chain operations for complex processing
65
result = sitk.BinaryThreshold(
66
sitk.MedianFilter(
67
sitk.SmoothingRecursiveGaussian(image, 1.5),
68
3
69
),
70
50, 200
71
)
72
```
73
74
## Architecture
75
76
SimpleITK's design centers around these key components:
77
78
- **Image**: Core data structure representing 2D/3D/4D images with various pixel types
79
- **Filters**: 291+ image processing operations organized as both classes and procedural functions
80
- **Transforms**: Geometric transformation classes for image registration and spatial manipulation
81
- **I/O System**: Automatic format detection for reading/writing medical and scientific image formats
82
- **Registration Framework**: Complete toolkit for image alignment and correspondence
83
84
The library emphasizes ease of use while maintaining access to ITK's powerful capabilities, making medical and scientific image analysis accessible to domain experts without deep technical knowledge of image processing algorithms.
85
86
## Capabilities
87
88
### Image Operations
89
90
Core image data structure and fundamental operations including creation, pixel access, metadata handling, and format conversions. The Image class supports multiple pixel types and dimensions with comprehensive metadata preservation.
91
92
```python { .api }
93
# Image class core methods
94
class Image:
95
def __init__(self, *args): ...
96
def GetSize(self) -> tuple: ...
97
def GetOrigin(self) -> tuple: ...
98
def GetSpacing(self) -> tuple: ...
99
def GetDirection(self) -> tuple: ...
100
def GetPixelID(self) -> int: ...
101
def GetNumberOfComponentsPerPixel(self) -> int: ...
102
def SetPixel(self, idx, value): ...
103
def GetPixel(self, idx): ...
104
def CopyInformation(self, other_image): ...
105
106
# NumPy integration (Python-specific)
107
def GetArrayFromImage(image) -> numpy.ndarray: ...
108
def GetImageFromArray(array, isVector=False) -> Image: ...
109
```
110
111
[Image Operations](./image-operations.md)
112
113
### I/O Operations
114
115
Comprehensive input/output functionality for reading and writing images in various formats including DICOM, NIfTI, PNG, JPEG, TIFF, and many scientific formats. Supports both single images and image series with automatic format detection.
116
117
```python { .api }
118
# Procedural I/O functions
119
def ReadImage(filename: str, pixelType=None) -> Image: ...
120
def WriteImage(image: Image, filename: str, useCompression=False): ...
121
122
# Class-based I/O
123
class ImageFileReader:
124
def SetFileName(self, filename: str): ...
125
def Execute(self) -> Image: ...
126
def ReadImageInformation(self): ...
127
def GetSize(self) -> tuple: ...
128
129
class ImageFileWriter:
130
def SetFileName(self, filename: str): ...
131
def SetUseCompression(self, compress: bool): ...
132
def Execute(self, image: Image): ...
133
134
class ImageSeriesReader:
135
def SetFileNames(self, filenames: list): ...
136
def Execute(self) -> Image: ...
137
138
# Display function
139
def Show(image: Image, title="", debugOn=False): ...
140
```
141
142
[I/O Operations](./io-operations.md)
143
144
### Transforms
145
146
Geometric transformation classes for image registration, spatial alignment, and coordinate system manipulation. Supports rigid, affine, deformable, and specialized transformations with parameter optimization.
147
148
```python { .api }
149
# Base Transform class
150
class Transform:
151
def GetParameters(self) -> tuple: ...
152
def SetParameters(self, parameters: tuple): ...
153
def GetFixedParameters(self) -> tuple: ...
154
def TransformPoint(self, point: tuple) -> tuple: ...
155
def GetInverse(self) -> Transform: ...
156
157
# Specific transform types
158
class AffineTransform(Transform): ...
159
class Euler3DTransform(Transform): ...
160
class BSplineTransform(Transform): ...
161
class DisplacementFieldTransform(Transform): ...
162
163
# Transform utilities
164
def ReadTransform(filename: str) -> Transform: ...
165
def WriteTransform(transform: Transform, filename: str): ...
166
```
167
168
[Transforms](./transforms.md)
169
170
### Image Processing Filters
171
172
291 image processing filters covering mathematical operations, morphological operations, smoothing, edge detection, thresholding, segmentation, frequency domain processing, and statistical analysis. Available as both classes and procedural functions.
173
174
```python { .api }
175
# Mathematical operations
176
def Add(image1: Image, image2: Image) -> Image: ...
177
def Subtract(image1: Image, image2: Image) -> Image: ...
178
def Multiply(image1: Image, image2: Image) -> Image: ...
179
180
# Smoothing filters
181
def GaussianBlur(image: Image, sigma: float) -> Image: ...
182
def MedianFilter(image: Image, radius: int) -> Image: ...
183
def BilateralFilter(image: Image, domainSigma: float, rangeSigma: float) -> Image: ...
184
185
# Thresholding
186
def BinaryThreshold(image: Image, lowerThreshold: float, upperThreshold: float,
187
insideValue: int = 1, outsideValue: int = 0) -> Image: ...
188
def OtsuThreshold(image: Image, insideValue: int = 1, outsideValue: int = 0) -> Image: ...
189
190
# Edge detection
191
def CannyEdgeDetection(image: Image, lowerThreshold: float, upperThreshold: float,
192
variance: list = [1.0]) -> Image: ...
193
def SobelEdgeDetection(image: Image) -> Image: ...
194
195
# Morphological operations
196
def BinaryDilate(image: Image, radius: int = 1) -> Image: ...
197
def BinaryErode(image: Image, radius: int = 1) -> Image: ...
198
```
199
200
[Image Processing Filters](./filters.md)
201
202
### Registration
203
204
Complete image registration framework for aligning images through optimization of similarity metrics. Supports multi-modal registration, transformation parameter estimation, and evaluation metrics.
205
206
```python { .api }
207
class ImageRegistrationMethod:
208
def SetMetric(self, metric): ...
209
def SetOptimizer(self, optimizer): ...
210
def SetInitialTransform(self, transform: Transform): ...
211
def SetFixedImage(self, image: Image): ...
212
def SetMovingImage(self, image: Image): ...
213
def Execute(self) -> Transform: ...
214
def GetOptimizerIteration(self) -> int: ...
215
def GetMetricValue(self) -> float: ...
216
217
# Registration utilities
218
def ResampleImageFilter(image: Image, transform: Transform,
219
referenceImage: Image = None) -> Image: ...
220
```
221
222
[Registration](./registration.md)
223
224
## Common Pixel Types
225
226
```python { .api }
227
# Pixel type constants
228
sitkUInt8 = 1
229
sitkInt8 = 2
230
sitkUInt16 = 3
231
sitkInt16 = 4
232
sitkUInt32 = 5
233
sitkInt32 = 6
234
sitkUInt64 = 7
235
sitkInt64 = 8
236
sitkFloat32 = 9
237
sitkFloat64 = 10
238
sitkComplexFloat32 = 11
239
sitkComplexFloat64 = 12
240
sitkVectorUInt8 = 13
241
sitkVectorInt8 = 14
242
sitkVectorUInt16 = 15
243
sitkVectorInt16 = 16
244
sitkVectorUInt32 = 17
245
sitkVectorInt32 = 18
246
sitkVectorFloat32 = 19
247
sitkVectorFloat64 = 20
248
```
249
250
## Interpolation Methods
251
252
```python { .api }
253
# Interpolation constants
254
sitkNearestNeighbor = 1
255
sitkLinear = 2
256
sitkBSpline = 3
257
sitkGaussian = 4
258
sitkLabelGaussian = 5
259
sitkHammingWindowedSinc = 6
260
sitkCosineWindowedSinc = 7
261
sitkWelchWindowedSinc = 8
262
sitkLanczosWindowedSinc = 9
263
sitkBlackmanWindowedSinc = 10
264
```