ITK  5.2.0
Insight Toolkit
itkImageToHistogramFilter.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  * 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 itkImageToHistogramFilter_h
19 #define itkImageToHistogramFilter_h
20 
21 #include <mutex>
22 
23 #include "itkHistogram.h"
24 #include "itkImageSink.h"
26 #include "itkProgressReporter.h"
27 
28 namespace itk
29 {
30 namespace Statistics
31 {
49 template <typename TImage>
50 class ITK_TEMPLATE_EXPORT ImageToHistogramFilter : public ImageSink<TImage>
51 {
52 public:
53  ITK_DISALLOW_COPY_AND_MOVE(ImageToHistogramFilter);
54 
60 
62  itkTypeMacro(ImageToHistogramFilter, ImageSink);
63 
65  itkNewMacro(Self);
66 
67  using ImageType = TImage;
68  using PixelType = typename ImageType::PixelType;
72 
79 
80 public:
82  const HistogramType *
83  GetOutput() const;
85  GetOutput();
87 
90 
93 
97 
100 
107  itkSetGetDecoratedInputMacro(HistogramSize, HistogramSizeType);
108 
112  itkSetGetDecoratedInputMacro(MarginalScale, HistogramMeasurementType);
113 
116  itkSetGetDecoratedInputMacro(HistogramBinMinimum, HistogramMeasurementVectorType);
117  itkSetGetDecoratedInputMacro(HistogramBinMaximum, HistogramMeasurementVectorType);
119 
123  itkSetGetDecoratedInputMacro(AutoMinimumMaximum, bool);
124  itkBooleanMacro(AutoMinimumMaximum);
126 
129  virtual void
130  GraftOutput(DataObject * graft);
131 
132 
133  // Change the access from protected to public to expose streaming option, a using statement can not be used due to
134  // limitations of wrapping.
135  void
136  SetNumberOfStreamDivisions(const unsigned int n) override
137  {
138  Superclass::SetNumberOfStreamDivisions(n);
139  }
140  unsigned int
141  GetNumberOfStreamDivisions() const override
142  {
143  return Superclass::GetNumberOfStreamDivisions();
144  }
145 
146 protected:
148  ~ImageToHistogramFilter() override = default;
149  void
150  PrintSelf(std::ostream & os, Indent indent) const override;
151 
152  void
153  StreamedGenerateData(unsigned int inputRequestedRegionNumber) override;
154 
155  void
156  InitializeOutputHistogram();
157  void
158  AfterStreamedGenerateData() override;
159 
162  using Superclass::MakeOutput;
164 
165  /* Override method to disable streaming when the minimum and
166  * maximum need to be computed. */
167  unsigned int
168  GetNumberOfInputRequestedRegions() override;
169 
170  void
171  ThreadedStreamedGenerateData(const RegionType &) override;
172  virtual void
173  ThreadedComputeMinimumAndMaximum(const RegionType & inputRegionForThread);
174 
175 
176  virtual void
177  ThreadedMergeHistogram(HistogramPointer && histogram);
178 
179  std::mutex m_Mutex;
180 
182 
185 
186 private:
187  void
188  ApplyMarginalScale(HistogramMeasurementVectorType & min,
190  HistogramSizeType & size);
191 };
192 } // end of namespace Statistics
193 } // end of namespace itk
194 
195 #ifndef ITK_MANUAL_INSTANTIATION
196 # include "itkImageToHistogramFilter.hxx"
197 #endif
198 
199 #endif
itk::SimpleDataObjectDecorator
Decorates any "simple" data type (data types without smart pointers) with a DataObject API.
Definition: itkSimpleDataObjectDecorator.h:66
itk::Statistics::ImageToHistogramFilter::SetNumberOfStreamDivisions
void SetNumberOfStreamDivisions(const unsigned int n) override
Definition: itkImageToHistogramFilter.h:136
itk::Statistics::ImageToHistogramFilter::HistogramMeasurementVectorType
typename HistogramType::MeasurementVectorType HistogramMeasurementVectorType
Definition: itkImageToHistogramFilter.h:78
itkProgressReporter.h
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::Statistics::ImageToHistogramFilter::HistogramConstPointer
typename HistogramType::ConstPointer HistogramConstPointer
Definition: itkImageToHistogramFilter.h:75
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ProcessObject::DataObjectPointerArraySizeType
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
Definition: itkProcessObject.h:193
itk::Statistics::Histogram::MeasurementVectorType
typename Superclass::MeasurementVectorType MeasurementVectorType
Definition: itkHistogram.h:101
itk::Statistics::Histogram
This class stores measurement vectors in the context of n-dimensional histogram.
Definition: itkHistogram.h:77
itkImageSink.h
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::Statistics::ImageToHistogramFilter::HistogramPointer
typename HistogramType::Pointer HistogramPointer
Definition: itkImageToHistogramFilter.h:74
itkHistogram.h
itk::Statistics::ImageToHistogramFilter::HistogramSizeType
typename HistogramType::SizeType HistogramSizeType
Definition: itkImageToHistogramFilter.h:76
itk::Statistics::ImageToHistogramFilter::PixelType
typename ImageType::PixelType PixelType
Definition: itkImageToHistogramFilter.h:68
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::Statistics::ImageToHistogramFilter::ValueType
typename NumericTraits< PixelType >::ValueType ValueType
Definition: itkImageToHistogramFilter.h:70
itk::Statistics::ImageToHistogramFilter::m_Maximum
HistogramMeasurementVectorType m_Maximum
Definition: itkImageToHistogramFilter.h:184
itk::Statistics::ImageToHistogramFilter::RegionType
typename ImageType::RegionType RegionType
Definition: itkImageToHistogramFilter.h:69
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::Statistics::ImageToHistogramFilter::ValueRealType
typename NumericTraits< ValueType >::RealType ValueRealType
Definition: itkImageToHistogramFilter.h:71
itk::Statistics::ImageToHistogramFilter::GetNumberOfStreamDivisions
unsigned int GetNumberOfStreamDivisions() const override
Definition: itkImageToHistogramFilter.h:141
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Statistics::ImageToHistogramFilter::ImageType
TImage ImageType
Definition: itkImageToHistogramFilter.h:67
itk::Statistics::ImageToHistogramFilter::m_MergeHistogram
HistogramPointer m_MergeHistogram
Definition: itkImageToHistogramFilter.h:181
itk::Statistics::ImageToHistogramFilter::m_Mutex
std::mutex m_Mutex
Definition: itkImageToHistogramFilter.h:179
itk::Statistics::ImageToHistogramFilter::HistogramMeasurementType
typename HistogramType::MeasurementType HistogramMeasurementType
Definition: itkImageToHistogramFilter.h:77
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:84
itkSimpleDataObjectDecorator.h
itk::Statistics::ImageToHistogramFilter
This class generates a histogram from an image.
Definition: itkImageToHistogramFilter.h:50
itk::Statistics::Histogram::MeasurementType
TMeasurement MeasurementType
Definition: itkHistogram.h:98
itk::ImageSink
Definition: itkImageSink.h:53
itk::Statistics::ImageToHistogramFilter::m_Minimum
HistogramMeasurementVectorType m_Minimum
Definition: itkImageToHistogramFilter.h:183
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293