0
# Image Processing Filters
1
2
SimpleITK provides 291 image processing filters covering mathematical operations, morphological operations, smoothing, edge detection, thresholding, segmentation, frequency domain processing, and statistical analysis. All filters are available as both classes and procedural functions for convenient usage.
3
4
## Filter Usage Patterns
5
6
All filters follow consistent patterns:
7
8
```python { .api }
9
# Procedural interface (recommended for simple usage)
10
def FilterName(input_image: Image, parameter1: type, parameter2: type, ...) -> Image:
11
"""Filter description"""
12
13
# Class interface (for advanced parameter control)
14
class FilterNameImageFilter:
15
def __init__(self): ...
16
def SetParameter1(self, value: type): ...
17
def GetParameter1(self) -> type: ...
18
def Execute(self, input_image: Image) -> Image: ...
19
```
20
21
## Capabilities
22
23
### Mathematical Operations
24
25
Pixel-wise mathematical operations between images or with scalar values.
26
27
```python { .api }
28
# Binary operations
29
def Add(image1: Image, image2: Image) -> Image:
30
"""Add two images pixel-wise"""
31
32
def Subtract(image1: Image, image2: Image) -> Image:
33
"""Subtract second image from first pixel-wise"""
34
35
def Multiply(image1: Image, image2: Image) -> Image:
36
"""Multiply two images pixel-wise"""
37
38
def Divide(image1: Image, image2: Image) -> Image:
39
"""Divide first image by second pixel-wise"""
40
41
def Maximum(image1: Image, image2: Image) -> Image:
42
"""Pixel-wise maximum of two images"""
43
44
def Minimum(image1: Image, image2: Image) -> Image:
45
"""Pixel-wise minimum of two images"""
46
47
def SquaredDifference(image1: Image, image2: Image) -> Image:
48
"""Squared difference between images"""
49
50
def AbsoluteValueDifference(image1: Image, image2: Image) -> Image:
51
"""Absolute value of difference between images"""
52
53
# Unary operations
54
def Abs(image: Image) -> Image:
55
"""Absolute value of each pixel"""
56
57
def Square(image: Image) -> Image:
58
"""Square each pixel value"""
59
60
def Sqrt(image: Image) -> Image:
61
"""Square root of each pixel value"""
62
63
def Exp(image: Image) -> Image:
64
"""Exponential of each pixel value"""
65
66
def ExpNegative(image: Image) -> Image:
67
"""Exponential of negative pixel values"""
68
69
def Log(image: Image) -> Image:
70
"""Natural logarithm of each pixel value"""
71
72
def Log10(image: Image) -> Image:
73
"""Base-10 logarithm of each pixel value"""
74
75
def UnaryMinus(image: Image) -> Image:
76
"""Negate each pixel value"""
77
78
def BoundedReciprocal(image: Image) -> Image:
79
"""Bounded reciprocal (1/x) with overflow protection"""
80
81
# Trigonometric functions
82
def Sin(image: Image) -> Image:
83
"""Sine of each pixel value"""
84
85
def Cos(image: Image) -> Image:
86
"""Cosine of each pixel value"""
87
88
def Tan(image: Image) -> Image:
89
"""Tangent of each pixel value"""
90
91
def Asin(image: Image) -> Image:
92
"""Arcsine of each pixel value"""
93
94
def Acos(image: Image) -> Image:
95
"""Arccosine of each pixel value"""
96
97
def Atan(image: Image) -> Image:
98
"""Arctangent of each pixel value"""
99
100
def Atan2(image1: Image, image2: Image) -> Image:
101
"""Two-argument arctangent"""
102
103
# Power and modulus
104
def Pow(image: Image, exponent: float) -> Image:
105
"""Raise pixels to power"""
106
107
def Modulus(image1: Image, image2: Image) -> Image:
108
"""Modulus operation between images"""
109
110
# N-ary operations
111
def NaryAdd(*images: Image) -> Image:
112
"""Add multiple images together"""
113
114
def NaryMaximum(*images: Image) -> Image:
115
"""Element-wise maximum across multiple images"""
116
```
117
118
### Comparison Operations
119
120
Pixel-wise comparison operations producing binary images.
121
122
```python { .api }
123
def Equal(image1: Image, image2: Image) -> Image:
124
"""Test pixel-wise equality"""
125
126
def NotEqual(image1: Image, image2: Image) -> Image:
127
"""Test pixel-wise inequality"""
128
129
def Greater(image1: Image, image2: Image) -> Image:
130
"""Test if first image pixels are greater than second"""
131
132
def GreaterEqual(image1: Image, image2: Image) -> Image:
133
"""Test if first image pixels are greater than or equal to second"""
134
135
def Less(image1: Image, image2: Image) -> Image:
136
"""Test if first image pixels are less than second"""
137
138
def LessEqual(image1: Image, image2: Image) -> Image:
139
"""Test if first image pixels are less than or equal to second"""
140
```
141
142
### Logical Operations
143
144
Pixel-wise logical operations for binary images.
145
146
```python { .api }
147
def And(image1: Image, image2: Image) -> Image:
148
"""Logical AND of two binary images"""
149
150
def Or(image1: Image, image2: Image) -> Image:
151
"""Logical OR of two binary images"""
152
153
def Xor(image1: Image, image2: Image) -> Image:
154
"""Logical XOR of two binary images"""
155
156
def Not(image: Image) -> Image:
157
"""Logical NOT of binary image"""
158
159
def BitwiseNot(image: Image) -> Image:
160
"""Bitwise NOT operation"""
161
```
162
163
### Smoothing and Denoising Filters
164
165
Filters for noise reduction and image smoothing while preserving important features.
166
167
```python { .api }
168
def SmoothingRecursiveGaussian(image: Image, sigma: float) -> Image:
169
"""
170
Efficient recursive Gaussian smoothing.
171
172
Args:
173
image: Input image
174
sigma: Standard deviation of Gaussian kernel
175
"""
176
177
def DiscreteGaussian(image: Image, variance: float, maximumKernelWidth: int = 32) -> Image:
178
"""
179
Discrete Gaussian smoothing with finite kernel.
180
181
Args:
182
image: Input image
183
variance: Gaussian variance
184
maximumKernelWidth: Maximum kernel size
185
"""
186
187
def BilateralFilter(image: Image, domainSigma: float, rangeSigma: float) -> Image:
188
"""
189
Edge-preserving bilateral filtering.
190
191
Args:
192
image: Input image
193
domainSigma: Spatial smoothing parameter
194
rangeSigma: Intensity smoothing parameter
195
"""
196
197
def MedianFilter(image: Image, radius: int = 1) -> Image:
198
"""
199
Median filtering for noise reduction.
200
201
Args:
202
image: Input image
203
radius: Neighborhood radius
204
"""
205
206
def MeanFilter(image: Image, radius: int = 1) -> Image:
207
"""
208
Mean filtering (box filter).
209
210
Args:
211
image: Input image
212
radius: Neighborhood radius
213
"""
214
215
def CurvatureAnisotropicDiffusion(image: Image, timeStep: float = 0.0625,
216
numberOfIterations: int = 5,
217
conductanceParameter: float = 3.0) -> Image:
218
"""
219
Curvature-driven anisotropic diffusion for edge-preserving smoothing.
220
221
Args:
222
image: Input image
223
timeStep: Time step for diffusion
224
numberOfIterations: Number of diffusion iterations
225
conductanceParameter: Controls edge preservation
226
"""
227
228
def GradientAnisotropicDiffusion(image: Image, timeStep: float = 0.0625,
229
numberOfIterations: int = 5,
230
conductanceParameter: float = 1.0) -> Image:
231
"""Gradient-based anisotropic diffusion"""
232
233
def PatchBasedDenoising(image: Image, kernelBandwidthSigma: float = 400.0,
234
patchRadius: int = 4, numberOfIterations: int = 1) -> Image:
235
"""
236
Patch-based denoising using non-local means approach.
237
238
Args:
239
image: Input image
240
kernelBandwidthSigma: Controls similarity weighting
241
patchRadius: Patch size radius
242
numberOfIterations: Number of denoising iterations
243
"""
244
245
def BinomialBlur(image: Image, repetitions: int = 1) -> Image:
246
"""Binomial blurring (approximates Gaussian)"""
247
248
def RecursiveGaussian(image: Image, sigma: float, direction: int = 0) -> Image:
249
"""Recursive Gaussian filtering along specific direction"""
250
```
251
252
### Thresholding Filters
253
254
Convert grayscale images to binary images using various thresholding methods.
255
256
```python { .api }
257
def BinaryThreshold(image: Image, lowerThreshold: float, upperThreshold: float,
258
insideValue: int = 1, outsideValue: int = 0) -> Image:
259
"""
260
Binary thresholding with specified range.
261
262
Args:
263
image: Input image
264
lowerThreshold: Lower threshold value
265
upperThreshold: Upper threshold value
266
insideValue: Value for pixels in range
267
outsideValue: Value for pixels outside range
268
"""
269
270
def Threshold(image: Image, lower: float, upper: float, outsideValue: float) -> Image:
271
"""Threshold with clamping outside values"""
272
273
def OtsuThreshold(image: Image, insideValue: int = 1, outsideValue: int = 0,
274
numberOfHistogramBins: int = 128) -> Image:
275
"""
276
Otsu's automatic thresholding method.
277
278
Args:
279
image: Input image
280
insideValue: Value for foreground pixels
281
outsideValue: Value for background pixels
282
numberOfHistogramBins: Histogram bins for threshold computation
283
"""
284
285
def OtsuMultipleThresholds(image: Image, numberOfThresholds: int = 1,
286
numberOfHistogramBins: int = 128) -> Image:
287
"""Multi-level Otsu thresholding"""
288
289
def TriangleThreshold(image: Image, insideValue: int = 1, outsideValue: int = 0) -> Image:
290
"""Triangle method automatic thresholding"""
291
292
def YenThreshold(image: Image, insideValue: int = 1, outsideValue: int = 0) -> Image:
293
"""Yen's automatic thresholding method"""
294
295
def HuangThreshold(image: Image, insideValue: int = 1, outsideValue: int = 0) -> Image:
296
"""Huang's fuzzy thresholding method"""
297
298
def IntermodesThreshold(image: Image, insideValue: int = 1, outsideValue: int = 0) -> Image:
299
"""Intermodes thresholding (assumes bimodal histogram)"""
300
301
def IsoDataThreshold(image: Image, insideValue: int = 1, outsideValue: int = 0) -> Image:
302
"""IsoData iterative thresholding"""
303
304
def KittlerIllingworthThreshold(image: Image, insideValue: int = 1, outsideValue: int = 0) -> Image:
305
"""Kittler-Illingworth minimum error thresholding"""
306
307
def LiThreshold(image: Image, insideValue: int = 1, outsideValue: int = 0) -> Image:
308
"""Li's iterative selection method"""
309
310
def MaximumEntropyThreshold(image: Image, insideValue: int = 1, outsideValue: int = 0) -> Image:
311
"""Maximum entropy thresholding"""
312
313
def MomentsThreshold(image: Image, insideValue: int = 1, outsideValue: int = 0) -> Image:
314
"""Moments-based thresholding"""
315
316
def RenyiEntropyThreshold(image: Image, insideValue: int = 1, outsideValue: int = 0) -> Image:
317
"""Renyi entropy thresholding"""
318
319
def ShanbhagThreshold(image: Image, insideValue: int = 1, outsideValue: int = 0) -> Image:
320
"""Shanbhag's thresholding method"""
321
322
def DoubleThreshold(image: Image, threshold1: float, threshold2: float) -> Image:
323
"""Double thresholding with three output levels"""
324
```
325
326
### Morphological Operations
327
328
Shape-based operations for binary and grayscale images.
329
330
```python { .api }
331
# Binary morphological operations
332
def BinaryDilate(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
333
"""
334
Binary dilation operation.
335
336
Args:
337
image: Binary input image
338
radius: Structuring element radius
339
kernelType: Kernel shape (1=ball, 2=box, 3=cross)
340
"""
341
342
def BinaryErode(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
343
"""Binary erosion operation"""
344
345
def BinaryMorphologicalOpening(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
346
"""Binary morphological opening (erosion followed by dilation)"""
347
348
def BinaryMorphologicalClosing(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
349
"""Binary morphological closing (dilation followed by erosion)"""
350
351
def BinaryFillhole(image: Image) -> Image:
352
"""Fill holes in binary objects"""
353
354
def BinaryGrindPeak(image: Image) -> Image:
355
"""Remove peaks in binary image"""
356
357
def BinaryThinning(image: Image) -> Image:
358
"""Thinning of binary objects to skeleton"""
359
360
# Grayscale morphological operations
361
def GrayscaleDilate(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
362
"""Grayscale dilation"""
363
364
def GrayscaleErode(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
365
"""Grayscale erosion"""
366
367
def GrayscaleMorphologicalOpening(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
368
"""Grayscale morphological opening"""
369
370
def GrayscaleMorphologicalClosing(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
371
"""Grayscale morphological closing"""
372
373
def GrayscaleFillhole(image: Image) -> Image:
374
"""Fill holes in grayscale image"""
375
376
def GrayscaleGrindPeak(image: Image) -> Image:
377
"""Remove peaks in grayscale image"""
378
379
# Top-hat transforms
380
def WhiteTopHat(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
381
"""White top-hat transform (original - opening)"""
382
383
def BlackTopHat(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
384
"""Black top-hat transform (closing - original)"""
385
386
def MorphologicalGradient(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
387
"""Morphological gradient (dilation - erosion)"""
388
389
# Reconstruction operations
390
def ReconstructionByDilation(image: Image, mask: Image) -> Image:
391
"""Morphological reconstruction by dilation"""
392
393
def ReconstructionByErosion(image: Image, mask: Image) -> Image:
394
"""Morphological reconstruction by erosion"""
395
396
def OpeningByReconstruction(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
397
"""Opening by reconstruction"""
398
399
def ClosingByReconstruction(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
400
"""Closing by reconstruction"""
401
402
def BinaryOpeningByReconstruction(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
403
"""Binary opening by reconstruction"""
404
405
def BinaryClosingByReconstruction(image: Image, radius: int = 1, kernelType: int = 1) -> Image:
406
"""Binary closing by reconstruction"""
407
408
def BinaryReconstructionByDilation(image: Image, mask: Image) -> Image:
409
"""Binary reconstruction by dilation"""
410
411
def BinaryReconstructionByErosion(image: Image, mask: Image) -> Image:
412
"""Binary reconstruction by erosion"""
413
414
# H-transforms for peak/valley detection
415
def HMaxima(image: Image, height: float) -> Image:
416
"""H-maxima transform (suppress maxima below height)"""
417
418
def HMinima(image: Image, height: float) -> Image:
419
"""H-minima transform (suppress minima above height)"""
420
421
def HConvex(image: Image, height: float) -> Image:
422
"""H-convex transform"""
423
424
def HConcave(image: Image, height: float) -> Image:
425
"""H-concave transform"""
426
```
427
428
### Image Grid Operations
429
430
Fundamental image manipulation operations including resampling, cropping, padding, and geometric transformations.
431
432
```python { .api }
433
def ResampleImageFilter(image: Image, transform: Transform = None,
434
interpolator: int = None, size: tuple = None,
435
outputSpacing: tuple = None, outputOrigin: tuple = None,
436
outputDirection: tuple = None, defaultPixelValue: float = 0.0) -> Image:
437
"""
438
Resample image to new grid with optional transformation.
439
440
Args:
441
image: Input image to resample
442
transform: Optional geometric transformation
443
interpolator: Interpolation method (sitkLinear, sitkNearestNeighbor, etc.)
444
size: Output image size tuple
445
outputSpacing: Output pixel spacing tuple
446
outputOrigin: Output image origin tuple
447
outputDirection: Output image direction matrix
448
defaultPixelValue: Fill value for pixels outside input
449
"""
450
451
def CropImageFilter(image: Image, lowerBoundaryCropSize: tuple,
452
upperBoundaryCropSize: tuple) -> Image:
453
"""
454
Crop image by removing pixels from boundaries.
455
456
Args:
457
image: Input image
458
lowerBoundaryCropSize: Pixels to remove from lower boundaries (x,y,z)
459
upperBoundaryCropSize: Pixels to remove from upper boundaries (x,y,z)
460
"""
461
462
def BinShrinkImageFilter(image: Image, shrinkFactors: tuple) -> Image:
463
"""
464
Shrink image by averaging pixels in local neighborhoods.
465
466
Args:
467
image: Input image
468
shrinkFactors: Shrinkage factor for each dimension
469
"""
470
471
def ShrinkImageFilter(image: Image, shrinkFactors: tuple) -> Image:
472
"""
473
Shrink image by subsampling (no averaging).
474
475
Args:
476
image: Input image
477
shrinkFactors: Shrinkage factor for each dimension
478
"""
479
480
def FlipImageFilter(image: Image, flipAxes: tuple) -> Image:
481
"""
482
Flip image along specified axes.
483
484
Args:
485
image: Input image
486
flipAxes: Boolean tuple indicating which axes to flip
487
"""
488
489
def WarpImageFilter(image: Image, displacementField: Image, interpolator: int = None,
490
outputSpacing: tuple = None, outputOrigin: tuple = None,
491
outputDirection: tuple = None, edgePaddingValue: float = 0.0) -> Image:
492
"""
493
Warp image using displacement field.
494
495
Args:
496
image: Input image to warp
497
displacementField: Vector image defining displacement at each pixel
498
interpolator: Interpolation method
499
outputSpacing: Output pixel spacing
500
outputOrigin: Output image origin
501
outputDirection: Output image direction
502
edgePaddingValue: Fill value for warped regions
503
"""
504
505
def RegionOfInterestImageFilter(image: Image, size: tuple, index: tuple) -> Image:
506
"""
507
Extract rectangular region of interest.
508
509
Args:
510
image: Input image
511
size: Size of ROI in each dimension
512
index: Starting index of ROI
513
"""
514
515
def PermuteAxesImageFilter(image: Image, order: tuple) -> Image:
516
"""
517
Reorder image axes by permuting dimensions.
518
519
Args:
520
image: Input image
521
order: New order of axes (e.g., (2,0,1) for z,x,y)
522
"""
523
524
def TileImageFilter(images: list, layout: tuple) -> Image:
525
"""
526
Tile multiple images into single image.
527
528
Args:
529
images: List of input images to tile
530
layout: Layout specification (rows, columns, slices)
531
"""
532
533
def PasteImageFilter(destinationImage: Image, sourceImage: Image,
534
sourceSize: tuple, sourceIndex: tuple,
535
destinationIndex: tuple) -> Image:
536
"""
537
Paste source image region into destination image.
538
539
Args:
540
destinationImage: Target image
541
sourceImage: Source image to paste from
542
sourceSize: Size of region to paste
543
sourceIndex: Starting index in source image
544
destinationIndex: Target location in destination image
545
"""
546
547
def CyclicShiftImageFilter(image: Image, shift: tuple) -> Image:
548
"""
549
Cyclically shift image by specified offset.
550
551
Args:
552
image: Input image
553
shift: Shift amount for each dimension
554
"""
555
556
def ZeroFluxNeumannPadImageFilter(image: Image, padUpperBound: tuple,
557
padLowerBound: tuple) -> Image:
558
"""
559
Pad image using Neumann boundary conditions (zero flux).
560
561
Args:
562
image: Input image
563
padUpperBound: Padding size for upper boundaries
564
padLowerBound: Padding size for lower boundaries
565
"""
566
567
def WrapPadImageFilter(image: Image, padUpperBound: tuple,
568
padLowerBound: tuple) -> Image:
569
"""
570
Pad image using wrap-around boundary conditions.
571
572
Args:
573
image: Input image
574
padUpperBound: Padding size for upper boundaries
575
padLowerBound: Padding size for lower boundaries
576
"""
577
```
578
579
### Edge Detection
580
581
Filters for detecting edges and boundaries in images.
582
583
```python { .api }
584
def CannyEdgeDetection(image: Image, lowerThreshold: float, upperThreshold: float,
585
variance: list = [1.0], maximumKernelWidth: int = 32) -> Image:
586
"""
587
Canny edge detection with hysteresis thresholding.
588
589
Args:
590
image: Input image
591
lowerThreshold: Lower threshold for edge linking
592
upperThreshold: Upper threshold for edge detection
593
variance: Gaussian smoothing variance per dimension
594
maximumKernelWidth: Maximum Gaussian kernel width
595
"""
596
597
def SobelEdgeDetection(image: Image) -> Image:
598
"""Sobel edge detection using gradient magnitude"""
599
600
def ZeroCrossingBasedEdgeDetection(image: Image, variance: float = 1.0,
601
foregroundValue: int = 1, backgroundValue: int = 0) -> Image:
602
"""Zero-crossing edge detection using Laplacian of Gaussian"""
603
604
def LaplacianImageFilter(image: Image) -> Image:
605
"""Laplacian edge detection filter"""
606
607
def LaplacianRecursiveGaussian(image: Image, sigma: float = 1.0) -> Image:
608
"""Laplacian of Gaussian edge detection"""
609
610
def LaplacianSharpeningImageFilter(image: Image) -> Image:
611
"""Laplacian sharpening filter"""
612
613
def GradientMagnitude(image: Image) -> Image:
614
"""Gradient magnitude for edge strength"""
615
616
def GradientMagnitudeRecursiveGaussian(image: Image, sigma: float = 1.0) -> Image:
617
"""Gradient magnitude using recursive Gaussian derivatives"""
618
619
def Gradient(image: Image) -> Image:
620
"""Gradient vector image"""
621
622
def GradientRecursiveGaussian(image: Image, sigma: float = 1.0) -> Image:
623
"""Gradient using recursive Gaussian derivatives"""
624
625
def Derivative(image: Image, direction: int = 0, order: int = 1) -> Image:
626
"""Directional derivative along specified axis"""
627
628
def DiscreteGaussianDerivative(image: Image, order: int = 1, variance: float = 1.0,
629
direction: int = 0, maximumKernelWidth: int = 32) -> Image:
630
"""Discrete Gaussian derivative"""
631
```
632
633
### Segmentation Filters
634
635
Region growing and level set methods for image segmentation.
636
637
```python { .api }
638
def ConnectedThreshold(image: Image, seedList: list, lower: float, upper: float,
639
replaceValue: int = 1) -> Image:
640
"""
641
Connected component segmentation using intensity thresholds.
642
643
Args:
644
image: Input image
645
seedList: List of seed points as [(x,y[,z]), ...]
646
lower: Lower intensity threshold
647
upper: Upper intensity threshold
648
replaceValue: Value for segmented region
649
"""
650
651
def ConfidenceConnected(image: Image, seedList: list, numberOfIterations: int = 1,
652
multiplier: float = 2.5, initialNeighborhoodRadius: int = 1,
653
replaceValue: int = 1) -> Image:
654
"""
655
Confidence connected region growing based on statistics.
656
657
Args:
658
image: Input image
659
seedList: List of seed points
660
numberOfIterations: Number of iterations
661
multiplier: Confidence interval multiplier
662
initialNeighborhoodRadius: Initial neighborhood radius
663
replaceValue: Value for segmented region
664
"""
665
666
def NeighborhoodConnected(image: Image, seedList: list, lower: float, upper: float,
667
radius: int = 1, replaceValue: int = 1) -> Image:
668
"""Neighborhood-based connected component segmentation"""
669
670
def IsolatedConnected(image: Image, seed1: list, seed2: list, lower: float, upper: float,
671
replaceValue: int = 1) -> Image:
672
"""
673
Isolated connected segmentation between two seed regions.
674
675
Args:
676
image: Input image
677
seed1: Seed points for first region
678
seed2: Seed points for second region
679
lower: Lower threshold
680
upper: Upper threshold
681
replaceValue: Value for segmented region
682
"""
683
684
def VectorConfidenceConnected(image: Image, seedList: list, numberOfIterations: int = 1,
685
multiplier: float = 2.5, initialNeighborhoodRadius: int = 1) -> Image:
686
"""Confidence connected for vector images"""
687
688
# Level set segmentation
689
def GeodesicActiveContourLevelSet(image: Image, featureImage: Image,
690
maximumRMSError: float = 0.02, numberOfIterations: int = 1000,
691
curvatureScaling: float = 1.0, advectionScaling: float = 1.0,
692
propagationScaling: float = 1.0) -> Image:
693
"""
694
Geodesic active contour level set segmentation.
695
696
Args:
697
image: Initial level set image
698
featureImage: Feature image (edge potential)
699
maximumRMSError: Convergence criteria
700
numberOfIterations: Maximum iterations
701
curvatureScaling: Curvature term weight
702
advectionScaling: Advection term weight
703
propagationScaling: Propagation term weight
704
"""
705
706
def ShapeDetectionLevelSet(image: Image, featureImage: Image,
707
maximumRMSError: float = 0.02, numberOfIterations: int = 1000,
708
curvatureScaling: float = 1.0, propagationScaling: float = 1.0) -> Image:
709
"""Shape detection level set method"""
710
711
def ThresholdSegmentationLevelSet(image: Image, featureImage: Image,
712
lowerThreshold: float, upperThreshold: float,
713
maximumRMSError: float = 0.02, numberOfIterations: int = 1000,
714
curvatureScaling: float = 1.0, propagationScaling: float = 1.0) -> Image:
715
"""Threshold-based level set segmentation"""
716
717
def LaplacianSegmentationLevelSet(image: Image, featureImage: Image,
718
maximumRMSError: float = 0.02, numberOfIterations: int = 1000,
719
curvatureScaling: float = 1.0, propagationScaling: float = 1.0) -> Image:
720
"""Laplacian level set segmentation"""
721
722
def ScalarChanAndVeseDenseLevelSet(image: Image, maximumRMSError: float = 0.02,
723
numberOfIterations: int = 1000, lambda1: float = 1.0,
724
lambda2: float = 1.0, mu: float = 0.1, nu: float = 0.0,
725
epsilon: float = 1.0, heavisideStepFunction: int = 1) -> Image:
726
"""Chan-Vese level set segmentation for scalar images"""
727
728
# Watershed segmentation
729
def MorphologicalWatershed(image: Image, level: float = 0.0, markWatershedLine: bool = True,
730
fullyConnected: bool = False) -> Image:
731
"""
732
Morphological watershed segmentation.
733
734
Args:
735
image: Input image (typically gradient magnitude)
736
level: Water level for flooding
737
markWatershedLine: Mark watershed boundaries
738
fullyConnected: Use full connectivity
739
"""
740
741
def MorphologicalWatershedFromMarkers(image: Image, markerImage: Image,
742
markWatershedLine: bool = True,
743
fullyConnected: bool = False) -> Image:
744
"""Watershed segmentation with pre-defined markers"""
745
746
def IsolatedWatershed(image: Image, seed1: list, seed2: list, threshold: float = 0.0,
747
isolatedValueTolerance: float = 0.001, upperValueLimit: float = 1.0,
748
replaceValue1: int = 1, replaceValue2: int = 2) -> Image:
749
"""Isolated watershed between two seed regions"""
750
751
# Other segmentation methods
752
def CollidingFronts(image: Image, seed1: list, seed2: list) -> Image:
753
"""Colliding fronts segmentation method"""
754
755
def FastMarching(image: Image, trialPoints: list, stoppingValue: float = 1e38) -> Image:
756
"""
757
Fast marching method for front propagation.
758
759
Args:
760
image: Speed image
761
trialPoints: Initial front points with travel times
762
stoppingValue: Stop when front reaches this value
763
"""
764
765
def FastMarchingUpwindGradient(image: Image, trialPoints: list, stoppingValue: float = 1e38) -> Image:
766
"""Fast marching with upwind gradient computation"""
767
```
768
769
### Connected Component Analysis
770
771
Analyze connected regions in binary and labeled images.
772
773
```python { .api }
774
def ConnectedComponent(image: Image, fullyConnected: bool = False) -> Image:
775
"""
776
Label connected components in binary image.
777
778
Args:
779
image: Binary input image
780
fullyConnected: Use 8-connectivity (2D) or 26-connectivity (3D)
781
782
Returns:
783
Labeled image with unique labels for each component
784
"""
785
786
def ScalarConnectedComponent(image: Image, fullyConnected: bool = False) -> Image:
787
"""Connected components for scalar images (same intensity)"""
788
789
def VectorConnectedComponent(image: Image, distanceThreshold: float = 0.0,
790
fullyConnected: bool = False) -> Image:
791
"""Connected components for vector images"""
792
793
def RelabelComponent(image: Image, minimumObjectSize: int = 0,
794
sortByObjectSize: bool = True) -> Image:
795
"""
796
Relabel connected components by size.
797
798
Args:
799
image: Labeled input image
800
minimumObjectSize: Remove components smaller than this
801
sortByObjectSize: Sort labels by component size
802
"""
803
804
def BinaryImageToLabelMap(image: Image, fullyConnected: bool = False,
805
inputForegroundValue: int = 1, outputBackgroundValue: int = 0) -> Image:
806
"""Convert binary image to label map"""
807
808
def LabelImageToLabelMap(image: Image, backgroundValue: int = 0) -> Image:
809
"""Convert labeled image to label map format"""
810
811
def LabelMapToBinary(image: Image, backgroundValue: int = 0) -> Image:
812
"""Convert label map to binary image"""
813
814
def LabelMapToLabel(image: Image, backgroundValue: int = 0) -> Image:
815
"""Convert label map to labeled image"""
816
```
817
818
### Statistical and Measurement Filters
819
820
Compute statistics and measurements on images and regions.
821
822
```python { .api }
823
def StatisticsImageFilter(image: Image) -> dict:
824
"""
825
Compute basic image statistics.
826
827
Returns:
828
Dictionary with 'Mean', 'Variance', 'Sigma', 'Minimum', 'Maximum', 'Sum'
829
"""
830
831
def MinimumMaximum(image: Image) -> tuple:
832
"""
833
Find minimum and maximum pixel values.
834
835
Returns:
836
Tuple of (minimum, maximum)
837
"""
838
839
def LabelStatistics(image: Image, labelImage: Image) -> dict:
840
"""
841
Compute statistics for each labeled region.
842
843
Args:
844
image: Intensity image
845
labelImage: Label image defining regions
846
847
Returns:
848
Dictionary with statistics per label
849
"""
850
851
def LabelIntensityStatistics(image: Image, labelImage: Image) -> dict:
852
"""Intensity statistics for labeled regions"""
853
854
def LabelShapeStatistics(image: Image) -> dict:
855
"""
856
Compute shape statistics for labeled regions.
857
858
Returns:
859
Dictionary with shape measurements per label
860
"""
861
862
def HistogramMatching(image: Image, referenceImage: Image, numberOfHistogramLevels: int = 256,
863
numberOfMatchPoints: int = 1, thresholdAtMeanIntensity: bool = True) -> Image:
864
"""
865
Match histogram of image to reference image.
866
867
Args:
868
image: Image to modify
869
referenceImage: Target histogram image
870
numberOfHistogramLevels: Histogram bins
871
numberOfMatchPoints: Match points for transformation
872
thresholdAtMeanIntensity: Use mean as threshold
873
"""
874
875
def NormalizeImageFilter(image: Image) -> Image:
876
"""Normalize image to [0,1] range"""
877
878
def NormalizeToConstant(image: Image, constant: float = 1.0) -> Image:
879
"""Normalize image so sum equals constant"""
880
881
def RescaleIntensity(image: Image, outputMinimum: float = 0.0, outputMaximum: float = 255.0) -> Image:
882
"""
883
Rescale intensities to specified range.
884
885
Args:
886
image: Input image
887
outputMinimum: Minimum output value
888
outputMaximum: Maximum output value
889
"""
890
891
def IntensityWindowing(image: Image, windowMinimum: float, windowMaximum: float,
892
outputMinimum: float = 0.0, outputMaximum: float = 255.0) -> Image:
893
"""
894
Window intensity values to specified range.
895
896
Args:
897
image: Input image
898
windowMinimum: Input window minimum
899
windowMaximum: Input window maximum
900
outputMinimum: Output minimum
901
outputMaximum: Output maximum
902
"""
903
904
def ShiftScale(image: Image, shift: float = 0.0, scale: float = 1.0) -> Image:
905
"""Apply linear transformation: output = (input + shift) * scale"""
906
907
def Clamp(image: Image, lowerBound: float = 0.0, upperBound: float = 255.0) -> Image:
908
"""Clamp pixel values to specified range"""
909
910
def Sigmoid(image: Image, alpha: float = 1.0, beta: float = 0.0,
911
outputMinimum: float = 0.0, outputMaximum: float = 1.0) -> Image:
912
"""
913
Sigmoid intensity transformation.
914
915
Args:
916
image: Input image
917
alpha: Controls sigmoid slope
918
beta: Controls sigmoid center
919
outputMinimum: Minimum output value
920
outputMaximum: Maximum output value
921
"""
922
```
923
924
### Noise Addition Filters
925
926
Add various types of noise to images for testing and simulation.
927
928
```python { .api }
929
def AdditiveGaussianNoise(image: Image, mean: float = 0.0, standardDeviation: float = 1.0) -> Image:
930
"""
931
Add Gaussian noise to image.
932
933
Args:
934
image: Input image
935
mean: Noise mean
936
standardDeviation: Noise standard deviation
937
"""
938
939
def SaltAndPepperNoise(image: Image, probability: float = 0.01, saltValue: float = 1.0) -> Image:
940
"""Add salt and pepper noise"""
941
942
def ShotNoise(image: Image, scale: float = 1.0) -> Image:
943
"""Add Poisson (shot) noise"""
944
945
def SpeckleNoise(image: Image, standardDeviation: float = 1.0) -> Image:
946
"""Add speckle (multiplicative) noise"""
947
948
def NoiseImageFilter(image: Image) -> Image:
949
"""Add uniform random noise"""
950
```
951
952
### Usage Examples
953
954
#### Basic Filter Usage
955
956
```python
957
import SimpleITK as sitk
958
959
# Read image
960
image = sitk.ReadImage('input.dcm')
961
962
# Apply Gaussian smoothing (procedural interface)
963
smoothed = sitk.SmoothingRecursiveGaussian(image, 2.0)
964
965
# Apply thresholding
966
binary = sitk.BinaryThreshold(smoothed, 100, 255, 255, 0)
967
968
# Chain multiple operations
969
result = sitk.BinaryMorphologicalClosing(
970
sitk.BinaryMorphologicalOpening(binary, 3),
971
3
972
)
973
```
974
975
#### Class-based Filter Control
976
977
```python
978
import SimpleITK as sitk
979
980
# Create filter object for detailed parameter control
981
gaussian_filter = sitk.SmoothingRecursiveGaussianImageFilter()
982
gaussian_filter.SetSigma(2.5)
983
gaussian_filter.SetNormalizeAcrossScale(True)
984
985
# Apply filter
986
smoothed = gaussian_filter.Execute(image)
987
988
# Check filter properties
989
print(f"Sigma: {gaussian_filter.GetSigma()}")
990
print(f"Normalize: {gaussian_filter.GetNormalizeAcrossScale()}")
991
```
992
993
#### Segmentation Pipeline
994
995
```python
996
import SimpleITK as sitk
997
998
# Load image
999
image = sitk.ReadImage('medical_scan.dcm')
1000
1001
# Preprocessing
1002
smoothed = sitk.SmoothingRecursiveGaussian(image, 1.0)
1003
grad_mag = sitk.GradientMagnitude(smoothed)
1004
1005
# Seed-based segmentation
1006
seeds = [(100, 150, 75), (120, 140, 80)] # Example seed points
1007
segmented = sitk.ConnectedThreshold(smoothed, seeds, 50, 200, 255)
1008
1009
# Post-processing
1010
cleaned = sitk.BinaryMorphologicalClosing(segmented, 2)
1011
filled = sitk.BinaryFillhole(cleaned)
1012
1013
# Save result
1014
sitk.WriteImage(filled, 'segmentation_result.png')
1015
```
1016
1017
#### Statistical Analysis
1018
1019
```python
1020
import SimpleITK as sitk
1021
1022
# Load images
1023
image = sitk.ReadImage('data.nii')
1024
labels = sitk.ReadImage('labels.nii')
1025
1026
# Compute basic statistics
1027
stats_filter = sitk.StatisticsImageFilter()
1028
stats_filter.Execute(image)
1029
1030
print(f"Mean: {stats_filter.GetMean()}")
1031
print(f"Std Dev: {stats_filter.GetSigma()}")
1032
print(f"Min: {stats_filter.GetMinimum()}")
1033
print(f"Max: {stats_filter.GetMaximum()}")
1034
1035
# Statistics per labeled region
1036
label_stats_filter = sitk.LabelStatisticsImageFilter()
1037
label_stats_filter.Execute(image, labels)
1038
1039
labels_list = label_stats_filter.GetLabels()
1040
for label in labels_list:
1041
print(f"Label {label}:")
1042
print(f" Mean: {label_stats_filter.GetMean(label)}")
1043
print(f" Volume: {label_stats_filter.GetCount(label)}")
1044
```