go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkAdvancedImageMomentsCalculator.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright Insight Software Consortium
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 * http://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 itkAdvancedImageMomentsCalculator_h
19#define itkAdvancedImageMomentsCalculator_h
20
21#include "itkInPlaceImageFilter.h"
22#include "itkBinaryThresholdImageFilter.h"
23#include "itkAffineTransform.h"
24#include "itkImage.h"
25#include "itkSpatialObject.h"
26#include "itkImageGridSampler.h"
27#include "itkImageFullSampler.h"
28
29#include <vnl/vnl_vector_fixed.h>
30#include <vnl/vnl_matrix_fixed.h>
31#include <vnl/vnl_diag_matrix.h>
32
33#include "itkPlatformMultiThreader.h"
34
35#include <vector>
36
37namespace itk
38{
67template <typename TImage>
68class ITK_TEMPLATE_EXPORT AdvancedImageMomentsCalculator : public Object
69{
70public:
73 using Superclass = Object;
74 using Pointer = SmartPointer<Self>;
75 using ConstPointer = SmartPointer<const Self>;
76
78 itkNewMacro(Self);
79
81 itkTypeMacro(AdvancedImageMomentsCalculator, Object);
82
84 itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
85
88
90 using VectorType = Vector<ScalarType, Self::ImageDimension>;
91
93 using SpatialObjectType = SpatialObject<Self::ImageDimension>;
94
96 using SpatialObjectPointer = typename SpatialObjectType::Pointer;
97 using SpatialObjectConstPointer = typename SpatialObjectType::ConstPointer;
98
100 using MatrixType = Matrix<ScalarType, Self::ImageDimension, Self::ImageDimension>;
101
103 using ImageType = TImage;
104
106 using ImagePointer = typename ImageType::Pointer;
107 using ImageConstPointer = typename ImageType::ConstPointer;
108
111 using AffineTransformPointer = typename AffineTransformType::Pointer;
112
114 virtual void
115 SetImage(const ImageType * image)
116 {
117 if (m_Image != image)
118 {
119 m_Image = image;
120 this->Modified();
121 m_Valid = false;
122 }
123 }
124
126 virtual void
127 SetSpatialObjectMask(const SpatialObject<Self::ImageDimension> * so)
128 {
129 if (m_SpatialObjectMask != so)
130 {
131 m_SpatialObjectMask = so;
132 this->Modified();
133 m_Valid = false;
134 }
135 }
136
143 void
145
147 void
155
163
171
178
185
194
209
215
222
224 void
225 SetNumberOfWorkUnits(ThreadIdType numberOfThreads)
226 {
227 this->m_Threader->SetNumberOfWorkUnits(numberOfThreads);
228 }
229
230 virtual void
232
233 virtual void
235
237 // using ImageGridSamplerType = itk::ImageFullSampler< ImageType > ;
239 using ImageSampleContainerType = typename ImageGridSamplerType ::ImageSampleContainerType;
240 using ImageSampleContainerPointer = typename ImageSampleContainerType::Pointer;
241
242 virtual void
244
245 using BinaryThresholdImageFilterType = itk::BinaryThresholdImageFilter<TImage, TImage>;
246 using InputPixelType = typename TImage::PixelType;
247
249 itkSetMacro(NumberOfSamplesForCenteredTransformInitialization, SizeValueType);
250 itkSetMacro(LowerThresholdForCenterGravity, InputPixelType);
251 itkSetMacro(CenterOfGravityUsesLowerThreshold, bool);
252
253protected:
256 void
257 PrintSelf(std::ostream & os, Indent indent) const override;
258
260 using ThreaderType = itk::PlatformMultiThreader;
261 using ThreadInfoType = ThreaderType::WorkUnitInfo;
262
264 void
266
268 static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
270
272 virtual void
273 ThreadedCompute(ThreadIdType threadID);
274
276 virtual void
278
281 {
283 };
284
286 {
288 ScalarType st_M0; // Zeroth moment for threading
289 VectorType st_M1; // First moments about origin for threading
290 MatrixType st_M2; // Second moments about origin for threading
291 VectorType st_Cg; // Center of gravity (physical units) for threading
292 MatrixType st_Cm; // Second central moments (physical) for threading
294 };
295 itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, ComputePerThreadStruct, PaddedComputePerThreadStruct);
296 itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedComputePerThreadStruct, AlignedComputePerThreadStruct);
297
299 using ThreadRegionType = typename ImageType::RegionType;
300
301private:
304 void
306
308 void
309 operator=(const Self &);
310
311 ThreaderType::Pointer m_Threader;
312
314
315 mutable std::vector<AlignedComputePerThreadStruct> m_ComputePerThreadVariables;
318
323
324 bool m_Valid; // Have moments been computed yet?
325 ScalarType m_M0; // Zeroth moment
326 VectorType m_M1; // First moments about origin
327 MatrixType m_M2; // Second moments about origin
328 VectorType m_Cg; // Center of gravity (physical units)
329 MatrixType m_Cm; // Second central moments (physical)
330 VectorType m_Pm; // Principal moments (physical)
331 MatrixType m_Pa; // Principal axes (physical)
332
335
336}; // class AdvancedImageMomentsCalculator
337} // end namespace itk
338
339#ifndef ITK_MANUAL_INSTANTIATION
340# include "itkAdvancedImageMomentsCalculator.hxx"
341#endif
342
343#endif /* itkAdvancedImageMomentsCalculator_h */
Compute moments of an n-dimensional image.
typename ImageGridSamplerType ::ImageSampleContainerType ImageSampleContainerType
virtual void SetImage(const ImageType *image)
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedComputePerThreadStruct, AlignedComputePerThreadStruct)
AffineTransformPointer GetPrincipalAxesToPhysicalAxesTransform() const
~AdvancedImageMomentsCalculator() override=default
itk::BinaryThresholdImageFilter< TImage, TImage > BinaryThresholdImageFilterType
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, ComputePerThreadStruct, PaddedComputePerThreadStruct)
itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension)
VectorType GetCenterOfGravity() const
SpatialObject< Self::ImageDimension > SpatialObjectType
void SetNumberOfWorkUnits(ThreadIdType numberOfThreads)
void PrintSelf(std::ostream &os, Indent indent) const override
typename ImageType::ConstPointer ImageConstPointer
AffineTransformPointer GetPhysicalAxesToPrincipalAxesTransform() const
typename ImageSampleContainerType::Pointer ImageSampleContainerPointer
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ComputeThreaderCallback(void *arg)
Vector< ScalarType, Self::ImageDimension > VectorType
Matrix< ScalarType, Self::ImageDimension, Self::ImageDimension > MatrixType
VectorType GetPrincipalMoments() const
typename SpatialObjectType::Pointer SpatialObjectPointer
typename ImageGridSamplerType::Pointer ImageGridSamplerPointer
std::vector< AlignedComputePerThreadStruct > m_ComputePerThreadVariables
typename AffineTransformType::Pointer AffineTransformPointer
virtual void SampleImage(ImageSampleContainerPointer &sampleContainer)
virtual void ThreadedCompute(ThreadIdType threadID)
typename SpatialObjectType::ConstPointer SpatialObjectConstPointer
virtual void SetSpatialObjectMask(const SpatialObject< Self::ImageDimension > *so)
virtual void InitializeThreadingParameters()
MatrixType GetCentralMoments() const
Samples image voxels on a regular grid.


Generated on 2023-01-13 for elastix by doxygen 1.9.6 elastix logo