ITK  6.0.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  auto sigmas = MakeFilled<SigmaArrayType>(sigma);
125  this->SetSigmas(sigmas); // checks whether it is actually modified
126  }
130  itkSetMacro(Amount, TInternalPrecision);
131  itkGetConstMacro(Amount, TInternalPrecision);
136  itkSetMacro(Threshold, TInternalPrecision);
137  itkGetConstMacro(Threshold, TInternalPrecision);
142  itkSetMacro(Clamp, bool);
143  itkGetConstMacro(Clamp, bool);
144  itkBooleanMacro(Clamp);
147 protected:
149  ~UnsharpMaskImageFilter() override = default;
150 
158  void
159  GenerateInputRequestedRegion() override;
160 
161  void
162  VerifyPreconditions() const override;
163  void
164  GenerateData() override;
165 
166  void
167  PrintSelf(std::ostream & os, Indent indent) const override;
168 
169 private:
171  TInternalPrecision m_Amount{};
172  TInternalPrecision m_Threshold{};
173  SigmaArrayType m_Sigmas{};
174  bool m_Clamp{};
175 
176  template <typename InPixelType, typename FunctorRealType = TInternalPrecision, typename OutPixelType = InPixelType>
178  {
179  private:
180  FunctorRealType m_Amount;
181  FunctorRealType m_Threshold;
182  bool m_Clamp{ false };
183 
184  public:
186  : m_Amount(0.5)
187  , m_Threshold(0.0)
188 
189  {}
190 
191  UnsharpMaskingFunctor(FunctorRealType amount, FunctorRealType threshold, bool clamp)
192  : m_Amount(amount)
193  , m_Threshold(threshold)
194  , m_Clamp(clamp)
195  {
196  assert(m_Threshold >= 0.0);
197  }
198 
199  bool
200  operator==(const UnsharpMaskingFunctor & other) const
201  {
202  return (m_Amount == other.m_Amount) && (m_Threshold == other.m_Threshold) && (m_Clamp == other.m_Clamp);
203  }
204 
205  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(UnsharpMaskingFunctor);
206 
207  inline OutPixelType
208  operator()(const InPixelType & v, const FunctorRealType & s) const
209  {
210  FunctorRealType diff = v - s;
211  FunctorRealType result;
212  if (diff > m_Threshold)
213  {
214  result = v + (diff - m_Threshold) * m_Amount;
215  }
216  else if (-diff > m_Threshold)
217  {
218  result = v + (diff + m_Threshold) * m_Amount;
219  }
220  else
221  {
222  result = v;
223  }
224 
225  if (m_Clamp)
226  {
228  {
230  }
231  else if (result > itk::NumericTraits<OutPixelType>::max())
232  {
234  }
235  }
236 
237  return static_cast<OutPixelType>(result);
238  }
239  }; // end UnsharpMaskingFunctor
240 }; // end UnsharpMaskImageFilter
241 } // end namespace itk
242 
243 #ifndef ITK_MANUAL_INSTANTIATION
244 # include "itkUnsharpMaskImageFilter.hxx"
245 #endif
246 
247 #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:716
itk::UnsharpMaskImageFilter
Edge enhancement filter.
Definition: itkUnsharpMaskImageFilter.h:55
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor::operator==
bool operator==(const UnsharpMaskingFunctor &other) const
Definition: itkUnsharpMaskImageFilter.h:200
itkSmoothingRecursiveGaussianImageFilter.h
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor::UnsharpMaskingFunctor
UnsharpMaskingFunctor(FunctorRealType amount, FunctorRealType threshold, bool clamp)
Definition: itkUnsharpMaskImageFilter.h:191
itk::NumericTraits::NonpositiveMin
static constexpr T NonpositiveMin()
Definition: itkNumericTraits.h:99
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:696
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor::m_Clamp
bool m_Clamp
Definition: itkUnsharpMaskImageFilter.h:182
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:185
itk::Concept::IsFloatingPoint
Definition: itkConceptChecking.h:948
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:180
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:60
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:169
itk::ImageSource::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor::m_Threshold
FunctorRealType m_Threshold
Definition: itkUnsharpMaskImageFilter.h:181
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor
Definition: itkUnsharpMaskImageFilter.h:177
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
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:208
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