Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
itkMaskedStatisticsImageFilter.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 * 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 itkMaskedStatisticsImageFilter_h
19 #define itkMaskedStatisticsImageFilter_h
20 
21 #include <itkImageToImageFilter.h>
22 #include <itkNumericTraits.h>
23 #include <itkArray.h>
24 #include <itkSimpleDataObjectDecorator.h>
25 
26 namespace itk
27 {
44  template< typename TInputImage , typename TMaskImage = ::itk::Image<unsigned char, TInputImage::ImageDimension> >
46  public ImageToImageFilter< TInputImage, TInputImage >
47  {
48  public:
51  typedef ImageToImageFilter< TInputImage, TInputImage > Superclass;
54 
56  itkNewMacro(Self);
57 
59  itkTypeMacro(MaskedStatisticsImageFilter, ImageToImageFilter);
60 
63  typedef typename Superclass::InputImagePointer InputImagePointer;
64 
65  typedef typename TInputImage::RegionType RegionType;
66  typedef typename TInputImage::SizeType SizeType;
67  typedef typename TInputImage::IndexType IndexType;
68  typedef typename TInputImage::PixelType PixelType;
69 
71  itkStaticConstMacro(ImageDimension, unsigned int,
72  TInputImage::ImageDimension);
73 
75  typedef typename NumericTraits< PixelType >::RealType RealType;
76 
78  typedef typename DataObject::Pointer DataObjectPointer;
79 
81  typedef SimpleDataObjectDecorator< RealType > RealObjectType;
82  typedef SimpleDataObjectDecorator< PixelType > PixelObjectType;
83 
84  typedef TMaskImage MaskImageType;
85  typedef typename MaskImageType::ConstPointer MaskImageConstPointer;
86  typedef typename MaskImageType::RegionType MaskImageRegionType;
87 
90  { return this->GetMinimumOutput()->Get(); }
91  PixelObjectType * GetMinimumOutput();
92 
94 
97  { return this->GetMaximumOutput()->Get(); }
98  PixelObjectType * GetMaximumOutput();
99 
101 
104  { return this->GetMeanOutput()->Get(); }
105  RealObjectType * GetMeanOutput();
106 
107  const RealObjectType * GetMeanOutput() const;
108 
111  { return this->GetSigmaOutput()->Get(); }
112  RealObjectType * GetSigmaOutput();
113 
115 
118  { return this->GetVarianceOutput()->Get(); }
119  RealObjectType * GetVarianceOutput();
120 
122 
124  RealType GetSum() const
125  { return this->GetSumOutput()->Get(); }
126  RealObjectType * GetSumOutput();
127 
128  const RealObjectType * GetSumOutput() const;
129 
132  typedef ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType;
133  using Superclass::MakeOutput;
135 
136  itkSetConstObjectMacro(Mask, MaskImageType);
137  itkGetConstObjectMacro(Mask, MaskImageType);
138 
139 #ifdef ITK_USE_CONCEPT_CHECKING
140  // Begin concept checking
141  itkConceptMacro( InputHasNumericTraitsCheck,
142  ( Concept::HasNumericTraits< PixelType > ) );
143  // End concept checking
144 #endif
145 
146  protected:
149  void PrintSelf(std::ostream & os, Indent indent) const override;
150 
154  void AllocateOutputs() override;
155 
157  void BeforeThreadedGenerateData() override;
158 
161  void AfterThreadedGenerateData() override;
162 
165  outputRegionForThread,
166  ThreadIdType threadId) override;
167 
168  // Override since the filter needs all the data for the algorithm
170 
171  // Override since the filter produces all of its output
172  void EnlargeOutputRequestedRegion(DataObject *data) override;
173 
174  private:
175  MaskedStatisticsImageFilter(const Self &); //purposely not implemented
176  void operator=(const Self &); //purposely not implemented
177 
178  Array< RealType > m_ThreadSum;
179  Array< RealType > m_SumOfSquares;
180  Array< SizeValueType > m_Count;
181  Array< PixelType > m_ThreadMin;
182  Array< PixelType > m_ThreadMax;
183  MaskImageConstPointer m_Mask;
184  }; // end of class
185 } // end namespace itk
186 
187 #ifndef ITK_MANUAL_INSTANTIATION
188 #include <itkMaskedStatisticsImageFilter.tpp>
189 #endif
190 
191 #endif
Compute min. max, variance and mean of an (masked) Image.
NumericTraits< PixelType >::RealType RealType
void AfterThreadedGenerateData() override
const PixelObjectType * GetMaximumOutput() const
PixelObjectType * GetMinimumOutput()
void PrintSelf(std::ostream &os, Indent indent) const override
void ThreadedGenerateData(const RegionType &outputRegionForThread, ThreadIdType threadId) override
SimpleDataObjectDecorator< PixelType > PixelObjectType
Superclass::InputImagePointer InputImagePointer
RealObjectType * GetVarianceOutput()
RealObjectType * GetMeanOutput()
void GenerateInputRequestedRegion() override
void BeforeThreadedGenerateData() override
const RealObjectType * GetSigmaOutput() const
RealObjectType * GetSumOutput()
const PixelObjectType * GetMinimumOutput() const
ImageToImageFilter< TInputImage, TInputImage > Superclass
RealObjectType * GetSigmaOutput()
const RealObjectType * GetVarianceOutput() const
ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override
const RealObjectType * GetSumOutput() const
itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension)
MaskImageType::ConstPointer MaskImageConstPointer
const RealObjectType * GetMeanOutput() const
void EnlargeOutputRequestedRegion(DataObject *data) override
SimpleDataObjectDecorator< RealType > RealObjectType
PixelObjectType * GetMaximumOutput()
::mitk::Image InputImageType
Input image type for mapping operations.