-
-
Notifications
You must be signed in to change notification settings - Fork 658
/
itkImageToImageFilter.h
382 lines (348 loc) · 16.7 KB
/
itkImageToImageFilter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
/*=========================================================================
*
* Portions of this file are subject to the VTK Toolkit Version 3 copyright.
*
* Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
*
* For complete copyright, license and disclaimer of warranty information
* please refer to the NOTICE file at the top of the ITK source tree.
*
*=========================================================================*/
#ifndef itkImageToImageFilter_h
#define itkImageToImageFilter_h
#include "itkImageSource.h"
#include "itkConceptChecking.h"
#include "itkImageToImageFilterDetail.h"
#include "itkImageToImageFilterCommon.h"
namespace itk
{
/** \class ImageToImageFilter
* \brief Base class for filters that take an image as input and produce an image as output.
*
* ImageToImageFilter is the base class for all process objects that output
* image data and require image data as input. Specifically, this class
* defines the SetInput() method for defining the input to a filter.
*
* This class provides the infrastructure for supporting multithreaded
* processing of images. If a filter provides an implementation of
* GenerateData(), the image processing will run in a single thread and the
* implementation is responsible for allocating its output data. If a filter
* provides an implementation of ThreadedGenerateData() instead, the image
* will be divided into a number of work units, a number of threads will be
* spawned, and ThreadedGenerateData() will be called in each thread. Here,
* the output memory will be allocated by this superclass prior to calling
* ThreadedGenerateData().
*
* ImageToImageFilter provides an implementation of
* GenerateInputRequestedRegion(). The base assumption to this point in the
* hierarchy is that a process object would ask for the largest possible
* region on input in order to produce any output. Imaging filters,
* however, can usually answer this question more precisely. The default
* implementation of GenerateInputRequestedRegion() in this class is to
* request an input that matches the size of the requested output. If a
* filter requires more input (say a filter that uses neighborhood
* information) or less input (for instance a magnify filter), then these
* filters will have to provide another implementation of this method. By
* convention, such implementations should call the Superclass' method
* first.
*
* All inputs to ImageToImageFilter (if there is more than one) are
* checked in the VerifyInputInformation() method to verify that they
* occupy the same physical space. If the input images are in the
* same physical space, then the location of each voxel is identical,
* and the filter can operate voxel-by-voxel in index space. Some
* filters -- registration filters, for example -- will violate this
* precondition, in which case they should redefine
* VerifyInputInformation() to relax or eliminate this requirement.
*
* Access methods -- Set/GetCoordinateTolerance and
* Set/GetDirectionTolerance -- are provided for cases where the
* default spatial-congruency tolerances are too fine, and images that
* are almost in the same space should be regard as being in the same
* space. This has come up, for example when comparing different
* on-disk image formats with differing digits of precision in the
* position, spacing, and orientation.
*
* The default tolerance is govern by the
* GlobalDefaultCoordinateTolerance and the
* GlobalDefaultDirectionTolerance properties, defaulting to 1.0e-6.
* The default tolerance for spatial comparison is then scaled by the
* voxelSpacing for coordinates (i.e. the coordinates must be the same
* to within one part per million). For the direction cosines the
* values must be within the current absolute tolerance.
*
* \ingroup ImageFilters
* \ingroup ITKCommon
*
* \sphinx
* \sphinxexample{Core/Common/FilterImage,Filter Image}
* \sphinxexample{Core/Common/MultipleInputsOfSameType,Multiple Inputs Of Same Type}
* \sphinxexample{Core/Common/MultipleInputsOfDifferentType,Multiple Inputs Of Different Type}
* \sphinxexample{Core/Common/MultipleOutputsOfSameType,Multiple Outputs Of Same Type}
* \sphinxexample{Core/Common/MultiThreadOilPainting,Multi-thread Oil Painting}
* \sphinxexample{Core/Common/MultipleOutputsOfDifferentType,Multiple Outputs Of Different Type}
* \sphinxexample{Core/Common/FilterImageUsingMultipleThreads,Filter Image Using Multiple Threads}
* \endsphinx
*/
template <typename TInputImage, typename TOutputImage>
class ITK_TEMPLATE_EXPORT ImageToImageFilter
: public ImageSource<TOutputImage>
, private ImageToImageFilterCommon
{
public:
ITK_DISALLOW_COPY_AND_MOVE(ImageToImageFilter);
/** Standard class type aliases. */
using Self = ImageToImageFilter;
using Superclass = ImageSource<TOutputImage>;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
/** \see LightObject::GetNameOfClass() */
itkOverrideGetNameOfClassMacro(ImageToImageFilter);
/** Superclass type alias. */
using typename Superclass::OutputImageRegionType;
using typename Superclass::OutputImagePixelType;
/** Some convenient type alias. */
using InputImageType = TInputImage;
using InputImagePointer = typename InputImageType::Pointer;
using InputImageConstPointer = typename InputImageType::ConstPointer;
using InputImageRegionType = typename InputImageType::RegionType;
using InputImagePixelType = typename InputImageType::PixelType;
/** ImageDimension constants */
static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
static constexpr unsigned int OutputImageDimension = TOutputImage::ImageDimension;
/** Set/Get the image input of this process object. */
using Superclass::SetInput;
virtual void
SetInput(const InputImageType * input);
virtual void
SetInput(unsigned int, const TInputImage * image);
const InputImageType *
GetInput() const;
const InputImageType *
GetInput(unsigned int idx) const;
/** Push/Pop the input of this process object. These methods allow a
* filter to model its input vector as a queue or stack. These
* routines may not be appropriate for all filters, especially
* filters with different types of inputs. These routines follow
* the semantics of STL.
*
* The routines are useful for applications that need to process
* "rolling" sets of images. For instance, if an application has 10
* images and they need to run a filter on images 1, 2, 3, 4, then
* run the filter on images 2, 3, 4, 5, then run the filter on
* images 3, 4, 5, 6, the application can accomplish this by popping
* an input off the front of the input list and push a new image
* onto the back of input list. Again, this only makes sense for
* filters that single type of input.
*
* Other uses are also possible. For a single input filter, pushing
* and popping inputs allow the application to temporarily replace
* an input to a filter.
*/
virtual void
PushBackInput(const InputImageType * input);
void
PopBackInput() override;
virtual void
PushFrontInput(const InputImageType * input);
void
PopFrontInput() override;
/** get/set the Coordinate tolerance
* This tolerance is used when comparing the space defined
* by the input images. ITK has a requirement that multiple input
* images be congruent in space by default.
*/
itkSetMacro(CoordinateTolerance, double);
itkGetConstMacro(CoordinateTolerance, double);
/** get/set the direction tolerance
* This tolerance is used to make sure that all input
* images are oriented the same before performing the filter's
* transformations.
*/
itkSetMacro(DirectionTolerance, double);
itkGetConstMacro(DirectionTolerance, double);
/** get/set the global default direction tolerance
*
* This value is used to initialize the DirectionTolerance upon
* class construction of \b any ImageToImage filter. This has no
* effect on currently constructed classes.
*/
using ImageToImageFilterCommon::SetGlobalDefaultDirectionTolerance;
using ImageToImageFilterCommon::GetGlobalDefaultDirectionTolerance;
/** get/set the global default coordinate tolerance
*
* This value is used to initialize the CoordinateTolerance upon
* class construction of \b any ImageToImage filter. This has no
* effect on currently constructed classes.
*/
using ImageToImageFilterCommon::SetGlobalDefaultCoordinateTolerance;
using ImageToImageFilterCommon::GetGlobalDefaultCoordinateTolerance;
protected:
ImageToImageFilter();
~ImageToImageFilter() override = default;
void
PrintSelf(std::ostream & os, Indent indent) const override;
/** \brief Verifies that the input images occupy the same physical
* space and the each index is at the same physical location.
*
* The default implementation of the PropagateRequestedRegion()
* methods copies the index and size from the output to the
* input. This makes an implicit assumption that the images occupy
* the same physical location at each voxel. This method enforces
* that they are the same.
*
* This implementation verifies that all input images of
* InputImageDimensions have the same origin, spacing and direction.
*
* Filters which do not expect all input images to be at the same
* physical location should over-ride this method. Also filters
* whose inputs are different dimensions may need to override this
* method.
*
* \sa ProcessObject::VerifyInputInformation
*/
void
VerifyInputInformation() ITKv5_CONST override;
/** What is the input requested region that is required to produce
* the output requested region? The base assumption for image
* processing filters is that the input requested region can be set
* to match the output requested region. If a filter requires more
* input (for instance a filter that uses neighborhoods needs more
* input than output to avoid introducing artificial boundary
* conditions) or less input (for instance a magnify filter) will
* have to override this method. In doing so, it should call its
* superclass' implementation as its first step. Note that imaging
* filters operate differently than the classes to this point in the
* class hierarchy. Up till now, the base assumption has been that
* the largest possible region will be requested of the input.
*
* This implementation of GenerateInputRequestedRegion() only
* processes the inputs that are a subclass of the
* ImageBase<InputImageDimension>. If an input is another type of
* DataObject (including an Image of a different dimension), they
* are skipped by this method. The subclasses of ImageToImageFilter
* are responsible for providing an implementation of
* GenerateInputRequestedRegion() when there are multiple inputs of
* different types.
*
* \sa ProcessObject::GenerateInputRequestedRegion(),
* ImageSource::GenerateInputRequestedRegion() */
void
GenerateInputRequestedRegion() override;
/** Typedef for the region copier function object that converts an
* input region to an output region. */
using InputToOutputRegionCopierType =
ImageToImageFilterDetail::ImageRegionCopier<Self::OutputImageDimension, Self::InputImageDimension>;
/** Typedef for the region copier function object that converts an
* output region to an input region. */
using OutputToInputRegionCopierType =
ImageToImageFilterDetail::ImageRegionCopier<Self::InputImageDimension, Self::OutputImageDimension>;
/** This function calls the actual region copier to do the mapping
* from output image space to input image space. It uses a Function
* object used for dispatching to various routines to copy an output
* region (start index and size) to an input region. For most
* filters, this is a trivial copy because most filters require the
* input dimension to match the output dimension. However, some
* filters like itk::ExtractImageFilter can support output images of
* a lower dimension that the input.
*
* This function object can be used by GenerateOutputInformation()
* to copy the input LargestPossibleRegion to the output
* LargestPossibleRegion and can also be used in GenerateData or
* ThreadedGenerateData() where a filter may need to map an
* output region to an input region.
*
* The default copier uses a "dispatch pattern" to call one of three
* overloaded functions depending on whether the input and output
* images are the same dimension, the input is a higher dimension
* that the output, or the input is of a lower dimension than the
* output. The use of an overloaded function is required for proper
* compilation of the various cases.
*
* For the latter two cases, trivial implementations are used. If
* the input image is a higher dimension than the output, the output
* region information is copied into the first portion of the input
* region and the rest of the input region is set to zero. If the
* input region is a lower dimension than the output, the first
* portion of the output region is copied to the input region.
*
* If a filter needs a different default behavior, it can override
* this method. The ExtractImageFilter overrides this function
* object so that if the input image is a higher dimension than the
* output image, the filter can control "where" in the input image
* the output subimage is extracted (as opposed to mapping to first
* few dimensions of the input). */
virtual void
CallCopyOutputRegionToInputRegion(InputImageRegionType & destRegion, const OutputImageRegionType & srcRegion);
/** This function calls the actual region copier to do the mapping
* from input image space to output image space. It uses a Function
* object used for dispatching to various routines to copy an input
* region (start index and size) to an output region. For most
* filters, this is a trivial copy because most filters require the
* input dimension to match the output dimension. However, some
* filters like itk::UnaryFunctorImageFilter can support output
* images of a higher dimension that the input.
*
* This function object is used by the default implementation of
* GenerateOutputInformation(). It can also be used in routines
* like ThreadedGenerateData() where a filter may need to map an
* input region to an output region.
*
* The default copier uses a "dispatch pattern" to call one of three
* overloaded functions depending on whether the input and output
* images are the same dimension, the input is a higher dimension
* that the output, or the input is of a lower dimension than the
* output. The use of an overloaded function is required for proper
* compilation of the various cases.
*
* For the latter two cases, trivial implementations are used. If
* the input image is a higher dimension than the output, the first
* portion of the input region is copied to the output region. If
* the input region is a lower dimension than the output, the input
* region information is copied into the first portion of the output
* region and the rest of the output region is set to zero.
*
* If a filter needs a different default behavior, it can override
* this method. */
virtual void
CallCopyInputRegionToOutputRegion(OutputImageRegionType & destRegion, const InputImageRegionType & srcRegion);
/**
* PushBackInput(), PushFronInput() in the public section force the
* input to be the type expected by an ImageToImageFilter. However,
* these methods end of "hiding" the versions from the superclass
* (ProcessObject) whose arguments are DataObjects. Here, we re-expose
* the versions from ProcessObject to avoid warnings about hiding
* methods from the superclass.
*/
using Superclass::PushBackInput;
using Superclass::PushFrontInput;
private:
/**
* Tolerances for checking whether input images are defined to
* occupy the same physical space.
*/
double m_CoordinateTolerance{};
double m_DirectionTolerance{};
};
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
# include "itkImageToImageFilter.hxx"
#endif
#endif