-
Notifications
You must be signed in to change notification settings - Fork 20
/
itkBlockMatchingMetricImageToDisplacementCalculator.h
174 lines (146 loc) · 6.52 KB
/
itkBlockMatchingMetricImageToDisplacementCalculator.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
/*=========================================================================
*
* 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 itkBlockMatchingMetricImageToDisplacementCalculator_h
#define itkBlockMatchingMetricImageToDisplacementCalculator_h
#include "itkImage.h"
#include "itkImageDuplicator.h"
#include "itkMultiThreaderBase.h"
#include "itkProcessObject.h"
namespace itk
{
namespace BlockMatching
{
/** \class MetricImageToDisplacementCalculator
*
* \brief Calculates the displacement of a block from the MetricImage(s).
*
* This class tightly integrates with BlockMatching::ImageRegistrationMethod.
* It is the responsibility of this class to calculate the displacement given
* MetricImage(s) in a block matching registration method.
*
* This is an abstract class with a required, protected method:
* void Compute()
*
* This method should be overridden and the calculation performed here if the
* local displacment depends on more than the local MetricImage. Alternatively,
* if the local displacement depends only on the metric image,
* ComputePixel( index, MetricImage* ) should be overridden and Compute()
* set to do nothing.
*
* Caching of the MetricImage can be enabled by SetCacheMetricImageOn();
*
* The behavior of the associated BlockMatching::ImageRegistrationMethod
* GenerateInputRequestedRegion() and EnlargeOutputRequestedRegion() with
* ModifyGenerateInputRequestedRegion() and
* ModifyEnlargeOutputRequestedRegion().
*
* \ingroup Ultrasound
* */
template <typename TMetricImage, typename TDisplacementImage>
class ITK_TEMPLATE_EXPORT MetricImageToDisplacementCalculator : public Object
{
public:
ITK_DISALLOW_COPY_AND_ASSIGN(MetricImageToDisplacementCalculator);
/** Standard class type alias. */
using Self = MetricImageToDisplacementCalculator;
using Superclass = Object;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
/** Run-time type information (and related methods). */
itkTypeMacro(MetricImageToDisplacementCalculator, Object);
/** Type of the metric image (input pixels). */
using MetricImageType = TMetricImage;
using MetricImagePointerType = typename MetricImageType::Pointer;
using IndexType = typename MetricImageType::IndexType;
/** Type of the displacement image (output). */
using DisplacementImageType = TDisplacementImage;
using DisplacementImagePointerType = typename DisplacementImageType::Pointer;
using RegionType = typename DisplacementImageType::RegionType;
using PointType = typename DisplacementImageType::PointType;
/** ImageDimension enumeration. */
itkStaticConstMacro(ImageDimension, unsigned int, TDisplacementImage::ImageDimension);
/** Type of an image of center points of the fixed image blocks. */
using CenterPointsImageType = itk::Image<PointType, ImageDimension>;
using CenterPointsImagePointerType = typename CenterPointsImageType::Pointer;
/** Type of the metric image image. */
using MetricImageImageType = itk::Image<MetricImagePointerType, ImageDimension>;
using MetricImageImagePointerType = typename MetricImageImageType::Pointer;
/** Ensure all the metric images are stored in the class's MetricImageImage.
* */
itkSetMacro(CacheMetricImage, bool);
itkGetConstMacro(CacheMetricImage, bool);
itkBooleanMacro(CacheMetricImage);
/** Set a metric image pixel. This is the way to supply input to this class.
* The point is the center point of the corresponding fixed block.
* The index is the index of the corresponding displacement image pixel. The
* metric image may or may not be stored in the class's MetricImageImage
* depending on the needs of the implementation and whether
* SetCacheMetricImageOn() has been set. */
virtual void
SetMetricImagePixel(const PointType & point, const IndexType & index, MetricImageType * image);
/** Set/Get the displacement image. Get should only be called after calling
* Compute() and all the metric image pixels have been set. */
virtual void
SetDisplacementImage(DisplacementImageType * image);
const DisplacementImageType *
GetDisplacementImage() const
{
return this->m_DisplacementImage.GetPointer();
}
/** Get the MetricImage image (The image of metric images.) This should only
* be called after all the the metric image pixels have been set with
* SetMetricImagePixel(). */
itkSetObjectMacro(MetricImageImage, MetricImageImageType);
itkGetConstObjectMacro(MetricImageImage, MetricImageImageType);
/** Get the center points of the kernels. The points in the metric image that
* corresponds to the kernels movement subtracted from these points is the
* displacement. */
itkSetObjectMacro(CenterPointsImage, CenterPointsImageType);
itkGetConstObjectMacro(CenterPointsImage, CenterPointsImageType);
/** Subclasses must implement this method. If the displacement calculation takes place in
* SetMetricImagePixel(), then this can do nothing. */
virtual void
Compute() = 0;
/** Modify the associated BlockMatching::ImageRegistrationMethod's
* GenerateInputRequestedRegion(). */
virtual void
ModifyGenerateInputRequestedRegion(RegionType & itkNotUsed(region))
{}
/** Modify the associated BlockMatching::ImageRegistrationMethod's
* EnlargeOutputRequestedRegion(). */
virtual void
ModifyEnlargeOutputRequestedRegion(DataObject * itkNotUsed(data))
{}
protected:
using MetricImageDuplicatorType = ImageDuplicator<MetricImageType>;
MetricImageToDisplacementCalculator();
CenterPointsImagePointerType m_CenterPointsImage;
MetricImageImagePointerType m_MetricImageImage;
DisplacementImagePointerType m_DisplacementImage;
bool m_CacheMetricImage;
bool m_RegionsDefined;
typename MetricImageDuplicatorType::Pointer m_MetricImageDuplicator;
MultiThreaderBase::Pointer m_MultiThreader;
private:
};
} // end namespace BlockMatching
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
# include "itkBlockMatchingMetricImageToDisplacementCalculator.hxx"
#endif
#endif