ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkMattesMutualInformationImageToImageMetricv4.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkMattesMutualInformationImageToImageMetricv4_h
19#define itkMattesMutualInformationImageToImageMetricv4_h
20
23#include "itkPoint.h"
24#include "itkIndex.h"
26#include "itkArray2D.h"
28#include <mutex>
29
30namespace itk
31{
32
85template <typename TFixedImage,
86 typename TMovingImage,
87 typename TVirtualImage = TFixedImage,
88 typename TInternalComputationValueType = double,
89 typename TMetricTraits =
92 : public ImageToImageMetricv4<TFixedImage, TMovingImage, TVirtualImage, TInternalComputationValueType, TMetricTraits>
93{
94public:
95 ITK_DISALLOW_COPY_AND_MOVE(MattesMutualInformationImageToImageMetricv4);
96
99 using Superclass =
103
105 itkNewMacro(Self);
106
108 itkOverrideGetNameOfClassMacro(MattesMutualInformationImageToImageMetricv4);
109
111 using typename Superclass::MeasureType;
112 using typename Superclass::DerivativeType;
114
115 using typename Superclass::FixedImageType;
116 using typename Superclass::FixedImagePointType;
117 using typename Superclass::FixedImageIndexType;
118 using typename Superclass::FixedImagePixelType;
120
124
125 using typename Superclass::MovingTransformType;
126 using typename Superclass::JacobianType;
128 using typename Superclass::VirtualIndexType;
129 using typename Superclass::VirtualPointType;
130 using typename Superclass::VirtualPointSetType;
131
134
135 /* Image dimension accessors */
136 static constexpr typename TVirtualImage::ImageDimensionType VirtualImageDimension = TVirtualImage::ImageDimension;
137 static constexpr typename TFixedImage::ImageDimensionType FixedImageDimension = TFixedImage::ImageDimension;
138 static constexpr typename TMovingImage::ImageDimensionType MovingImageDimension = TMovingImage::ImageDimension;
139
145 itkSetClampMacro(NumberOfHistogramBins, SizeValueType, 5, NumericTraits<SizeValueType>::max());
146 itkGetConstReferenceMacro(NumberOfHistogramBins, SizeValueType);
148
149 void
150 Initialize() override;
151
153 // NOTE: floating point precision is not as stable.
154 // Double precision proves faster and more robust in real-world testing.
155 using PDFValueType = TInternalComputationValueType;
156
160
165 const typename JointPDFType::Pointer
167 {
168 if (this->m_ThreaderJointPDF.empty())
169 {
170 return typename JointPDFType::Pointer(nullptr);
171 }
172 return this->m_ThreaderJointPDF[0];
173 }
174
175
182 const typename JointPDFDerivativesType::Pointer
184 {
185 return this->m_JointPDFDerivatives;
186 }
187
188 void
189 FinalizeThread(const ThreadIdType threadId) override;
190
191protected:
194
198 Self>;
200 ThreadedIndexedContainerPartitioner,
201 Superclass,
202 Self>;
205 ThreadedImageRegionPartitioner<Superclass::VirtualImageDimension>,
206 Superclass,
207 Self>;
210 Superclass,
211 Self>;
212
213 void
214 PrintSelf(std::ostream & os, Indent indent) const override;
215
224
228
231 virtual void
233
235 ComputeSingleFixedImageParzenWindowIndex(const FixedImagePixelType & value) const;
236
247
250 using PRatioArrayType = std::vector<PRatioType>;
251
253
256 mutable std::vector<OffsetValueType> m_JointPdfIndex1DArray{};
257
259 mutable std::vector<PDFValueType> m_MovingImageMarginalPDF{};
260 mutable std::vector<std::vector<PDFValueType>> m_ThreaderFixedImageMarginalPDF{};
261
263 typename std::vector<typename JointPDFType::Pointer> m_ThreaderJointPDF{};
264
265 /* \class DerivativeBufferManager
266 * A helper class to manage complexities of minimizing memory
267 * needs for mattes mutual information derivative computations
268 * per thread.
269 *
270 * Thread safety note:
271 * A separate object is used locally per each thread. Only the members
272 * m_ParentJointPDFDerivativesMutexPtr and m_ParentJointPDFDerivatives
273 * are shared between threads and access to m_ParentJointPDFDerivatives
274 * is controlled with the m_ParentJointPDFDerivativesMutexPtr mutex lock.
275 * \ingroup ITKMetricsv4
276 */
278 {
280
281 public:
282 /* All these methods are thread safe except ReduceBuffer */
283
284 void
285 Initialize(size_t maxBufferLength,
286 const size_t cachedNumberOfLocalParameters,
287 std::mutex * parentDerivativeMutexPtr,
288 typename JointPDFDerivativesType::Pointer parentJointPDFDerivatives);
289
290 void
292
296
298
299 size_t
304
309 void
311
315 void
317
318 // If offset is same as previous offset, then accumulate with previous
321 {
325 return PDFBufferForWriting;
326 }
327
332 void
334
335 private:
336 // How many AccumulatorElements used
337 size_t m_CurrentFillSize{ 0 };
338 // Contiguous chunk of memory for efficiency
339 std::vector<PDFValueType> m_MemoryBlock;
340 // The (number of lines in the buffer) * (cells per line)
342 std::vector<PDFValueType *> m_BufferPDFValuesContainer;
343 std::vector<OffsetValueType> m_BufferOffsetContainer;
346 // Pointer handle to parent version
348 // Smart pointer handle to parent version
350 };
351
352 std::vector<DerivativeBufferManager> m_ThreaderDerivativeManager{};
355
357
360 mutable std::vector<DerivativeType> m_LocalDerivativeByParzenBin{};
361
362private:
364 virtual void
366};
367
368} // end namespace itk
369
370#ifndef ITK_MANUAL_INSTANTIATION
371# include "itkMattesMutualInformationImageToImageMetricv4.hxx"
372#endif
373
374#endif
Derivative of a BSpline kernel used for density estimation and nonparametric regression.
BSpline kernel used for density estimation and nonparametric regression.
A simple structure holding type information for ImageToImageMetricv4 classes.
Templated n-dimensional image class.
Definition itkImage.h:89
Size< VImageDimension > SizeType
ImageRegion< VImageDimension > RegionType
SmartPointer< Self > Pointer
Definition itkImage.h:96
Index< VImageDimension > IndexType
void Initialize(vcl_size_t maxBufferLength, const vcl_size_t cachedNumberOfLocalParameters, std::mutex *parentDerivativeMutexPtr, typename JointPDFDerivativesType::Pointer parentJointPDFDerivatives)
OffsetValueType ComputeSingleFixedImageParzenWindowIndex(const FixedImagePixelType &value) const
BSplineDerivativeKernelFunction< 3, PDFValueType > CubicBSplineDerivativeFunctionType
void FinalizeThread(const ThreadIdType threadId) override
MattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedImageRegionPartitioner< Superclass::VirtualImageDimension >, Superclass, Self > MattesMutualInformationDenseGetValueAndDerivativeThreaderType
void PrintSelf(std::ostream &os, Indent indent) const override
ImageToImageMetricv4< TFixedImage, TMovingImage, TVirtualImage, TInternalComputationValueType, TMetricTraits > Superclass
static constexpr TVirtualImage::ImageDimensionType VirtualImageDimension
MattesMutualInformationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedIndexedContainerPartitioner, Superclass, Self > MattesMutualInformationSparseGetValueAndDerivativeThreaderType
static constexpr T max(const T &)
Transform< TInternalComputationValueType, TVirtualImage::ImageDimension, TMovingDimension > MovingTransformType
Array< TInternalComputationValueType > DerivativeType
Implements transparent reference counting.
Class for partitioning of an ImageRegion.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned int ThreadIdType
unsigned long SizeValueType
Definition itkIntTypes.h:86
long OffsetValueType
Definition itkIntTypes.h:97