OTB  9.0.0
Orfeo Toolbox
otbFastNLMeansImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 ThreadedGenerateData(const OutRegionType& outputRegionForThread, itk::ThreadIdType itkNotUsed(threadId)) 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
otb::NLMeansFilter::OutSizeType
OutImageType::SizeType OutSizeType
Definition: otbFastNLMeansImageFilter.h:71
otb::NLMeansFilter::OutImagePointerType
OutImageType::Pointer OutImagePointerType
Definition: otbFastNLMeansImageFilter.h:68
otb::NLMeansFilter
This class implements a fast approximated version of NL Means denoising algorithm....
Definition: otbFastNLMeansImageFilter.h:48
otb::NLMeansFilter::m_Var
float m_Var
Definition: otbFastNLMeansImageFilter.h:162
otb::NLMeansFilter::SetHalfSearchSize
void SetHalfSearchSize(const unsigned int hss)
Definition: otbFastNLMeansImageFilter.h:91
otb::NLMeansFilter::m_NormalizeDistance
float m_NormalizeDistance
Definition: otbFastNLMeansImageFilter.h:164
otb::NLMeansFilter::SetHalfWindowSize
void SetHalfWindowSize(const unsigned int hws)
Definition: otbFastNLMeansImageFilter.h:84
otb::NLMeansFilter::SetCutOffDistance
void SetCutOffDistance(const float thresh)
Definition: otbFastNLMeansImageFilter.h:95
otb::NLMeansFilter::InIndexType
InImageType::IndexType InIndexType
Definition: otbFastNLMeansImageFilter.h:65
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::NLMeansFilter::OutRegionType
OutImageType::RegionType OutRegionType
Definition: otbFastNLMeansImageFilter.h:69
otb::NLMeansFilter::InRegionType
InImageType::RegionType InRegionType
Definition: otbFastNLMeansImageFilter.h:64
otb::NLMeansFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbFastNLMeansImageFilter.h:54
otb::NLMeansFilter::InImageType
TInputImage InImageType
Definition: otbFastNLMeansImageFilter.h:58
otb::NLMeansFilter::SetSigma
void SetSigma(const float sigma)
Definition: otbFastNLMeansImageFilter.h:79
otb::NLMeansFilter::Self
NLMeansFilter Self
Definition: otbFastNLMeansImageFilter.h:52
otb::NLMeansFilter::InSizeType
InImageType::SizeType InSizeType
Definition: otbFastNLMeansImageFilter.h:66
otbFastNLMeansImageFilter.hxx
otb::NLMeansFilter::OutIndexType
OutImageType::IndexType OutIndexType
Definition: otbFastNLMeansImageFilter.h:72
otb::NLMeansFilter::InOffsetType
InImageType::OffsetType InOffsetType
Definition: otbFastNLMeansImageFilter.h:67
otb::NLMeansFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbFastNLMeansImageFilter.h:55
otb::NLMeansFilter::InImagePointerType
InImageType::Pointer InImagePointerType
Definition: otbFastNLMeansImageFilter.h:62
otb::NLMeansFilter::InImageConstPointerType
InImageType::ConstPointer InImageConstPointerType
Definition: otbFastNLMeansImageFilter.h:63
otb::NLMeansFilter::m_CutoffDistance
float m_CutoffDistance
Definition: otbFastNLMeansImageFilter.h:163
otb::NLMeansFilter::Superclass
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
Definition: otbFastNLMeansImageFilter.h:53
otb::NLMeansFilter::OutPixelType
OutImageType::PixelType OutPixelType
Definition: otbFastNLMeansImageFilter.h:70
otb::NLMeansFilter::OutImageType
TOutputImage OutImageType
Definition: otbFastNLMeansImageFilter.h:59