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
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 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);
147protected:
149 ~UnsharpMaskImageFilter() override = default;
150
158 void
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
169private:
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
201 {
202 return (m_Amount == other.m_Amount) && (m_Threshold == other.m_Threshold) && (m_Clamp == other.m_Clamp);
203 }
204
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
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
typename TOutputImage::PixelType OutputPixelType
~UnsharpMaskImageFilter() override=default
typename TInputImage::InternalPixelType InputInternalPixelType
typename TInputImage::RegionType InputImageRegionType
void GenerateData() override
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
void PrintSelf(std::ostream &os, Indent indent) const override
void VerifyPreconditions() const override
Verifies that the process object has been configured correctly, that all required inputs are set,...
SmartPointer< Self > Pointer
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....