0
# Image Processing Filters
1
2
ITK provides an extensive collection of image processing filters organized in a hierarchical framework. All filters follow a pipeline architecture with lazy evaluation, supporting both basic pixel operations and advanced image analysis algorithms.
3
4
## Filter Base Classes
5
6
### ImageToImageFilter
7
8
Base class for filters that process images and produce images.
9
10
```cpp { .api }
11
template<typename TInputImage, typename TOutputImage>
12
class ImageToImageFilter : public ImageSource<TOutputImage>
13
{
14
public:
15
typedef ImageToImageFilter Self;
16
typedef ImageSource<TOutputImage> Superclass;
17
typedef SmartPointer<Self> Pointer;
18
typedef SmartPointer<const Self> ConstPointer;
19
20
// Input handling
21
using Superclass::SetInput;
22
virtual void SetInput(const TInputImage *image);
23
virtual void SetInput(unsigned int, const TInputImage *image);
24
const TInputImage * GetInput() const;
25
const TInputImage * GetInput(unsigned int idx) const;
26
27
// Pipeline management
28
virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
29
virtual void GenerateOutputInformation() ITK_OVERRIDE;
30
31
protected:
32
virtual void GenerateData() ITK_OVERRIDE;
33
virtual void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
34
ThreadIdType threadId);
35
};
36
```
37
38
### UnaryFunctorImageFilter
39
40
Base class for pixel-wise operations using function objects.
41
42
```cpp { .api }
43
template<typename TInputImage, typename TOutputImage, typename TFunction>
44
class UnaryFunctorImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
45
{
46
public:
47
typedef UnaryFunctorImageFilter Self;
48
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
49
typedef SmartPointer<Self> Pointer;
50
typedef SmartPointer<const Self> ConstPointer;
51
52
// Functor access
53
FunctionType & GetFunctor();
54
const FunctionType & GetFunctor() const;
55
void SetFunctor(const FunctionType & functor);
56
57
protected:
58
virtual void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread,
59
ThreadIdType threadId) ITK_OVERRIDE;
60
};
61
```
62
63
### BinaryFunctorImageFilter
64
65
Base class for two-input pixel-wise operations.
66
67
```cpp { .api }
68
template<typename TInputImage1, typename TInputImage2, typename TOutputImage, typename TFunction>
69
class BinaryFunctorImageFilter : public ImageToImageFilter<TInputImage1, TOutputImage>
70
{
71
public:
72
typedef BinaryFunctorImageFilter Self;
73
typedef ImageToImageFilter<TInputImage1, TOutputImage> Superclass;
74
typedef SmartPointer<Self> Pointer;
75
typedef SmartPointer<const Self> ConstPointer;
76
77
// Second input handling
78
void SetInput1(const TInputImage1 * image);
79
void SetInput2(const TInputImage2 * image);
80
const TInputImage1 * GetInput1();
81
const TInputImage2 * GetInput2();
82
83
// Functor access
84
FunctionType & GetFunctor();
85
const FunctionType & GetFunctor() const;
86
void SetFunctor(const FunctionType & functor);
87
};
88
```
89
90
## Type Conversion Filters
91
92
### CastImageFilter
93
94
Casts input pixels to output pixel type for converting between different pixel types.
95
96
```cpp { .api }
97
template<typename TInputImage, typename TOutputImage>
98
class CastImageFilter : public InPlaceImageFilter<TInputImage, TOutputImage>
99
{
100
public:
101
typedef CastImageFilter Self;
102
typedef InPlaceImageFilter<TInputImage, TOutputImage> Superclass;
103
typedef SmartPointer<Self> Pointer;
104
typedef SmartPointer<const Self> ConstPointer;
105
106
// Creation
107
static Pointer New();
108
109
// Type definitions
110
typedef TInputImage InputImageType;
111
typedef TOutputImage OutputImageType;
112
typedef typename InputImageType::PixelType InputPixelType;
113
typedef typename OutputImageType::PixelType OutputPixelType;
114
};
115
```
116
117
### RescaleIntensityImageFilter
118
119
Applies a linear transformation to rescale intensity values to a desired output range.
120
121
```cpp { .api }
122
template<typename TInputImage, typename TOutputImage>
123
class RescaleIntensityImageFilter : public UnaryFunctorImageFilter<TInputImage, TOutputImage,
124
Functor::IntensityLinearTransform<
125
typename TInputImage::PixelType,
126
typename TOutputImage::PixelType>>
127
{
128
public:
129
typedef RescaleIntensityImageFilter Self;
130
typedef UnaryFunctorImageFilter<TInputImage, TOutputImage,
131
Functor::IntensityLinearTransform<
132
typename TInputImage::PixelType,
133
typename TOutputImage::PixelType>> Superclass;
134
typedef SmartPointer<Self> Pointer;
135
typedef SmartPointer<const Self> ConstPointer;
136
137
// Creation
138
static Pointer New();
139
140
// Type definitions
141
typedef typename TOutputImage::PixelType OutputPixelType;
142
typedef typename TInputImage::PixelType InputPixelType;
143
144
// Intensity range control
145
void SetOutputMinimum(OutputPixelType min);
146
void SetOutputMaximum(OutputPixelType max);
147
OutputPixelType GetOutputMinimum() const;
148
OutputPixelType GetOutputMaximum() const;
149
150
// Input range computation
151
InputPixelType GetInputMinimum() const;
152
InputPixelType GetInputMaximum() const;
153
void SetInputMinimum(InputPixelType min);
154
void SetInputMaximum(InputPixelType max);
155
156
// Scale and shift access
157
double GetScale() const;
158
double GetShift() const;
159
};
160
```
161
162
## Smoothing Filters
163
164
### DiscreteGaussianImageFilter
165
166
Gaussian smoothing with discrete kernel approximation.
167
168
```cpp { .api }
169
template<typename TInputImage, typename TOutputImage>
170
class DiscreteGaussianImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
171
{
172
public:
173
typedef DiscreteGaussianImageFilter Self;
174
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
175
typedef SmartPointer<Self> Pointer;
176
typedef SmartPointer<const Self> ConstPointer;
177
178
static Pointer New();
179
180
// Variance control
181
void SetVariance(const ArrayType & variance);
182
void SetVariance(const double variance);
183
void SetVariance(const double* variance);
184
itkGetConstMacro(Variance, ArrayType);
185
186
// Maximum error control
187
void SetMaximumError(const ArrayType & error);
188
void SetMaximumError(const double error);
189
void SetMaximumError(const double* error);
190
itkGetConstMacro(MaximumError, ArrayType);
191
192
// Kernel size limits
193
void SetMaximumKernelWidth(unsigned int n);
194
itkGetConstMacro(MaximumKernelWidth, unsigned int);
195
196
// Boundary handling
197
void SetUseImageSpacingOn();
198
void SetUseImageSpacingOff();
199
itkGetConstMacro(UseImageSpacing, bool);
200
};
201
```
202
203
### SmoothingRecursiveGaussianImageFilter
204
205
Recursive Gaussian smoothing for efficient large-kernel operations.
206
207
```cpp { .api }
208
template<typename TInputImage, typename TOutputImage>
209
class SmoothingRecursiveGaussianImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
210
{
211
public:
212
typedef SmoothingRecursiveGaussianImageFilter Self;
213
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
214
typedef SmartPointer<Self> Pointer;
215
typedef SmartPointer<const Self> ConstPointer;
216
217
static Pointer New();
218
219
// Sigma control (standard deviation)
220
void SetSigma(ScalarRealType sigma);
221
ScalarRealType GetSigma() const;
222
223
void SetSigmaArray(const SigmaArrayType & sigmas);
224
SigmaArrayType GetSigmaArray() const;
225
226
// Normalization control
227
void SetNormalizeAcrossScale(bool normalizeInScaleSpace);
228
itkGetConstMacro(NormalizeAcrossScale, bool);
229
};
230
```
231
232
### BilateralImageFilter
233
234
Edge-preserving bilateral smoothing.
235
236
```cpp { .api }
237
template<typename TInputImage, typename TOutputImage>
238
class BilateralImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
239
{
240
public:
241
typedef BilateralImageFilter Self;
242
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
243
typedef SmartPointer<Self> Pointer;
244
typedef SmartPointer<const Self> ConstPointer;
245
246
static Pointer New();
247
248
// Filter parameters
249
void SetDomainSigma(const double domainSigma);
250
itkGetConstMacro(DomainSigma, double);
251
252
void SetRangeSigma(const double rangeSigma);
253
itkGetConstMacro(RangeSigma, double);
254
255
// Automatic parameter selection
256
void SetAutomaticKernelSize(bool automaticKernelSize);
257
itkGetConstMacro(AutomaticKernelSize, bool);
258
259
// Manual kernel size
260
void SetRadius(const RadiusType & radius);
261
itkGetConstMacro(Radius, RadiusType);
262
};
263
```
264
265
## Thresholding Filters
266
267
### BinaryThresholdImageFilter
268
269
Binary segmentation based on intensity thresholds.
270
271
```cpp { .api }
272
template<typename TInputImage, typename TOutputImage>
273
class BinaryThresholdImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
274
{
275
public:
276
typedef BinaryThresholdImageFilter Self;
277
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
278
typedef SmartPointer<Self> Pointer;
279
typedef SmartPointer<const Self> ConstPointer;
280
281
static Pointer New();
282
283
// Threshold values
284
void SetLowerThreshold(const InputPixelType & threshold);
285
void SetUpperThreshold(const InputPixelType & threshold);
286
itkGetConstMacro(LowerThreshold, InputPixelType);
287
itkGetConstMacro(UpperThreshold, InputPixelType);
288
289
// Output values
290
void SetOutsideValue(const OutputPixelType & value);
291
void SetInsideValue(const OutputPixelType & value);
292
itkGetConstMacro(OutsideValue, OutputPixelType);
293
itkGetConstMacro(InsideValue, OutputPixelType);
294
};
295
```
296
297
### OtsuThresholdImageFilter
298
299
Automatic threshold selection using Otsu's method.
300
301
```cpp { .api }
302
template<typename TInputImage, typename TOutputImage>
303
class OtsuThresholdImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
304
{
305
public:
306
typedef OtsuThresholdImageFilter Self;
307
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
308
typedef SmartPointer<Self> Pointer;
309
typedef SmartPointer<const Self> ConstPointer;
310
311
static Pointer New();
312
313
// Computed threshold
314
itkGetConstMacro(Threshold, InputPixelType);
315
316
// Output values
317
void SetOutsideValue(const OutputPixelType & value);
318
void SetInsideValue(const OutputPixelType & value);
319
itkGetConstMacro(OutsideValue, OutputPixelType);
320
itkGetConstMacro(InsideValue, OutputPixelType);
321
322
// Histogram parameters
323
void SetNumberOfHistogramBins(SizeValueType numberOfBins);
324
itkGetConstMacro(NumberOfHistogramBins, SizeValueType);
325
};
326
```
327
328
## Mathematical Morphology
329
330
### BinaryErodeImageFilter
331
332
Binary erosion operation.
333
334
```cpp { .api }
335
template<typename TInputImage, typename TOutputImage, typename TKernel>
336
class BinaryErodeImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
337
{
338
public:
339
typedef BinaryErodeImageFilter Self;
340
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
341
typedef SmartPointer<Self> Pointer;
342
typedef SmartPointer<const Self> ConstPointer;
343
344
static Pointer New();
345
346
// Structuring element
347
void SetKernel(const KernelType & kernel);
348
itkGetConstReferenceMacro(Kernel, KernelType);
349
350
// Foreground/background values
351
void SetForegroundValue(const InputPixelType & value);
352
void SetBackgroundValue(const InputPixelType & value);
353
itkGetConstMacro(ForegroundValue, InputPixelType);
354
itkGetConstMacro(BackgroundValue, InputPixelType);
355
356
// Boundary handling
357
void SetBoundaryToForeground(bool boundaryToForeground);
358
itkGetConstMacro(BoundaryToForeground, bool);
359
};
360
```
361
362
### BinaryDilateImageFilter
363
364
Binary dilation operation.
365
366
```cpp { .api }
367
template<typename TInputImage, typename TOutputImage, typename TKernel>
368
class BinaryDilateImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
369
{
370
public:
371
typedef BinaryDilateImageFilter Self;
372
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
373
typedef SmartPointer<Self> Pointer;
374
typedef SmartPointer<const Self> ConstPointer;
375
376
static Pointer New();
377
378
// Structuring element
379
void SetKernel(const KernelType & kernel);
380
itkGetConstReferenceMacro(Kernel, KernelType);
381
382
// Foreground/background values
383
void SetForegroundValue(const InputPixelType & value);
384
void SetBackgroundValue(const InputPixelType & value);
385
itkGetConstMacro(ForegroundValue, InputPixelType);
386
itkGetConstMacro(BackgroundValue, InputPixelType);
387
};
388
```
389
390
### GrayscaleErodeImageFilter
391
392
Grayscale erosion operation.
393
394
```cpp { .api }
395
template<typename TInputImage, typename TOutputImage, typename TKernel>
396
class GrayscaleErodeImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
397
{
398
public:
399
typedef GrayscaleErodeImageFilter Self;
400
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
401
typedef SmartPointer<Self> Pointer;
402
typedef SmartPointer<const Self> ConstPointer;
403
404
static Pointer New();
405
406
// Structuring element
407
void SetKernel(const KernelType & kernel);
408
itkGetConstReferenceMacro(Kernel, KernelType);
409
410
// Algorithm selection
411
void SetAlgorithm(AlgorithmType algorithm);
412
itkGetConstMacro(Algorithm, AlgorithmType);
413
};
414
```
415
416
## Edge Detection
417
418
### CannyEdgeDetectionImageFilter
419
420
Canny edge detection with hysteresis thresholding.
421
422
```cpp { .api }
423
template<typename TInputImage, typename TOutputImage>
424
class CannyEdgeDetectionImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
425
{
426
public:
427
typedef CannyEdgeDetectionImageFilter Self;
428
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
429
typedef SmartPointer<Self> Pointer;
430
typedef SmartPointer<const Self> ConstPointer;
431
432
static Pointer New();
433
434
// Gaussian parameters
435
void SetVariance(const ArrayType & variance);
436
void SetVariance(const double variance);
437
itkGetConstMacro(Variance, ArrayType);
438
439
void SetMaximumError(const ArrayType & maximumError);
440
void SetMaximumError(const double maximumError);
441
itkGetConstMacro(MaximumError, ArrayType);
442
443
// Threshold parameters
444
void SetUpperThreshold(const OutputImagePixelType upperThreshold);
445
void SetLowerThreshold(const OutputImagePixelType lowerThreshold);
446
itkGetConstMacro(UpperThreshold, OutputImagePixelType);
447
itkGetConstMacro(LowerThreshold, OutputImagePixelType);
448
};
449
```
450
451
### LaplacianImageFilter
452
453
Laplacian edge enhancement.
454
455
```cpp { .api }
456
template<typename TInputImage, typename TOutputImage>
457
class LaplacianImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
458
{
459
public:
460
typedef LaplacianImageFilter Self;
461
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
462
typedef SmartPointer<Self> Pointer;
463
typedef SmartPointer<const Self> ConstPointer;
464
465
static Pointer New();
466
467
// Scaling control
468
void SetUseImageSpacingOn();
469
void SetUseImageSpacingOff();
470
itkGetConstMacro(UseImageSpacing, bool);
471
};
472
```
473
474
## Gradient Computation
475
476
### GradientMagnitudeImageFilter
477
478
Computes gradient magnitude of an image.
479
480
```cpp { .api }
481
template<typename TInputImage, typename TOutputImage>
482
class GradientMagnitudeImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
483
{
484
public:
485
typedef GradientMagnitudeImageFilter Self;
486
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
487
typedef SmartPointer<Self> Pointer;
488
typedef SmartPointer<const Self> ConstPointer;
489
490
static Pointer New();
491
492
// Spacing consideration
493
void SetUseImageSpacingOn();
494
void SetUseImageSpacingOff();
495
itkGetConstMacro(UseImageSpacing, bool);
496
};
497
```
498
499
### GradientImageFilter
500
501
Computes gradient vector field of an image.
502
503
```cpp { .api }
504
template<typename TInputImage, typename TOperatorValueType, typename TOutputValueType>
505
class GradientImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
506
{
507
public:
508
typedef GradientImageFilter Self;
509
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
510
typedef SmartPointer<Self> Pointer;
511
typedef SmartPointer<const Self> ConstPointer;
512
513
static Pointer New();
514
515
// Spacing consideration
516
void SetUseImageSpacingOn();
517
void SetUseImageSpacingOff();
518
itkGetConstMacro(UseImageSpacing, bool);
519
520
// Direction control
521
void SetUseImageDirection(bool useImageDirection);
522
itkGetConstMacro(UseImageDirection, bool);
523
};
524
```
525
526
## Resampling and Geometric Transforms
527
528
### ResampleImageFilter
529
530
Resamples an image using arbitrary geometric transforms.
531
532
```cpp { .api }
533
template<typename TInputImage, typename TOutputImage, typename TInterpolatorPrecisionType>
534
class ResampleImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
535
{
536
public:
537
typedef ResampleImageFilter Self;
538
typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
539
typedef SmartPointer<Self> Pointer;
540
typedef SmartPointer<const Self> ConstPointer;
541
542
static Pointer New();
543
544
// Transform specification
545
void SetTransform(const TransformType * transform);
546
itkGetConstObjectMacro(Transform, TransformType);
547
548
// Interpolator specification
549
void SetInterpolator(InterpolatorType * interpolator);
550
itkGetConstObjectMacro(Interpolator, InterpolatorType);
551
552
// Output image geometry
553
void SetSize(const SizeType & size);
554
itkGetConstReferenceMacro(Size, SizeType);
555
556
void SetOutputOrigin(const OriginPointType & origin);
557
itkGetConstReferenceMacro(OutputOrigin, OriginPointType);
558
559
void SetOutputSpacing(const SpacingType & spacing);
560
itkGetConstReferenceMacro(OutputSpacing, SpacingType);
561
562
void SetOutputDirection(const DirectionType & direction);
563
itkGetConstReferenceMacro(OutputDirection, DirectionType);
564
565
// Default pixel value
566
void SetDefaultPixelValue(const PixelType & pixel);
567
itkGetConstReferenceMacro(DefaultPixelValue, PixelType);
568
};
569
```
570
571
## Noise Reduction
572
573
### CurvatureFlowImageFilter
574
575
Anisotropic diffusion for noise reduction.
576
577
```cpp { .api }
578
template<typename TInputImage, typename TOutputImage>
579
class CurvatureFlowImageFilter : public FiniteDifferenceImageFilter<TInputImage, TOutputImage>
580
{
581
public:
582
typedef CurvatureFlowImageFilter Self;
583
typedef FiniteDifferenceImageFilter<TInputImage, TOutputImage> Superclass;
584
typedef SmartPointer<Self> Pointer;
585
typedef SmartPointer<const Self> ConstPointer;
586
587
static Pointer New();
588
589
// Time step control
590
void SetTimeStep(const TimeStepType & timeStep);
591
itkGetConstMacro(TimeStep, TimeStepType);
592
593
// Iteration control
594
void SetNumberOfIterations(unsigned int numberOfIterations);
595
itkGetConstMacro(NumberOfIterations, unsigned int);
596
};
597
```
598
599
### AnisotropicDiffusionImageFilter
600
601
Base class for anisotropic diffusion filters.
602
603
```cpp { .api }
604
template<typename TInputImage, typename TOutputImage>
605
class AnisotropicDiffusionImageFilter : public FiniteDifferenceImageFilter<TInputImage, TOutputImage>
606
{
607
public:
608
typedef AnisotropicDiffusionImageFilter Self;
609
typedef FiniteDifferenceImageFilter<TInputImage, TOutputImage> Superclass;
610
typedef SmartPointer<Self> Pointer;
611
typedef SmartPointer<const Self> ConstPointer;
612
613
// Conductance parameter
614
void SetConductanceParameter(double conductance);
615
itkGetConstMacro(ConductanceParameter, double);
616
617
// Time step
618
void SetTimeStep(const TimeStepType & timeStep);
619
itkGetConstMacro(TimeStep, TimeStepType);
620
621
// Iterations
622
void SetNumberOfIterations(unsigned int numberOfIterations);
623
itkGetConstMacro(NumberOfIterations, unsigned int);
624
};
625
```
626
627
## Type Definitions
628
629
```cpp { .api }
630
// Common filter instantiations
631
typedef BinaryThresholdImageFilter<Image<short,2>, Image<unsigned char,2>> BinaryThreshold2DFilter;
632
typedef BinaryThresholdImageFilter<Image<short,3>, Image<unsigned char,3>> BinaryThreshold3DFilter;
633
634
typedef DiscreteGaussianImageFilter<Image<float,2>, Image<float,2>> GaussianFilter2D;
635
typedef DiscreteGaussianImageFilter<Image<float,3>, Image<float,3>> GaussianFilter3D;
636
637
typedef GradientMagnitudeImageFilter<Image<float,2>, Image<float,2>> GradientMagnitude2D;
638
typedef GradientMagnitudeImageFilter<Image<float,3>, Image<float,3>> GradientMagnitude3D;
639
640
// Array types for multi-dimensional parameters
641
typedef FixedArray<double, 2> Array2D;
642
typedef FixedArray<double, 3> Array3D;
643
typedef FixedArray<unsigned int, 2> UIntArray2D;
644
typedef FixedArray<unsigned int, 3> UIntArray3D;
645
646
// Kernel types for morphological operations
647
typedef BinaryBallStructuringElement<PixelType, 2> Ball2D;
648
typedef BinaryBallStructuringElement<PixelType, 3> Ball3D;
649
typedef BinaryCrossStructuringElement<PixelType, 2> Cross2D;
650
typedef BinaryCrossStructuringElement<PixelType, 3> Cross3D;
651
```
652
653
ITK's image processing framework provides a comprehensive suite of filters for medical image analysis, from basic pixel operations to advanced feature detection and noise reduction algorithms.