ITK  5.4.0
Insight Toolkit
itkUnsharpMaskImageFilter.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 itkUnsharpMaskImageFilter_h
19 #define itkUnsharpMaskImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
23 
24 namespace itk
25 {
54 template <typename TInputImage, typename TOutputImage = TInputImage, typename TInternalPrecision = float>
55 class ITK_TEMPLATE_EXPORT UnsharpMaskImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
56 {
57 public:
58  ITK_DISALLOW_COPY_AND_MOVE(UnsharpMaskImageFilter);
59 
65 
69  using OutputPixelType = typename TOutputImage::PixelType;
70  using OutputInternalPixelType = typename TOutputImage::InternalPixelType;
71  using InputPixelType = typename TInputImage::PixelType;
72  using InputInternalPixelType = typename TInputImage::InternalPixelType;
75  static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension;
76  static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
77 
81  using InputImageType = TInputImage;
82  using OutputImageType = TOutputImage;
84 
85  using InternalPrecisionType = TInternalPrecision;
86 
92 
96  itkOverrideGetNameOfClassMacro(UnsharpMaskImageFilter);
97 
101  itkNewMacro(Self);
102 
103 #ifdef ITK_USE_CONCEPT_CHECKING
105  itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits<OutputPixelType>));
106  itkConceptMacro(InternalTypeIsFloatingPoint, (Concept::IsFloatingPoint<TInternalPrecision>));
107 #endif
108 
109  using GaussianType =
111 
113 
115  itkSetMacro(Sigmas, SigmaArrayType);
116  itkGetConstMacro(Sigmas, SigmaArrayType);
121  void
122  SetSigma(const typename SigmaArrayType::ValueType sigma)
123  {
124  SigmaArrayType sigmas;
125  sigmas.Fill(sigma);
126  this->SetSigmas(sigmas); // checks whether it is actually modified
127  }
131  itkSetMacro(Amount, TInternalPrecision);
132  itkGetConstMacro(Amount, TInternalPrecision);
137  itkSetMacro(Threshold, TInternalPrecision);
138  itkGetConstMacro(Threshold, TInternalPrecision);
143  itkSetMacro(Clamp, bool);
144  itkGetConstMacro(Clamp, bool);
145  itkBooleanMacro(Clamp);
148 protected:
150  ~UnsharpMaskImageFilter() override = default;
151 
159  void
160  GenerateInputRequestedRegion() override;
161 
162  void
163  VerifyPreconditions() ITKv5_CONST override;
164  void
165  GenerateData() override;
166 
167  void
168  PrintSelf(std::ostream & os, Indent indent) const override;
169 
170 private:
172  TInternalPrecision m_Amount{};
173  TInternalPrecision m_Threshold{};
174  SigmaArrayType m_Sigmas{};
175  bool m_Clamp{};
176 
177  template <typename InPixelType, typename FunctorRealType = TInternalPrecision, typename OutPixelType = InPixelType>
179  {
180  private:
181  FunctorRealType m_Amount;
182  FunctorRealType m_Threshold;
183  bool m_Clamp{ false };
184 
185  public:
187  : m_Amount(0.5)
188  , m_Threshold(0.0)
189 
190  {}
191 
192  UnsharpMaskingFunctor(FunctorRealType amount, FunctorRealType threshold, bool clamp)
193  : m_Amount(amount)
194  , m_Threshold(threshold)
195  , m_Clamp(clamp)
196  {
197  assert(m_Threshold >= 0.0);
198  }
199 
200  bool
201  operator==(const UnsharpMaskingFunctor & other) const
202  {
203  return (m_Amount == other.m_Amount) && (m_Threshold == other.m_Threshold) && (m_Clamp == other.m_Clamp);
204  }
205 
206  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(UnsharpMaskingFunctor);
207 
208  inline OutPixelType
209  operator()(const InPixelType & v, const FunctorRealType & s) const
210  {
211  FunctorRealType diff = v - s;
212  FunctorRealType result;
213  if (diff > m_Threshold)
214  {
215  result = v + (diff - m_Threshold) * m_Amount;
216  }
217  else if (-diff > m_Threshold)
218  {
219  result = v + (diff + m_Threshold) * m_Amount;
220  }
221  else
222  {
223  result = v;
224  }
225 
226  if (m_Clamp)
227  {
229  {
231  }
232  else if (result > itk::NumericTraits<OutPixelType>::max())
233  {
235  }
236  }
237 
238  return static_cast<OutPixelType>(result);
239  }
240  }; // end UnsharpMaskingFunctor
241 }; // end UnsharpMaskImageFilter
242 } // end namespace itk
243 
244 #ifndef ITK_MANUAL_INSTANTIATION
245 # include "itkUnsharpMaskImageFilter.hxx"
246 #endif
247 
248 #endif
itk::UnsharpMaskImageFilter::InternalPrecisionType
TInternalPrecision InternalPrecisionType
Definition: itkUnsharpMaskImageFilter.h:85
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::UnsharpMaskImageFilter::InputInternalPixelType
typename TInputImage::InternalPixelType InputInternalPixelType
Definition: itkUnsharpMaskImageFilter.h:72
itk::UnsharpMaskImageFilter::OutputPixelType
typename TOutputImage::PixelType OutputPixelType
Definition: itkUnsharpMaskImageFilter.h:69
itk::Concept::HasNumericTraits
Definition: itkConceptChecking.h:714
itk::UnsharpMaskImageFilter
Edge enhancement filter.
Definition: itkUnsharpMaskImageFilter.h:55
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor::operator==
bool operator==(const UnsharpMaskingFunctor &other) const
Definition: itkUnsharpMaskImageFilter.h:201
itkSmoothingRecursiveGaussianImageFilter.h
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor::UnsharpMaskingFunctor
UnsharpMaskingFunctor(FunctorRealType amount, FunctorRealType threshold, bool clamp)
Definition: itkUnsharpMaskImageFilter.h:192
itk::NumericTraits::NonpositiveMin
static constexpr T NonpositiveMin()
Definition: itkNumericTraits.h:98
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::UnsharpMaskImageFilter::OutputInternalPixelType
typename TOutputImage::InternalPixelType OutputInternalPixelType
Definition: itkUnsharpMaskImageFilter.h:70
itk::Concept::SameDimension
Definition: itkConceptChecking.h:694
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor::m_Clamp
bool m_Clamp
Definition: itkUnsharpMaskImageFilter.h:183
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::UnsharpMaskImageFilter::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkUnsharpMaskImageFilter.h:71
itk::ImageToImageFilter::InputImagePointer
typename InputImageType::Pointer InputImagePointer
Definition: itkImageToImageFilter.h:130
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor::UnsharpMaskingFunctor
UnsharpMaskingFunctor()
Definition: itkUnsharpMaskImageFilter.h:186
itk::Concept::IsFloatingPoint
Definition: itkConceptChecking.h:946
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itkImageToImageFilter.h
itk::FixedArray< ScalarRealType, Self::ImageDimension >
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor::m_Amount
FunctorRealType m_Amount
Definition: itkUnsharpMaskImageFilter.h:181
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:59
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:168
itk::ImageSource::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor::m_Threshold
FunctorRealType m_Threshold
Definition: itkUnsharpMaskImageFilter.h:182
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor
Definition: itkUnsharpMaskImageFilter.h:178
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::UnsharpMaskImageFilter::SetSigma
void SetSigma(const typename SigmaArrayType::ValueType sigma)
Definition: itkUnsharpMaskImageFilter.h:122
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor::operator()
OutPixelType operator()(const InPixelType &v, const FunctorRealType &s) const
Definition: itkUnsharpMaskImageFilter.h:209
itk::ImageToImageFilter::InputImageRegionType
typename InputImageType::RegionType InputImageRegionType
Definition: itkImageToImageFilter.h:132
itk::SmoothingRecursiveGaussianImageFilter
Computes the smoothing of an image by convolution with the Gaussian kernels implemented as IIR filter...
Definition: itkSmoothingRecursiveGaussianImageFilter.h:50
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90
itk::UnsharpMaskImageFilter::SigmaArrayType
typename GaussianType::SigmaArrayType SigmaArrayType
Definition: itkUnsharpMaskImageFilter.h:112