Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
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 * 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 __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 {
48  template< typename TInputImage , typename TMaskImage = ::itk::Image<unsigned char, TInputImage::ImageDimension> >
50  public ImageToImageFilter< TInputImage, TInputImage >
51  {
52  public:
55  typedef ImageToImageFilter< TInputImage, TInputImage > Superclass;
58 
60  itkNewMacro(Self);
61 
63  itkTypeMacro(MaskedStatisticsImageFilter, ImageToImageFilter);
64 
67  typedef typename Superclass::InputImagePointer InputImagePointer;
68 
69  typedef typename TInputImage::RegionType RegionType;
70  typedef typename TInputImage::SizeType SizeType;
71  typedef typename TInputImage::IndexType IndexType;
73 
75  itkStaticConstMacro(ImageDimension, unsigned int,
76  TInputImage::ImageDimension);
77 
79  typedef typename NumericTraits< PixelType >::RealType RealType;
80 
82  typedef typename DataObject::Pointer DataObjectPointer;
83 
85  typedef SimpleDataObjectDecorator< RealType > RealObjectType;
86  typedef SimpleDataObjectDecorator< PixelType > PixelObjectType;
87 
88  typedef TMaskImage MaskImageType;
89  typedef typename MaskImageType::ConstPointer MaskImageConstPointer;
90  typedef typename MaskImageType::RegionType MaskImageRegionType;
91 
93  PixelType GetMinimum() const
94  { return this->GetMinimumOutput()->Get(); }
95  PixelObjectType * GetMinimumOutput();
96 
97  const PixelObjectType * GetMinimumOutput() const;
98 
100  PixelType GetMaximum() const
101  { return this->GetMaximumOutput()->Get(); }
102  PixelObjectType * GetMaximumOutput();
103 
104  const PixelObjectType * GetMaximumOutput() const;
105 
107  RealType GetMean() const
108  { return this->GetMeanOutput()->Get(); }
109  RealObjectType * GetMeanOutput();
110 
111  const RealObjectType * GetMeanOutput() const;
112 
114  RealType GetSigma() const
115  { return this->GetSigmaOutput()->Get(); }
116  RealObjectType * GetSigmaOutput();
117 
118  const RealObjectType * GetSigmaOutput() const;
119 
121  RealType GetVariance() const
122  { return this->GetVarianceOutput()->Get(); }
123  RealObjectType * GetVarianceOutput();
124 
125  const RealObjectType * GetVarianceOutput() const;
126 
128  RealType GetSum() const
129  { return this->GetSumOutput()->Get(); }
130  RealObjectType * GetSumOutput();
131 
132  const RealObjectType * GetSumOutput() const;
133 
136  typedef ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType;
137  using Superclass::MakeOutput;
138  DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override;
139 
140  itkSetConstObjectMacro(Mask, MaskImageType);
141  itkGetConstObjectMacro(Mask, MaskImageType);
142 
143 #ifdef ITK_USE_CONCEPT_CHECKING
144  // Begin concept checking
145  itkConceptMacro( InputHasNumericTraitsCheck,
146  ( Concept::HasNumericTraits< PixelType > ) );
147  // End concept checking
148 #endif
149 
150  protected:
153  void PrintSelf(std::ostream & os, Indent indent) const override;
154 
158  void AllocateOutputs() override;
159 
161  void BeforeThreadedGenerateData() override;
162 
165  void AfterThreadedGenerateData() override;
166 
168  void ThreadedGenerateData(const RegionType &
169  outputRegionForThread,
170  ThreadIdType threadId) override;
171 
172  // Override since the filter needs all the data for the algorithm
173  void GenerateInputRequestedRegion() override;
174 
175  // Override since the filter produces all of its output
176  void EnlargeOutputRequestedRegion(DataObject *data) override;
177 
178  private:
179  MaskedStatisticsImageFilter(const Self &); //purposely not implemented
180  void operator=(const Self &); //purposely not implemented
181 
182  Array< RealType > m_ThreadSum;
183  Array< RealType > m_SumOfSquares;
184  Array< SizeValueType > m_Count;
185  Array< PixelType > m_ThreadMin;
186  Array< PixelType > m_ThreadMax;
187  MaskImageConstPointer m_Mask;
188  }; // end of class
189 } // end namespace itk
190 
191 #ifndef ITK_MANUAL_INSTANTIATION
192 #include "itkMaskedStatisticsImageFilter.hxx"
193 #endif
194 
195 #endif
itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension)
NumericTraits< PixelType >::RealType RealType
SimpleDataObjectDecorator< RealType > RealObjectType
PixelObjectType * GetMaximumOutput()
PixelObjectType * GetMinimumOutput()
void BeforeThreadedGenerateData() override
ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
void EnlargeOutputRequestedRegion(DataObject *data) override
RealObjectType * GetMeanOutput()
void AfterThreadedGenerateData() override
Compute min. max, variance and mean of an (masked) Image.
RealObjectType * GetVarianceOutput()
MaskImageType::ConstPointer MaskImageConstPointer
ImageToImageFilter< TInputImage, TInputImage > Superclass
SimpleDataObjectDecorator< PixelType > PixelObjectType
Superclass::InputImagePointer InputImagePointer
RealObjectType * GetSumOutput()
void PrintSelf(std::ostream &os, Indent indent) const override
void ThreadedGenerateData(const RegionType &outputRegionForThread, ThreadIdType threadId) override
DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override
unsigned short PixelType
void GenerateInputRequestedRegion() override
RealObjectType * GetSigmaOutput()