ITK  4.13.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:
64 
68  typedef typename TOutputImage::PixelType OutputPixelType;
69  typedef typename TOutputImage::InternalPixelType OutputInternalPixelType;
70  typedef typename TInputImage::PixelType InputPixelType;
71  typedef typename TInputImage::InternalPixelType InputInternalPixelType;
72  typedef typename TOutputImage::RegionType OutputImageRegionType;
73  typedef typename TInputImage::RegionType InputImageRegionType;
74  itkStaticConstMacro(ImageDimension, unsigned int,
75  TOutputImage::ImageDimension);
76  itkStaticConstMacro(InputImageDimension, unsigned int,
77  TInputImage::ImageDimension);
79 
83  typedef TInputImage InputImageType;
84  typedef TOutputImage OutputImageType;
85  typedef typename InputImageType::Pointer InputImagePointer;
86 
87  typedef TInternalPrecision InternalPrecisionType;
88 
94 
99 
103  itkNewMacro(Self);
104 
105 #ifdef ITK_USE_CONCEPT_CHECKING
106  itkConceptMacro( SameDimensionCheck,
108  itkConceptMacro( InputHasNumericTraitsCheck,
110  itkConceptMacro( InternalTypeIsFloatingPoint,
112 #endif
113 
116 
118 
120  itkSetMacro(Sigmas, SigmaArrayType);
121  itkGetConstMacro(Sigmas, SigmaArrayType);
123 
126  void SetSigma(const typename SigmaArrayType::ValueType sigma)
127  {
128  SigmaArrayType sigmas;
129  sigmas.Fill(sigma);
130  this->SetSigmas(sigmas); //checks whether it is actually modified
131  }
133 
135  itkSetMacro(Amount, TInternalPrecision);
136  itkGetConstMacro(Amount, TInternalPrecision);
138 
139 
141  itkSetMacro(Threshold, TInternalPrecision);
142  itkGetConstMacro(Threshold, TInternalPrecision);
144 
147  itkSetMacro(Clamp, bool);
148  itkGetConstMacro(Clamp, bool);
149  itkBooleanMacro(Clamp);
151 
152 protected:
154  virtual ~UnsharpMaskImageFilter() ITK_OVERRIDE {}
155 
163  virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
164 
165  virtual void VerifyPreconditions() ITK_OVERRIDE;
166  virtual void GenerateData() ITK_OVERRIDE;
167 
168  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
169 
170 private:
171  ITK_DISALLOW_COPY_AND_ASSIGN(UnsharpMaskImageFilter);
172 
174  TInternalPrecision m_Amount;
175  TInternalPrecision m_Threshold;
176  SigmaArrayType m_Sigmas;
177  bool m_Clamp;
178 
179  template<typename InPixelType, typename FunctorRealType = TInternalPrecision, typename OutPixelType = InPixelType>
181  {
182  private:
183  FunctorRealType m_Amount;
184  FunctorRealType m_Threshold;
185  bool m_Clamp;
186 
187  public:
189  : m_Amount(0.5),
190  m_Threshold(0.0),
191  m_Clamp(false)
192  {
193  }
194 
195  UnsharpMaskingFunctor(FunctorRealType amount, FunctorRealType threshold, bool clamp)
196  : m_Amount(amount),
197  m_Threshold(threshold),
198  m_Clamp(clamp)
199  {
200  assert(m_Threshold >= 0.0);
201  }
202 
203  bool operator==(const UnsharpMaskingFunctor & other)
204  {
205  return (m_Amount == other.m_Amount)
206  && (m_Threshold == other.m_Threshold)
207  && (m_Clamp == other.m_Clamp);
208  }
209 
210  bool operator!= (const UnsharpMaskingFunctor & other)
211  {
212  return !(*this == other);
213  }
214 
215  inline OutPixelType operator()(const InPixelType & v, const FunctorRealType & s) const
216  {
217  FunctorRealType diff = v - s;
218  FunctorRealType result;
219  if (diff > m_Threshold)
220  {
221  result = v + (diff - m_Threshold)*m_Amount;
222  }
223  else if (-diff > m_Threshold)
224  {
225  result = v + (diff + m_Threshold)*m_Amount;
226  }
227  else
228  {
229  result = v;
230  }
231 
232  if (m_Clamp)
233  {
235  {
237  }
238  else if (result > itk::NumericTraits< OutPixelType >::max())
239  {
241  }
242  }
243 
244  return static_cast<OutPixelType>(result);
245  }
246  }; //end UnsharpMaskingFunctor
247 }; //end UnsharpMaskImageFilter
248 } // end namespace itk
249 
250 #ifndef ITK_MANUAL_INSTANTIATION
251 #include "itkUnsharpMaskImageFilter.hxx"
252 #endif
253 
254 #endif
bool operator!=(const ImageRegionCopier< D1, D2 > &c1, const ImageRegionCopier< D1, D2 > &c2)
TOutputImage::PixelType OutputPixelType
ImageToImageFilter< TInputImage, TOutputImage > Superclass
OutPixelType operator()(const InPixelType &v, const FunctorRealType &s) const
SmoothingRecursiveGaussianImageFilter< TInputImage, Image< TInternalPrecision, TOutputImage::ImageDimension > > GaussianType
Base class for all process objects that output image data.
void Fill(const ValueType &)
bool operator==(const UnsharpMaskingFunctor &other)
SmartPointer< const Self > ConstPointer
TOutputImage::RegionType OutputImageRegionType
static ITK_CONSTEXPR_FUNC T max(const T &)
void SetSigma(const typename SigmaArrayType::ValueType sigma)
TInputImage::InternalPixelType InputInternalPixelType
UnsharpMaskingFunctor(FunctorRealType amount, FunctorRealType threshold, bool clamp)
TInputImage::PixelType InputPixelType
Computes the smoothing of an image by convolution with the Gaussian kernels implemented as IIR filter...
TOutputImage::InternalPixelType OutputInternalPixelType
static ITK_CONSTEXPR_FUNC T NonpositiveMin()
TInputImage::RegionType InputImageRegionType
InputImageType::Pointer InputImagePointer
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 additional traits for native types such as int or float.
#define itkConceptMacro(name, concept)
Templated n-dimensional image class.
Definition: itkImage.h:75
GaussianType::SigmaArrayType SigmaArrayType