ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkUnsharpMaskImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2 *
3 * Copyright Insight Software Consortium
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:
56  public ImageToImageFilter< TInputImage, TOutputImage >
57 {
58 public:
59  ITK_DISALLOW_COPY_AND_ASSIGN(UnsharpMaskImageFilter);
60 
66 
70  using OutputPixelType = typename TOutputImage::PixelType;
71  using OutputInternalPixelType = typename TOutputImage::InternalPixelType;
72  using InputPixelType = typename TInputImage::PixelType;
73  using InputInternalPixelType = typename TInputImage::InternalPixelType;
76  static constexpr unsigned int ImageDimension = TOutputImage::ImageDimension;
77  static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
78 
82  using InputImageType = TInputImage;
83  using OutputImageType = TOutputImage;
84  using InputImagePointer = typename InputImageType::Pointer;
85 
86  using InternalPrecisionType = TInternalPrecision;
87 
93 
98 
102  itkNewMacro(Self);
103 
104 #ifdef ITK_USE_CONCEPT_CHECKING
105  itkConceptMacro( SameDimensionCheck,
107  itkConceptMacro( InputHasNumericTraitsCheck,
109  itkConceptMacro( InternalTypeIsFloatingPoint,
111 #endif
112 
115 
117 
119  itkSetMacro(Sigmas, SigmaArrayType);
120  itkGetConstMacro(Sigmas, SigmaArrayType);
122 
125  void SetSigma(const typename SigmaArrayType::ValueType sigma)
126  {
127  SigmaArrayType sigmas;
128  sigmas.Fill(sigma);
129  this->SetSigmas(sigmas); //checks whether it is actually modified
130  }
132 
134  itkSetMacro(Amount, TInternalPrecision);
135  itkGetConstMacro(Amount, TInternalPrecision);
137 
138 
140  itkSetMacro(Threshold, TInternalPrecision);
141  itkGetConstMacro(Threshold, TInternalPrecision);
143 
146  itkSetMacro(Clamp, bool);
147  itkGetConstMacro(Clamp, bool);
148  itkBooleanMacro(Clamp);
150 
151 protected:
153  ~UnsharpMaskImageFilter() override = default;
154 
162  void GenerateInputRequestedRegion() override;
163 
164  void VerifyPreconditions() ITKv5_CONST override;
165  void GenerateData() override;
166 
167  void 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 
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 operator==(const UnsharpMaskingFunctor & other)
201  {
202  return (m_Amount == other.m_Amount)
203  && (m_Threshold == other.m_Threshold)
204  && (m_Clamp == other.m_Clamp);
205  }
206 
207  bool operator!= (const UnsharpMaskingFunctor & other)
208  {
209  return !(*this == other);
210  }
211 
212  inline OutPixelType operator()(const InPixelType & v, const FunctorRealType & s) const
213  {
214  FunctorRealType diff = v - s;
215  FunctorRealType result;
216  if (diff > m_Threshold)
217  {
218  result = v + (diff - m_Threshold)*m_Amount;
219  }
220  else if (-diff > m_Threshold)
221  {
222  result = v + (diff + m_Threshold)*m_Amount;
223  }
224  else
225  {
226  result = v;
227  }
228 
229  if (m_Clamp)
230  {
231  if (result < itk::NumericTraits< OutPixelType >::NonpositiveMin())
232  {
233  return itk::NumericTraits< OutPixelType >::NonpositiveMin();
234  }
235  else if (result > itk::NumericTraits< OutPixelType >::max())
236  {
237  return itk::NumericTraits< OutPixelType >::max();
238  }
239  }
240 
241  return static_cast<OutPixelType>(result);
242  }
243  }; //end UnsharpMaskingFunctor
244 }; //end UnsharpMaskImageFilter
245 } // end namespace itk
246 
247 #ifndef ITK_MANUAL_INSTANTIATION
248 #include "itkUnsharpMaskImageFilter.hxx"
249 #endif
250 
251 #endif
typename TInputImage::InternalPixelType InputInternalPixelType
OutPixelType operator()(const InPixelType &v, const FunctorRealType &s) const
typename TInputImage::PixelType InputPixelType
typename TOutputImage::PixelType OutputPixelType
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Base class for all process objects that output image data.
typename TOutputImage::InternalPixelType OutputInternalPixelType
bool operator==(const UnsharpMaskingFunctor &other)
void SetSigma(const typename SigmaArrayType::ValueType sigma)
typename InputImageType::Pointer InputImagePointer
bool operator!=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:492
typename OutputImageType::RegionType OutputImageRegionType
UnsharpMaskingFunctor(FunctorRealType amount, FunctorRealType threshold, bool clamp)
TOutputImage OutputImageType
Computes the smoothing of an image by convolution with the Gaussian kernels implemented as IIR filter...
typename InputImageType::RegionType InputImageRegionType
Base class for filters that take an image as input and produce an image as output.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
#define itkConceptMacro(name, concept)
Templated n-dimensional image class.
Definition: itkImage.h:75
typename GaussianType::SigmaArrayType SigmaArrayType