ITK  5.2.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  * 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 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_ASSIGN(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;
83  using InputImagePointer = typename InputImageType::Pointer;
84 
85  using InternalPrecisionType = TInternalPrecision;
86 
92 
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);
118 
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  }
129 
131  itkSetMacro(Amount, TInternalPrecision);
132  itkGetConstMacro(Amount, TInternalPrecision);
134 
135 
137  itkSetMacro(Threshold, TInternalPrecision);
138  itkGetConstMacro(Threshold, TInternalPrecision);
140 
143  itkSetMacro(Clamp, bool);
144  itkGetConstMacro(Clamp, bool);
145  itkBooleanMacro(Clamp);
147 
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
202  {
203  return (m_Amount == other.m_Amount) && (m_Threshold == other.m_Threshold) && (m_Clamp == other.m_Clamp);
204  }
205 
206  bool
208  {
209  return !(*this == other);
210  }
211 
212  inline OutPixelType
213  operator()(const InPixelType & v, const FunctorRealType & s) const
214  {
215  FunctorRealType diff = v - s;
216  FunctorRealType result;
217  if (diff > m_Threshold)
218  {
219  result = v + (diff - m_Threshold) * m_Amount;
220  }
221  else if (-diff > m_Threshold)
222  {
223  result = v + (diff + m_Threshold) * m_Amount;
224  }
225  else
226  {
227  result = v;
228  }
229 
230  if (m_Clamp)
231  {
233  {
235  }
236  else if (result > itk::NumericTraits<OutPixelType>::max())
237  {
239  }
240  }
241 
242  return static_cast<OutPixelType>(result);
243  }
244  }; // end UnsharpMaskingFunctor
245 }; // end UnsharpMaskImageFilter
246 } // end namespace itk
247 
248 #ifndef ITK_MANUAL_INSTANTIATION
249 # include "itkUnsharpMaskImageFilter.hxx"
250 #endif
251 
252 #endif
itk::UnsharpMaskImageFilter::InternalPrecisionType
TInternalPrecision InternalPrecisionType
Definition: itkUnsharpMaskImageFilter.h:85
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:712
itk::UnsharpMaskImageFilter
Edge enhancement filter.
Definition: itkUnsharpMaskImageFilter.h:55
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:97
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor::operator==
bool operator==(const UnsharpMaskingFunctor &other)
Definition: itkUnsharpMaskImageFilter.h:201
itk::UnsharpMaskImageFilter::OutputInternalPixelType
typename TOutputImage::InternalPixelType OutputInternalPixelType
Definition: itkUnsharpMaskImageFilter.h:70
itk::Concept::SameDimension
Definition: itkConceptChecking.h:692
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:945
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:58
itk::NumericTraits::max
static constexpr T max(const T &)
Definition: itkNumericTraits.h:167
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:64
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:138
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:213
itk::ImageToImageFilter::InputImageRegionType
typename InputImageType::RegionType InputImageRegionType
Definition: itkImageToImageFilter.h:132
itk::UnsharpMaskImageFilter::UnsharpMaskingFunctor::operator!=
bool operator!=(const UnsharpMaskingFunctor &other)
Definition: itkUnsharpMaskImageFilter.h:207
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