ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkHistogramMatchingImageFilter.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 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 {
65 /* THistogramMeasurement -- The precision level for which to do
66  HistogramMeasurmenets */
67 template< typename TInputImage, typename TOutputImage, typename THistogramMeasurement = typename TInputImage::PixelType >
68 class ITK_TEMPLATE_EXPORT HistogramMatchingImageFilter:
69  public ImageToImageFilter< TInputImage, TOutputImage >
70 {
71 public:
72  ITK_DISALLOW_COPY_AND_ASSIGN(HistogramMatchingImageFilter);
73 
79 
81  itkNewMacro(Self);
82 
85 
87  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
88  static constexpr unsigned int OutputImageDimension = TOutputImage::ImageDimension;
89 
92 
94  using InputImageType = typename Superclass::InputImageType;
95  using InputImagePointer = typename Superclass::InputImagePointer;
96  using InputImageConstPointer = typename Superclass::InputImageConstPointer;
97  using OutputImageType = typename Superclass::OutputImageType;
98  using OutputImagePointer = typename Superclass::OutputImagePointer;
99 
101  using InputPixelType = typename InputImageType::PixelType;
102  using OutputPixelType = typename OutputImageType::PixelType;
103 
107 
109  void SetSourceImage(const InputImageType *source)
110  { this->SetInput(source); }
112  { return this->GetInput(); }
114 
116  void SetReferenceImage(const InputImageType *reference);
117 
118  const InputImageType * GetReferenceImage();
119 
121  itkSetMacro(NumberOfHistogramLevels, SizeValueType);
122  itkGetConstMacro(NumberOfHistogramLevels, SizeValueType);
124 
126  itkSetMacro(NumberOfMatchPoints, SizeValueType);
127  itkGetConstMacro(NumberOfMatchPoints, SizeValueType);
129 
135  itkSetMacro(ThresholdAtMeanIntensity, bool);
136  itkGetConstMacro(ThresholdAtMeanIntensity, bool);
137  itkBooleanMacro(ThresholdAtMeanIntensity);
139 
141  void GenerateInputRequestedRegion() override;
142 
146  itkGetModifiableObjectMacro(SourceHistogram, HistogramType);
147  itkGetModifiableObjectMacro(ReferenceHistogram, HistogramType);
148  itkGetModifiableObjectMacro(OutputHistogram, HistogramType);
150 
151 #ifdef ITK_USE_CONCEPT_CHECKING
152  // Begin concept checking
153  itkConceptMacro( IntConvertibleToInputCheck,
155  itkConceptMacro( SameDimensionCheck,
157  itkConceptMacro( DoubleConvertibleToInputCheck,
159  itkConceptMacro( DoubleConvertibleToOutputCheck,
161  itkConceptMacro( InputConvertibleToDoubleCheck,
163  itkConceptMacro( OutputConvertibleToDoubleCheck,
165  itkConceptMacro( SameTypeCheck,
167  // End concept checking
168 #endif
169 
170 protected:
172  ~HistogramMatchingImageFilter() override = default;
173  void PrintSelf(std::ostream & os, Indent indent) const override;
174 
175  void BeforeThreadedGenerateData() override;
176 
177  void AfterThreadedGenerateData() override;
178 
179  void DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread) override;
180 
181 
187  void VerifyInputInformation() ITKv5_CONST override {}
188 
190  void ComputeMinMaxMean(const InputImageType *image,
191  THistogramMeasurement & minValue,
192  THistogramMeasurement & maxValue,
193  THistogramMeasurement & meanValue);
194 
196  void ConstructHistogram(const InputImageType *image,
197  HistogramType *histogram, const THistogramMeasurement minValue,
198  const THistogramMeasurement maxValue);
199 
200 private:
201  SizeValueType m_NumberOfHistogramLevels{256};
202  SizeValueType m_NumberOfMatchPoints{1};
203  bool m_ThresholdAtMeanIntensity{true};
204 
208 
209  THistogramMeasurement m_SourceMinValue;
210  THistogramMeasurement m_SourceMaxValue;
211  THistogramMeasurement m_SourceMeanValue;
212  THistogramMeasurement m_ReferenceMinValue;
213  THistogramMeasurement m_ReferenceMaxValue;
214  THistogramMeasurement m_ReferenceMeanValue;
215  THistogramMeasurement m_OutputMinValue;
216  THistogramMeasurement m_OutputMaxValue;
217  THistogramMeasurement m_OutputMeanValue;
218 
222 
223  using TableType = vnl_matrix< double >;
225 
226  using GradientArrayType = vnl_vector< double >;
228  double m_LowerGradient{0.0};
229  double m_UpperGradient{0.0};
230 };
231 } // end namespace itk
232 
233 #ifndef ITK_MANUAL_INSTANTIATION
234 #include "itkHistogramMatchingImageFilter.hxx"
235 #endif
236 
237 #endif
typename OutputImageType::Pointer OutputImagePointer
unsigned long SizeValueType
Definition: itkIntTypes.h:83
This class stores measurement vectors in the context of n-dimensional histogram.
Definition: itkHistogram.h:77
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Base class for all process objects that output image data.
typename HistogramType::Pointer HistogramPointer
typename InputImageType::Pointer InputImagePointer
typename OutputImageType::RegionType OutputImageRegionType
TOutputImage OutputImageType
Base class for filters that take an image as input and produce an image as output.
void SetSourceImage(const InputImageType *source)
Normalize the grayscale values between two images by histogram matching.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename OutputImageType::PixelType OutputPixelType
typename InputImageType::PixelType InputPixelType
#define itkConceptMacro(name, concept)
typename InputImageType::ConstPointer InputImageConstPointer