-
Notifications
You must be signed in to change notification settings - Fork 20
/
itkBlockMatchingMultiResolutionSimilarityFunctionSearchRegionImageSource.h
308 lines (257 loc) · 11 KB
/
itkBlockMatchingMultiResolutionSimilarityFunctionSearchRegionImageSource.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
/*=========================================================================
*
* 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.
*
*=========================================================================*/
#ifndef itkBlockMatchingMultiResolutionSimilarityFunctionSearchRegionImageSource_h
#define itkBlockMatchingMultiResolutionSimilarityFunctionSearchRegionImageSource_h
#include "itkArray.h"
#include "itkInterpolateImageFunction.h"
#include "itkVector.h"
#include "itkBlockMatchingMultiResolutionSearchRegionImageSource.h"
#include "itkBlockMatchingMetricImageToDisplacementCalculator.h"
#include "itkResampleImageFilter.h"
namespace itk
{
namespace BlockMatching
{
/** \class MultiResolutionSimilarityFunctionSearchRegionImageSource
*
* \brief The search region at subsequent levels is a function of the similarity
* metric at the displacement.
*
* This is a SearchRegionImageSource that defines the search region size
* dynamically according the metric image performance at higher levels. The
* search region given the metric images at the current level is determined by
* the value of the similarity at the determined displacement.
* This size is interpolated is interpolated at the following levels.
*
* In order to examine the metric image values, this class also inherits from
* MetricImageToDisplacementCalculator.
*
* A second displacment calculator is used to
* calculate the displacement from similarity metric images. This can be set with
* SetDisplacementCalculator(), and it defaults to
* MaximumPixelDisplacementCalculator.
*
* The specified functor is defined with SetFunctor() and it should evaluate to
* 1.0 to keep the search region the same size at the next level or less than
* one to decrease the size at the next level. Candidate functions are
* available in the itk::Function:: namespace.
*
* @todo more with this. top level / 2 ?
* The search region radius will be truncated to the top level radius after
* evaluation with the functor.
*
* \ingroup Ultrasound
* */
template <class TFixedImage,
class TMovingImage,
class TMetricImage,
class TDisplacementImage,
class TFunctor,
class TInterpolatorPrecisionType = double>
class ITK_TEMPLATE_EXPORT MultiResolutionSimilarityFunctionSearchRegionImageSource
: public MultiResolutionSearchRegionImageSource<TFixedImage, TMovingImage, TDisplacementImage>
, public MetricImageToDisplacementCalculator<TMetricImage, TDisplacementImage>
{
public:
/** Standard class type alias. */
using Self = MultiResolutionSimilarityFunctionSearchRegionImageSource;
using Superclass = MultiResolutionSearchRegionImageSource<TFixedImage, TMovingImage, TDisplacementImage>;
using DisplacementCalculatorSuperclass = MetricImageToDisplacementCalculator<TMetricImage, TDisplacementImage>;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
/** ImageDimension enumeration. */
itkStaticConstMacro(ImageDimension, unsigned int, TMovingImage::ImageDimension);
/** Type of the fixed image. */
using FixedImageType = TFixedImage;
using FixedRegionType = typename FixedImageType::RegionType;
/** Type of the radius used to characterized the fixed image block. */
using RadiusType = typename FixedImageType::SizeType;
/** Type of the moving image. */
using MovingImageType = TMovingImage;
using MovingRegionType = typename MovingImageType::RegionType;
/** Type of the metric image. */
using MetricImageType = TMetricImage;
/** Type of the image of metric images. */
using MetricImageImageType = typename DisplacementCalculatorSuperclass::MetricImageImageType;
using CenterPointsImageType = typename DisplacementCalculatorSuperclass::CenterPointsImageType;
/** Interpolator type alias. */
using InterpolatorType = InterpolateImageFunction<MetricImageType, TInterpolatorPrecisionType>;
using InterpolatorPointerType = typename InterpolatorType::Pointer;
/** Type of the search region image. */
using OutputImageType = typename Superclass::OutputImageType;
using OutputRegionType = typename OutputImageType::RegionType;
using SearchRegionRadiusImageType =
Image<typename itk::Vector<typename RadiusType::SizeValueType, ImageDimension>, ImageDimension>;
using SearchRegionRadiusImagePointer = typename SearchRegionRadiusImageType::Pointer;
using SearchRegionRadiusResamplerType = ResampleImageFilter<SearchRegionRadiusImageType, SearchRegionRadiusImageType>;
/** ScheduleType type alias support. */
using PyramidScheduleType = typename Superclass::PyramidScheduleType;
/** OverlapScheduleType type alias support. */
using OverlapScheduleType = typename Superclass::OverlapScheduleType;
/** Type of the displacement image from the previous level. */
using DisplacementImageType = TDisplacementImage;
/** Type of the function object used to calculate the search region size. */
using FunctorType = TFunctor;
/** Type of the filter used to resample the deformations. */
using DisplacementResamplerType = typename Superclass::DisplacementResamplerType;
using DisplacementResamplerPointer = typename DisplacementResamplerType::Pointer;
/** Types inherited from the DisplacementCalculator superclass. */
using PointType = typename DisplacementCalculatorSuperclass::PointType;
using IndexType = typename DisplacementCalculatorSuperclass::IndexType;
/** Type of the minimum search region radius factor. */
using RadiusFactorType = FixedArray<double, ImageDimension>;
/** Run-time type information (and related methods). */
itkTypeMacro(MultiResolutionSimilarityFunctionSearchRegionImageSource, MultiResolutionFixedSearchRegionImageSource);
/** New macro for creation of through a Smart Pointer is not used because of
* ambiguities with LightObject. */
static Pointer
New(void)
{
Pointer smartPtr = ObjectFactory<Self>::Create();
if (smartPtr.GetPointer() == nullptr)
{
smartPtr = new Self;
}
smartPtr->UnRegister();
return smartPtr;
}
// virtual LightObject::Pointer CreateAnother(void) const
// {
// LightObject::Pointer smartPtr;
// // @todo fix me -- itk::LightObject ambiguity somewhere in the following
// line
// smartPtr = Self::New().GetPointer();
// return smartPtr;
// }
/** Set/Get the search region radius at the top, highest level ( level 0 ). */
virtual void
SetTopLevelRadius(const RadiusType & radius)
{
m_TopLevelRadius = radius;
m_TopLevelRadiusSpecified = true;
this->Modified();
}
/** Set/Get the minimum search region radius factor. This is multiplied by
* the fixed block size to obtain the minimum search region radius. */
virtual void
SetMinimumSearchRegionRadiusFactor(const RadiusFactorType & factor)
{
m_MinimumSearchRegionRadiusFactor = factor;
this->Modified();
}
virtual void
SetMinimumSearchRegionRadiusFactor(const double & factor)
{
RadiusFactorType rf(factor);
this->SetMinimumSearchRegionRadiusFactor(rf);
}
itkGetConstReferenceMacro(MinimumSearchRegionRadiusFactor, RadiusFactorType);
/** We allocate the previous search region image. */
virtual void
SetDisplacementImage(DisplacementImageType * image);
/** Calculates the search region radius based on the metric image. */
virtual void
SetMetricImagePixel(const PointType & point, const IndexType & index, MetricImageType * image);
virtual void
Compute();
/** This is needed to avoid resolution ambiguities that occur with multiple
* inheritance. */
virtual void
Register() const
{
Superclass::Register();
}
virtual void
UnRegister() const
{
Superclass::UnRegister();
}
virtual void
Modified() const
{
Superclass::Modified();
}
bool
GetDebug() const
{
return Superclass::GetDebug();
}
/** Set/Get the internal displacement calculator that is used to calculate the
* displacements after regularization. Defaults to a
* MaximumPixelDisplacementCalcultor. */
itkSetObjectMacro(DisplacementCalculator, DisplacementCalculatorSuperclass);
itkGetConstObjectMacro(DisplacementCalculator, DisplacementCalculatorSuperclass);
/** Set the interpolator function. The default is
* itk::LinearInterpolateImageFunction<InputImageType, TInterpolatorPrecisionType>. Some
* other options are itk::NearestNeighborInterpolateImageFunction
* (useful for binary masks and other images with a small number of
* possible pixel values), and itk::BSplineInterpolateImageFunction
* (which provides a higher order of interpolation). */
itkSetObjectMacro(Interpolator, InterpolatorType);
/** Get a pointer to the interpolator function. */
itkGetConstObjectMacro(Interpolator, InterpolatorType);
/** Get the functor object. The functor is returned by reference.
* (Functors do not have to derive from itk::LightObject, so they do
* not necessarily have a reference count. So we cannot return a
* SmartPointer.) */
const FunctorType &
GetFunctor() const
{
return m_Functor;
}
/** Set the functor object. This replaces the current Functor with a
* copy of the specified Functor. This allows the user to specify a
* functor that has ivars set differently than the default functor.
* This method requires an operator!=() be defined on the functor
* (or the compiler's default implementation of operator!=() being
* appropriate). */
void
SetFunctor(const FunctorType & functor)
{
if (m_Functor != functor)
{
m_Functor = functor;
this->Modified();
}
}
protected:
MultiResolutionSimilarityFunctionSearchRegionImageSource();
virtual void
BeforeThreadedGenerateData() override;
virtual void
ThreadedGenerateData(const OutputRegionType & outputRegion, ThreadIdType threadID);
RadiusType m_TopLevelRadius;
bool m_TopLevelRadiusSpecified;
RadiusFactorType m_MinimumSearchRegionRadiusFactor;
typename SearchRegionRadiusImageType::Pointer m_SearchRegionRadiusImage;
typename SearchRegionRadiusResamplerType::Pointer m_SearchRegionRadiusResampler;
typename DisplacementCalculatorSuperclass::Pointer m_DisplacementCalculator;
InterpolatorPointerType m_Interpolator; // Image function for
// metric interpolation
FunctorType m_Functor;
private:
MultiResolutionSimilarityFunctionSearchRegionImageSource(const Self &);
void
operator=(const Self &);
};
} // end namespace BlockMatching
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
# include "itkBlockMatchingMultiResolutionSimilarityFunctionSearchRegionImageSource.hxx"
#endif
#endif