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
23
24namespace itk
25{
54template <typename TInputImage, typename TOutputImage = TInputImage, typename TInternalPrecision = float>
55class ITK_TEMPLATE_EXPORT UnsharpMaskImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
56{
57public:
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>));
107#endif
108
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);
148protected:
150 ~UnsharpMaskImageFilter() override = default;
151
159 void
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
170private:
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
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
Base class for filters that take an image as input and produce an image as output.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Define additional traits for native types such as int or float.
static constexpr T NonpositiveMin()
static constexpr T max(const T &)
Computes the smoothing of an image by convolution with the Gaussian kernels implemented as IIR filter...
OutPixelType operator()(const InPixelType &v, const FunctorRealType &s) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(UnsharpMaskingFunctor)
UnsharpMaskingFunctor(FunctorRealType amount, FunctorRealType threshold, bool clamp)
bool operator==(const UnsharpMaskingFunctor &other) const
typename GaussianType::SigmaArrayType SigmaArrayType
void VerifyPreconditions() ITKv5_CONST override
Verifies that the process object has been configured correctly, that all required inputs are set,...
typename TOutputImage::PixelType OutputPixelType
~UnsharpMaskImageFilter() override=default
typename TInputImage::InternalPixelType InputInternalPixelType
typename TInputImage::RegionType InputImageRegionType
void SetSigma(const typename SigmaArrayType::ValueType sigma)
typename InputImageType::Pointer InputImagePointer
typename TInputImage::PixelType InputPixelType
typename TOutputImage::InternalPixelType OutputInternalPixelType
void GenerateInputRequestedRegion() override
typename TOutputImage::RegionType OutputImageRegionType
SmartPointer< Self > Pointer
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
STL namespace.