0
# SimpleITK
1
2
SimpleITK 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.
3
4
## Package Information
5
6
- **Package Name**: SimpleITK
7
- **Language**: Python (with C++ backend)
8
- **Installation**: `pip install SimpleITK`
9
10
## Core Imports
11
12
```python
13
import SimpleITK as sitk
14
```
15
16
Common for working with NumPy arrays:
17
18
```python
19
import SimpleITK as sitk
20
import numpy as np
21
```
22
23
## Basic Usage
24
25
```python
26
import SimpleITK as sitk
27
28
# Read an image
29
image = sitk.ReadImage('input.nii.gz')
30
31
# Apply Gaussian smoothing
32
smoothed = sitk.SmoothingRecursiveGaussian(image, sigma=2.0)
33
34
# Write the result
35
sitk.WriteImage(smoothed, 'output.nii.gz')
36
37
# NumPy integration
38
array = sitk.GetArrayFromImage(image)
39
processed_array = array * 2 # Simple processing
40
result_image = sitk.GetImageFromArray(processed_array)
41
result_image.CopyInformation(image) # Copy spacing, origin, direction
42
```
43
44
## Architecture
45
46
SimpleITK provides both procedural and object-oriented interfaces:
47
48
- **Image**: Core data structure representing n-dimensional images with metadata
49
- **Filters**: Image processing algorithms with configurable parameters
50
- **Transforms**: Geometric transformations for registration and resampling
51
- **Readers/Writers**: I/O operations for various medical image formats
52
- **NumPy Integration**: Seamless conversion between SimpleITK images and NumPy arrays
53
54
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.
55
56
## Capabilities
57
58
### Core Image Operations
59
60
Basic image I/O, NumPy integration, and fundamental image manipulations including creation, copying, and format conversion.
61
62
```python { .api }
63
def ReadImage(fileName, outputPixelType=sitkUnknown, imageIO=""): ...
64
def WriteImage(image, fileName, useCompression=False, compressionLevel=-1): ...
65
def GetArrayFromImage(image): ...
66
def GetImageFromArray(arr, isVector=None): ...
67
def GetArrayViewFromImage(image): ...
68
```
69
70
[Core Image Operations](./core-image-operations.md)
71
72
### Image Filtering
73
74
Comprehensive filtering operations including smoothing, edge detection, noise reduction, mathematical operations, and morphological processing.
75
76
```python { .api }
77
def SmoothingRecursiveGaussian(image, sigma=[1]*3, normalizeAcrossScale=False): ...
78
def DiscreteGaussian(image, variance=[1]*3, maximumKernelWidth=32): ...
79
def BinaryThreshold(image, lowerThreshold=0, upperThreshold=255): ...
80
def CannyEdgeDetection(image, lowerThreshold=0, upperThreshold=0): ...
81
```
82
83
[Image Filtering](./image-filtering.md)
84
85
### Segmentation
86
87
Advanced segmentation algorithms including threshold-based, region growing, watershed, and level set methods for extracting regions of interest.
88
89
```python { .api }
90
def ConnectedThreshold(image, seedList, lower=0, upper=255): ...
91
def RegionGrowing(image, seedList, multiplier=2.5, numberOfIterations=5): ...
92
def Watershed(image, level=0, markWatershedLine=True): ...
93
def FastMarchingImageFilter(): ...
94
```
95
96
[Segmentation](./segmentation.md)
97
98
### Registration and Transforms
99
100
Image registration algorithms and geometric transformations for aligning images and correcting spatial distortions.
101
102
```python { .api }
103
def Resample(image, referenceImage=None, transform=Transform()): ...
104
class ImageRegistrationMethod: ...
105
class Transform: ...
106
class AffineTransform: ...
107
class BSplineTransform: ...
108
```
109
110
[Registration and Transforms](./registration-transforms.md)
111
112
### Morphological Operations
113
114
Mathematical morphology operations including erosion, dilation, opening, closing, and distance transforms for shape analysis.
115
116
```python { .api }
117
def BinaryErode(image, kernelRadius=[1]*3, kernelType=sitkBall): ...
118
def BinaryDilate(image, kernelRadius=[1]*3, kernelType=sitkBall): ...
119
def BinaryOpening(image, kernelRadius=[1]*3, kernelType=sitkBall): ...
120
def BinaryClosing(image, kernelRadius=[1]*3, kernelType=sitkBall): ...
121
```
122
123
[Morphological Operations](./morphological-operations.md)
124
125
### Feature Detection
126
127
Advanced feature detection algorithms including corner detection, blob detection, and texture analysis for image analysis.
128
129
```python { .api }
130
def LaplacianRecursiveGaussian(image, sigma=1.0): ...
131
def HessianRecursiveGaussian(image, sigma=1.0): ...
132
def LaplacianImageFilter(): ...
133
def HoughTransform(): ...
134
```
135
136
[Feature Detection](./feature-detection.md)
137
138
## Types
139
140
```python { .api }
141
class Image:
142
def __init__(size, pixelType, numberOfComponents=1): ...
143
def GetSize(): ...
144
def GetOrigin(): ...
145
def GetSpacing(): ...
146
def GetDirection(): ...
147
def GetPixelIDValue(): ...
148
def CopyInformation(sourceImage): ...
149
150
class Transform:
151
def __init__(): ...
152
def SetParameters(parameters): ...
153
def GetParameters(): ...
154
155
class ImageFileReader:
156
def SetFileName(fileName): ...
157
def Execute(): ...
158
159
class ImageFileWriter:
160
def SetFileName(fileName): ...
161
def Execute(image): ...
162
```