ITK  5.4.0
Insight Toolkit
itkHistogramMatchingImageFilter.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  * 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 itkHistogramMatchingImageFilter_h
19 #define itkHistogramMatchingImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
22 #include "itkHistogram.h"
23 #include "vnl/vnl_matrix.h"
24 
25 namespace itk
26 {
72 /* THistogramMeasurement -- The precision level for which to do
73  HistogramMeasurements */
74 template <typename TInputImage, typename TOutputImage, typename THistogramMeasurement = typename TInputImage::PixelType>
75 class ITK_TEMPLATE_EXPORT HistogramMatchingImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
76 {
77 public:
78  ITK_DISALLOW_COPY_AND_MOVE(HistogramMatchingImageFilter);
79 
85 
87  itkNewMacro(Self);
88 
90  itkOverrideGetNameOfClassMacro(HistogramMatchingImageFilter);
91 
93  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
94  static constexpr unsigned int OutputImageDimension = TOutputImage::ImageDimension;
95 
98 
100  using typename Superclass::InputImageType;
101  using typename Superclass::InputImagePointer;
102  using typename Superclass::InputImageConstPointer;
103  using typename Superclass::OutputImageType;
104  using typename Superclass::OutputImagePointer;
105 
107  using InputPixelType = typename InputImageType::PixelType;
108  using OutputPixelType = typename OutputImageType::PixelType;
109 
113 
115  itkSetInputMacro(SourceImage, InputImageType);
116  itkGetInputMacro(SourceImage, InputImageType);
120  itkSetInputMacro(ReferenceImage, InputImageType);
121  itkGetInputMacro(ReferenceImage, InputImageType);
132  itkSetInputMacro(ReferenceHistogram, HistogramType);
133  itkGetInputMacro(ReferenceHistogram, HistogramType);
137  itkSetMacro(NumberOfHistogramLevels, SizeValueType);
138  itkGetConstMacro(NumberOfHistogramLevels, SizeValueType);
142  itkSetMacro(NumberOfMatchPoints, SizeValueType);
143  itkGetConstMacro(NumberOfMatchPoints, SizeValueType);
151  itkSetMacro(ThresholdAtMeanIntensity, bool);
152  itkGetConstMacro(ThresholdAtMeanIntensity, bool);
153  itkBooleanMacro(ThresholdAtMeanIntensity);
165  itkSetMacro(GenerateReferenceHistogramFromImage, bool);
166  itkGetConstMacro(GenerateReferenceHistogramFromImage, bool);
167  itkBooleanMacro(GenerateReferenceHistogramFromImage);
171  void
172  GenerateInputRequestedRegion() override;
173 
177  itkGetModifiableObjectMacro(SourceHistogram, HistogramType);
178  itkGetModifiableObjectMacro(OutputHistogram, HistogramType);
181 #ifdef ITK_USE_CONCEPT_CHECKING
182  // Begin concept checking
183  itkConceptMacro(IntConvertibleToInputCheck, (Concept::Convertible<int, InputPixelType>));
185  itkConceptMacro(DoubleConvertibleToInputCheck, (Concept::Convertible<double, InputPixelType>));
186  itkConceptMacro(DoubleConvertibleToOutputCheck, (Concept::Convertible<double, OutputPixelType>));
187  itkConceptMacro(InputConvertibleToDoubleCheck, (Concept::Convertible<InputPixelType, double>));
188  itkConceptMacro(OutputConvertibleToDoubleCheck, (Concept::Convertible<OutputPixelType, double>));
190  // End concept checking
191 #endif
192 
193 protected:
195  ~HistogramMatchingImageFilter() override = default;
196  void
197  PrintSelf(std::ostream & os, Indent indent) const override;
198 
199  void
200  BeforeThreadedGenerateData() override;
201 
202  void
203  AfterThreadedGenerateData() override;
204 
205  void
206  DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
207 
208 
214  void
215  VerifyInputInformation() ITKv5_CONST override
216  {}
217 
218  void
219  VerifyPreconditions() ITKv5_CONST override;
220 
222  void
223  ComputeMinMaxMean(const InputImageType * image,
224  THistogramMeasurement & minValue,
225  THistogramMeasurement & maxValue,
226  THistogramMeasurement & meanValue);
227 
232  void
233  ConstructHistogramFromIntensityRange(const InputImageType * image,
234  HistogramType * histogram,
235  const THistogramMeasurement minHistogramValidValue,
236  const THistogramMeasurement maxHistogramValidValue,
237  const THistogramMeasurement imageTrueMinValue,
238  const THistogramMeasurement imageTrueMaxValue);
239 
240 private:
241  SizeValueType m_NumberOfHistogramLevels{ 256 };
242  SizeValueType m_NumberOfMatchPoints{ 1 };
243  bool m_ThresholdAtMeanIntensity{ true };
244 
245  THistogramMeasurement m_SourceMinValue{};
246  THistogramMeasurement m_SourceMaxValue{};
247 
248  THistogramMeasurement m_ReferenceMinValue{};
249  THistogramMeasurement m_ReferenceMaxValue{};
250 
251  HistogramPointer m_SourceHistogram{};
252  HistogramPointer m_OutputHistogram{};
253 
254  using TableType = vnl_matrix<double>;
255  TableType m_QuantileTable{};
256 
257  using GradientArrayType = vnl_vector<double>;
258  GradientArrayType m_Gradients{};
259  double m_LowerGradient{ 0.0 };
260  double m_UpperGradient{ 0.0 };
261  bool m_GenerateReferenceHistogramFromImage{ true };
262 };
263 } // end namespace itk
264 
265 #ifndef ITK_MANUAL_INSTANTIATION
266 # include "itkHistogramMatchingImageFilter.hxx"
267 #endif
268 
269 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::HistogramMatchingImageFilter::InputPixelType
typename InputImageType::PixelType InputPixelType
Definition: itkHistogramMatchingImageFilter.h:107
itk::HistogramMatchingImageFilter
Normalize the grayscale values for a source image by matching the shape of the source image histogram...
Definition: itkHistogramMatchingImageFilter.h:75
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::HistogramMatchingImageFilter::HistogramPointer
typename HistogramType::Pointer HistogramPointer
Definition: itkHistogramMatchingImageFilter.h:112
itk::Concept::SameDimension
Definition: itkConceptChecking.h:694
itk::HistogramMatchingImageFilter::OutputPixelType
typename OutputImageType::PixelType OutputPixelType
Definition: itkHistogramMatchingImageFilter.h:108
itk::ImageToImageFilter
Base class for filters that take an image as input and produce an image as output.
Definition: itkImageToImageFilter.h:108
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::Statistics::Histogram
This class stores measurement vectors in the context of n-dimensional histogram.
Definition: itkHistogram.h:77
itk::HistogramMatchingImageFilter::VerifyInputInformation
void VerifyInputInformation() ITKv5_CONST override
Definition: itkHistogramMatchingImageFilter.h:215
itkHistogram.h
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itkImageToImageFilter.h
itk::ImageSource::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk::Concept::SameType
Definition: itkConceptChecking.h:677
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::Concept::Convertible
Definition: itkConceptChecking.h:216
itk::HistogramMatchingImageFilter::TableType
vnl_matrix< double > TableType
Definition: itkHistogramMatchingImageFilter.h:254
itk::HistogramMatchingImageFilter::GradientArrayType
vnl_vector< double > GradientArrayType
Definition: itkHistogramMatchingImageFilter.h:257
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83