OTB  10.0.0
Orfeo Toolbox
otbFastNLMeansImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbFastNLMeansImageFilter_h
22 #define otbFastNLMeansImageFilter_h
23 
24 #include "itkImageToImageFilter.h"
25 
26 namespace otb
27 {
28 
47 template <class TInputImage, class TOutputImage>
48 class ITK_EXPORT NLMeansFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage>
49 {
50 public:
53  typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
54  typedef itk::SmartPointer<Self> Pointer;
55  typedef itk::SmartPointer<const Self> ConstPointer;
56 
58  typedef TInputImage InImageType;
59  typedef TOutputImage OutImageType;
60 
62  typedef typename InImageType::Pointer InImagePointerType;
63  typedef typename InImageType::ConstPointer InImageConstPointerType;
64  typedef typename InImageType::RegionType InRegionType;
65  typedef typename InImageType::IndexType InIndexType;
66  typedef typename InImageType::SizeType InSizeType;
67  typedef typename InImageType::OffsetType InOffsetType;
68  typedef typename OutImageType::Pointer OutImagePointerType;
69  typedef typename OutImageType::RegionType OutRegionType;
70  typedef typename OutImageType::PixelType OutPixelType;
71  typedef typename OutImageType::SizeType OutSizeType;
72  typedef typename OutImageType::IndexType OutIndexType;
73 
75  itkNewMacro(Self);
76  itkTypeMacro(NLMeansFilter, ImageToImageFilter);
78 
79  void SetSigma(const float sigma)
80  {
81  m_Var = 2.0 * sigma * sigma;
82  }
83 
84  void SetHalfWindowSize(const unsigned int hws)
85  {
86  m_HalfPatchSize.Fill(hws);
87  // Update NormalizeDistance
88  m_NormalizeDistance = (2 * hws + 1) * (2 * hws + 1) * m_CutoffDistance * m_CutoffDistance;
89  }
90 
91  void SetHalfSearchSize(const unsigned int hss)
92  {
93  m_HalfSearchSize.Fill(hss);
94  }
95  void SetCutOffDistance(const float thresh)
96  {
97  m_CutoffDistance = thresh;
98  // Update NormalizeDistance
99  m_NormalizeDistance = (2 * m_HalfPatchSize[0] + 1) * (2 * m_HalfPatchSize[1] + 1) * m_CutoffDistance * m_CutoffDistance;
100  }
101 
102 protected:
104  NLMeansFilter();
105 
107  ~NLMeansFilter() override = default;
108 
109  void DynamicThreadedGenerateData(const OutRegionType& outputRegionForThread) override;
110 
111  void GenerateInputRequestedRegion() override;
112 
120  std::tuple<InRegionType, int, int, int, int, bool> OutputRegionToInputRegion(const OutRegionType& outputRegion) const;
121 
123  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
124 
125 private:
126  NLMeansFilter(const Self&) = delete; // purposely not implemented
127  NLMeansFilter& operator=(const Self&) = delete; // purposely not implemented
128 
143  ) const;
144 
157  ) const;
158 
159  // Define class attributes
160  InSizeType m_HalfSearchSize{0,0};
161  InSizeType m_HalfPatchSize{0,0};
162  float m_Var;
164  float m_NormalizeDistance; // cutoff**2 * windowSize**2
165 
166  static const int m_ROW = 1;
167  static const int m_COL = 0;
168 };
169 } // end namespace otb
170 
171 #ifndef OTB_MANUAL_INSTANTIATION
173 #endif
174 
175 #endif
This class implements a fast approximated version of NL Means denoising algorithm....
InImageType::SizeType InSizeType
NLMeansFilter & operator=(const Self &)=delete
OutImageType::PixelType OutPixelType
InImageType::RegionType InRegionType
InImageType::OffsetType InOffsetType
InImageType::ConstPointer InImageConstPointerType
OutImageType::RegionType OutRegionType
~NLMeansFilter() override=default
itk::SmartPointer< const Self > ConstPointer
InImageType::IndexType InIndexType
void SetHalfWindowSize(const unsigned int hws)
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
OutImageType::Pointer OutImagePointerType
void SetCutOffDistance(const float thresh)
NLMeansFilter(const Self &)=delete
OutImageType::SizeType OutSizeType
OutImageType::IndexType OutIndexType
InImageType::Pointer InImagePointerType
void SetSigma(const float sigma)
itk::SmartPointer< Self > Pointer
void SetHalfSearchSize(const unsigned int hss)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.