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
35namespace itk
36{
65template< typename TImage >
66class AdvancedImageMomentsCalculator : public Object
67{
68public:
71 typedef Object Superclass;
73 typedef SmartPointer< const Self > ConstPointer;
74
76 itkNewMacro(Self);
77
79 itkTypeMacro(AdvancedImageMomentsCalculator, Object);
80
82 itkStaticConstMacro(ImageDimension, unsigned int,
83 TImage::ImageDimension);
84
86 typedef double ScalarType;
87
89 typedef Vector< ScalarType, itkGetStaticConstMacro(ImageDimension) > VectorType;
90
92 typedef SpatialObject< itkGetStaticConstMacro(ImageDimension) > SpatialObjectType;
93
95 typedef typename SpatialObjectType::Pointer SpatialObjectPointer;
96 typedef typename SpatialObjectType::ConstPointer SpatialObjectConstPointer;
97
99 typedef Matrix< ScalarType,
100 itkGetStaticConstMacro(ImageDimension),
101 itkGetStaticConstMacro(ImageDimension) > MatrixType;
102
104 typedef TImage ImageType;
105
107 typedef typename ImageType::Pointer ImagePointer;
108 typedef typename ImageType::ConstPointer ImageConstPointer;
109
111 typedef AffineTransform< double, itkGetStaticConstMacro(ImageDimension) > AffineTransformType;
112 typedef typename AffineTransformType::Pointer AffineTransformPointer;
113
115 virtual void 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 SetSpatialObjectMask(const SpatialObject< itkGetStaticConstMacro(ImageDimension) > *so)
127 {
128 if ( m_SpatialObjectMask != so )
129 {
131 this->Modified();
132 m_Valid = false;
133 }
134 }
135
142 void Compute();
143
151
158
165
171
177
185
199
204
210
212 void SetNumberOfWorkUnits(ThreadIdType numberOfThreads)
213 {
214 this->m_Threader->SetNumberOfWorkUnits(numberOfThreads);
215 }
216
217 virtual void BeforeThreadedCompute( void );
218
219 virtual void AfterThreadedCompute( void );
220
222// typedef itk::ImageFullSampler< ImageType > ImageGridSamplerType;
224 typedef typename ImageGridSamplerType
227
228 virtual void SampleImage(ImageSampleContainerPointer & sampleContainer);
229
230 typedef itk::BinaryThresholdImageFilter < TImage, TImage > BinaryThresholdImageFilterType;
231 typedef typename TImage::PixelType InputPixelType;
232
234 itkSetMacro( NumberOfSamplesForCenteredTransformInitialization, SizeValueType );
235 itkSetMacro( LowerThresholdForCenterGravity, InputPixelType );
236 itkSetMacro( CenterOfGravityUsesLowerThreshold, bool );
237
238protected:
241 void PrintSelf(std::ostream & os, Indent indent) const override;
242
244 typedef itk::PlatformMultiThreader ThreaderType;
245 typedef ThreaderType::WorkUnitInfo ThreadInfoType;
246 ThreaderType::Pointer m_Threader;
247
250
252 static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ComputeThreaderCallback(void * arg);
253
255 virtual inline void ThreadedCompute(ThreadIdType threadID);
256
259
262 {
264 };
266
268 {
270 ScalarType st_M0; // Zeroth moment for threading
271 VectorType st_M1; // First moments about origin for threading
272 MatrixType st_M2; // Second moments about origin for threading
273 VectorType st_Cg; // Center of gravity (physical units) for threading
274 MatrixType st_Cm; // Second central moments (physical) for threading
276 };
277 itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, ComputePerThreadStruct,
278 PaddedComputePerThreadStruct);
279 itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedComputePerThreadStruct,
280 AlignedComputePerThreadStruct);
281 mutable AlignedComputePerThreadStruct * m_ComputePerThreadVariables;
285
287 typedef typename ImageType::RegionType ThreadRegionType;
288
293
294private:
298
300 void operator = ( const Self & );
301
302 bool m_Valid; // Have moments been computed yet?
303 ScalarType m_M0; // Zeroth moment
304 VectorType m_M1; // First moments about origin
305 MatrixType m_M2; // Second moments about origin
306 VectorType m_Cg; // Center of gravity (physical units)
307 MatrixType m_Cm; // Second central moments (physical)
308 VectorType m_Pm; // Principal moments (physical)
309 MatrixType m_Pa; // Principal axes (physical)
310
313
314}; // class AdvancedImageMomentsCalculator
315} // end namespace itk
316
317#ifndef ITK_MANUAL_INSTANTIATION
318#include "itkAdvancedImageMomentsCalculator.hxx"
319#endif
320
321#endif /* itkAdvancedImageMomentsCalculator_h */
Compute moments of an n-dimensional image.
virtual void AfterThreadedCompute(void)
virtual void SetImage(const ImageType *image)
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedComputePerThreadStruct, AlignedComputePerThreadStruct)
ImageSampleContainerType::Pointer ImageSampleContainerPointer
AffineTransformPointer GetPrincipalAxesToPhysicalAxesTransform() const
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, ComputePerThreadStruct, PaddedComputePerThreadStruct)
itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension)
VectorType GetCenterOfGravity() const
Vector< ScalarType, itkGetStaticConstMacro(ImageDimension) > VectorType
void LaunchComputeThreaderCallback(void) const
void SetNumberOfWorkUnits(ThreadIdType numberOfThreads)
ImageGridSamplerType::ImageSampleContainerType ImageSampleContainerType
void PrintSelf(std::ostream &os, Indent indent) const override
itk::BinaryThresholdImageFilter< TImage, TImage > BinaryThresholdImageFilterType
SpatialObject< itkGetStaticConstMacro(ImageDimension) > SpatialObjectType
AlignedComputePerThreadStruct * m_ComputePerThreadVariables
AffineTransformPointer GetPhysicalAxesToPrincipalAxesTransform() const
AffineTransform< double, itkGetStaticConstMacro(ImageDimension) > AffineTransformType
AdvancedImageMomentsCalculator< TImage > Self
virtual void BeforeThreadedCompute(void)
virtual void InitializeThreadingParameters(void)
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ComputeThreaderCallback(void *arg)
VectorType GetPrincipalMoments() const
virtual void SetSpatialObjectMask(const SpatialObject< itkGetStaticConstMacro(ImageDimension) > *so)
SpatialObjectType::ConstPointer SpatialObjectConstPointer
virtual void SampleImage(ImageSampleContainerPointer &sampleContainer)
virtual void ThreadedCompute(ThreadIdType threadID)
itk::ImageGridSampler< ImageType > ImageGridSamplerType
Matrix< ScalarType, itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension) > MatrixType
MatrixType GetCentralMoments() const
Samples image voxels on a regular grid.
Superclass::ImageSampleContainerType ImageSampleContainerType


Generated on 1667476801 for elastix by doxygen 1.9.4 elastix logo