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
114 itkSetMacro(Sigmas, SigmaArrayType);
115 itkGetConstMacro(Sigmas, SigmaArrayType);
117
120 void
121 SetSigma(const typename SigmaArrayType::ValueType sigma)
122 {
123 auto sigmas = MakeFilled<SigmaArrayType>(sigma);
124 this->SetSigmas(sigmas); // checks whether it is actually modified
125 }
126
129 itkSetMacro(Amount, TInternalPrecision);
130 itkGetConstMacro(Amount, TInternalPrecision);
132
135 itkSetMacro(Threshold, TInternalPrecision);
136 itkGetConstMacro(Threshold, TInternalPrecision);
138
142 itkSetMacro(Clamp, bool);
143 itkGetConstMacro(Clamp, bool);
144 itkBooleanMacro(Clamp);
146protected:
148 ~UnsharpMaskImageFilter() override = default;
149
157 void
159
160 void
161 VerifyPreconditions() const override;
162 void
163 GenerateData() override;
164
165 void
166 PrintSelf(std::ostream & os, Indent indent) const override;
167
168private:
170 TInternalPrecision m_Amount{};
171 TInternalPrecision m_Threshold{};
173 bool m_Clamp{};
174
175 template <typename InPixelType, typename FunctorRealType = TInternalPrecision, typename OutPixelType = InPixelType>
177 {
178 private:
179 FunctorRealType m_Amount;
180 FunctorRealType m_Threshold;
181 bool m_Clamp{ false };
182
183 public:
185 : m_Amount(0.5)
186 , m_Threshold(0.0)
187
188 {}
189
190 UnsharpMaskingFunctor(FunctorRealType amount, FunctorRealType threshold, bool clamp)
191 : m_Amount(amount)
192 , m_Threshold(threshold)
193 , m_Clamp(clamp)
194 {
195 assert(m_Threshold >= 0.0);
196 }
197
198 bool
200 {
201 return (m_Amount == other.m_Amount) && (m_Threshold == other.m_Threshold) && (m_Clamp == other.m_Clamp);
202 }
203
205
206 inline OutPixelType
207 operator()(const InPixelType & v, const FunctorRealType & s) const
208 {
209 FunctorRealType diff = v - s;
210 FunctorRealType result;
211 if (diff > m_Threshold)
212 {
213 result = v + (diff - m_Threshold) * m_Amount;
214 }
215 else if (-diff > m_Threshold)
216 {
217 result = v + (diff + m_Threshold) * m_Amount;
218 }
219 else
220 {
221 result = v;
222 }
223
224 if (m_Clamp)
225 {
227 {
229 }
231 {
233 }
234 }
235
236 return static_cast<OutPixelType>(result);
237 }
238 }; // end UnsharpMaskingFunctor
239}; // end UnsharpMaskImageFilter
240} // end namespace itk
241
242#ifndef ITK_MANUAL_INSTANTIATION
243# include "itkUnsharpMaskImageFilter.hxx"
244#endif
245
246#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)