ITK  5.2.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  * 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 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  HistogramMeasurmenets */
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 
91 
93  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
94  static constexpr unsigned int OutputImageDimension = TOutputImage::ImageDimension;
95 
98 
100  using InputImageType = typename Superclass::InputImageType;
101  using InputImagePointer = typename Superclass::InputImagePointer;
102  using InputImageConstPointer = typename Superclass::InputImageConstPointer;
103  using OutputImageType = typename Superclass::OutputImageType;
104  using OutputImagePointer = 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);
118 
120  itkSetInputMacro(ReferenceImage, InputImageType);
121  itkGetInputMacro(ReferenceImage, InputImageType);
123 
132  itkSetInputMacro(ReferenceHistogram, HistogramType);
133  itkGetInputMacro(ReferenceHistogram, HistogramType);
135 
137  itkSetMacro(NumberOfHistogramLevels, SizeValueType);
138  itkGetConstMacro(NumberOfHistogramLevels, SizeValueType);
140 
142  itkSetMacro(NumberOfMatchPoints, SizeValueType);
143  itkGetConstMacro(NumberOfMatchPoints, SizeValueType);
145 
151  itkSetMacro(ThresholdAtMeanIntensity, bool);
152  itkGetConstMacro(ThresholdAtMeanIntensity, bool);
153  itkBooleanMacro(ThresholdAtMeanIntensity);
155 
165  itkSetMacro(GenerateReferenceHistogramFromImage, bool);
166  itkGetConstMacro(GenerateReferenceHistogramFromImage, bool);
167  itkBooleanMacro(GenerateReferenceHistogramFromImage);
169 
171  void
172  GenerateInputRequestedRegion() override;
173 
177  itkGetModifiableObjectMacro(SourceHistogram, HistogramType);
178  itkGetModifiableObjectMacro(OutputHistogram, HistogramType);
180 
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 
253 
254  using TableType = vnl_matrix<double>;
256 
257  using GradientArrayType = vnl_vector<double>;
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
itk::HistogramMatchingImageFilter::m_OutputHistogram
HistogramPointer m_OutputHistogram
Definition: itkHistogramMatchingImageFilter.h:252
itk::ImageSource::OutputImagePointer
typename OutputImageType::Pointer OutputImagePointer
Definition: itkImageSource.h:91
itk::HistogramMatchingImageFilter::m_SourceMaxValue
THistogramMeasurement m_SourceMaxValue
Definition: itkHistogramMatchingImageFilter.h:246
itk::HistogramMatchingImageFilter::InputPixelType
typename InputImageType::PixelType InputPixelType
Definition: itkHistogramMatchingImageFilter.h:107
itk::HistogramMatchingImageFilter::m_QuantileTable
TableType m_QuantileTable
Definition: itkHistogramMatchingImageFilter.h:255
itk::HistogramMatchingImageFilter
Normalize the grayscale values for a source image by matching the shape of the source image histogram...
Definition: itkHistogramMatchingImageFilter.h:75
itk::HistogramMatchingImageFilter::m_SourceHistogram
HistogramPointer m_SourceHistogram
Definition: itkHistogramMatchingImageFilter.h:251
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::ImageToImageFilter::InputImagePointer
typename InputImageType::Pointer InputImagePointer
Definition: itkImageToImageFilter.h:130
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itkImageToImageFilter.h
itk::HistogramMatchingImageFilter::m_Gradients
GradientArrayType m_Gradients
Definition: itkHistogramMatchingImageFilter.h:258
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::HistogramMatchingImageFilter::m_ReferenceMaxValue
THistogramMeasurement m_ReferenceMaxValue
Definition: itkHistogramMatchingImageFilter.h:249
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::HistogramMatchingImageFilter::m_SourceMinValue
THistogramMeasurement m_SourceMinValue
Definition: itkHistogramMatchingImageFilter.h:245
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::HistogramMatchingImageFilter::m_ReferenceMinValue
THistogramMeasurement m_ReferenceMinValue
Definition: itkHistogramMatchingImageFilter.h:248
itk::ImageToImageFilter::InputImageConstPointer
typename InputImageType::ConstPointer InputImageConstPointer
Definition: itkImageToImageFilter.h:131
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90