ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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{
53
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;
73 using OutputImageRegionType = typename TOutputImage::RegionType;
74 using InputImageRegionType = typename TInputImage::RegionType;
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
96 itkOverrideGetNameOfClassMacro(UnsharpMaskImageFilter);
97
101 itkNewMacro(Self);
102
104 itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits<OutputPixelType>));
106
109
111
113 itkSetMacro(Sigmas, SigmaArrayType);
114 itkGetConstMacro(Sigmas, SigmaArrayType);
116
119 void
120 SetSigma(const typename SigmaArrayType::ValueType sigma)
121 {
122 auto sigmas = MakeFilled<SigmaArrayType>(sigma);
123 this->SetSigmas(sigmas); // checks whether it is actually modified
124 }
125
126
128 itkSetMacro(Amount, TInternalPrecision);
129 itkGetConstMacro(Amount, TInternalPrecision);
131
132
134 itkSetMacro(Threshold, TInternalPrecision);
135 itkGetConstMacro(Threshold, TInternalPrecision);
137
140 itkSetMacro(Clamp, bool);
141 itkGetConstMacro(Clamp, bool);
142 itkBooleanMacro(Clamp);
144
145protected:
147 ~UnsharpMaskImageFilter() override = default;
148
156 void
158
159 void
160 VerifyPreconditions() const override;
161 void
162 GenerateData() override;
163
164 void
165 PrintSelf(std::ostream & os, Indent indent) const override;
166
167private:
169 TInternalPrecision m_Amount{};
170 TInternalPrecision m_Threshold{};
172 bool m_Clamp{};
173
174 template <typename InPixelType, typename FunctorRealType = TInternalPrecision, typename OutPixelType = InPixelType>
176 {
177 private:
178 FunctorRealType m_Amount;
179 FunctorRealType m_Threshold;
180 bool m_Clamp{ false };
181
182 public:
184 : m_Amount(0.5)
185 , m_Threshold(0.0)
186
187 {}
188
189 UnsharpMaskingFunctor(FunctorRealType amount, FunctorRealType threshold, bool clamp)
190 : m_Amount(amount)
191 , m_Threshold(threshold)
192 , m_Clamp(clamp)
193 {
194 assert(m_Threshold >= 0.0);
195 }
196
197 bool
199 {
200 return (m_Amount == other.m_Amount) && (m_Threshold == other.m_Threshold) && (m_Clamp == other.m_Clamp);
201 }
202
204
205 inline OutPixelType
206 operator()(const InPixelType & v, const FunctorRealType & s) const
207 {
208 FunctorRealType diff = v - s;
209 FunctorRealType result;
210 if (diff > m_Threshold)
211 {
212 result = v + (diff - m_Threshold) * m_Amount;
213 }
214 else if (-diff > m_Threshold)
215 {
216 result = v + (diff + m_Threshold) * m_Amount;
217 }
218 else
219 {
220 result = v;
221 }
222
223 if (m_Clamp)
224 {
226 {
228 }
230 {
232 }
233 }
234
235 return static_cast<OutPixelType>(result);
236 }
237 }; // end UnsharpMaskingFunctor
238}; // end UnsharpMaskImageFilter
239} // end namespace itk
240
241#ifndef ITK_MANUAL_INSTANTIATION
242# include "itkUnsharpMaskImageFilter.hxx"
243#endif
244
245#endif
Control indentation during Print() invocation.
Definition itkIndent.h:50
static constexpr T NonpositiveMin()
static constexpr T max(const T &)
Implements transparent reference counting.
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
SmoothingRecursiveGaussianImageFilter< TInputImage, Image< TInternalPrecision, TOutputImage::ImageDimension > > GaussianType
typename TOutputImage::PixelType OutputPixelType
static constexpr unsigned int InputImageDimension
static constexpr unsigned int ImageDimension
ImageToImageFilter< TInputImage, TOutputImage > Superclass
~UnsharpMaskImageFilter() override=default
typename TInputImage::InternalPixelType InputInternalPixelType
typename TInputImage::RegionType InputImageRegionType
virtual void SetSigmas(SigmaArrayType _arg)
SmartPointer< const Self > ConstPointer
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,...
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
constexpr TContainer MakeFilled(typename TContainer::const_reference value)