18 #ifndef itkPatchBasedDenoisingImageFilter_h
19 #define itkPatchBasedDenoisingImageFilter_h
32 #include <type_traits>
35 #include "ITKDenoisingExport.h"
61 template <
typename TInputImage,
typename TOutputImage>
74 using typename Superclass::OutputImagePointer;
83 using typename Superclass::InputImageType;
84 using typename Superclass::OutputImageType;
87 static constexpr
unsigned int ImageDimension = Superclass::ImageDimension;
98 using typename Superclass::PixelType;
99 using typename Superclass::PixelValueType;
108 using typename Superclass::ListAdaptorType;
109 using typename Superclass::PatchRadiusType;
110 using typename Superclass::InputImagePatchIterator;
112 using typename Superclass::PatchWeightsType;
146 itkSetMacro(UseSmoothDiscPatchWeights,
bool);
147 itkBooleanMacro(UseSmoothDiscPatchWeights);
148 itkGetConstMacro(UseSmoothDiscPatchWeights,
bool);
164 itkSetClampMacro(KernelBandwidthFractionPixelsForEstimation,
double, 0.01, 1.0);
165 itkGetConstReferenceMacro(KernelBandwidthFractionPixelsForEstimation,
double);
170 itkSetMacro(ComputeConditionalDerivatives,
bool);
171 itkBooleanMacro(ComputeConditionalDerivatives);
172 itkGetConstMacro(ComputeConditionalDerivatives,
bool);
188 itkSetMacro(UseFastTensorComputations,
bool);
189 itkBooleanMacro(UseFastTensorComputations);
190 itkGetConstMacro(UseFastTensorComputations,
bool);
194 static constexpr
unsigned int MaxSigmaUpdateIterations = 20;
202 itkSetClampMacro(KernelBandwidthMultiplicationFactor,
double, 0.01, 100);
203 itkGetConstReferenceMacro(KernelBandwidthMultiplicationFactor,
double);
210 SetNoiseSigma(
const RealType & sigma);
212 itkGetConstMacro(NoiseSigma,
RealType);
220 itkGetConstMacro(NumIndependentComponents,
unsigned int);
226 PrintSelf(std::ostream & os,
Indent indent)
const override;
234 AllocateUpdateBuffer()
override;
237 CopyInputToOutput()
override;
240 GenerateInputRequestedRegion()
override;
242 template <
typename T,
typename U =
void>
245 template <
typename T,
typename U =
void>
255 template <
typename T>
268 template <
typename T>
269 typename EnableIfMultiComponent<T, typename NumericTraits<T>::ValueType>::type
276 template <
typename T>
279 unsigned int itkNotUsed(idx),
285 template <
typename T>
298 if (this->GetComponentSpace() == Superclass::ComponentSpaceEnum::RIEMANNIAN)
300 DispatchedRiemannianMinMax(img);
304 DispatchedArrayMinMax(img);
308 template <
typename TImageType>
309 typename DisableIfMultiComponent<typename TImageType::PixelType>::type
312 DispatchedMinMax(img);
315 template <
typename TImageType>
316 typename EnableIfMultiComponent<typename TImageType::PixelType>::type
319 DispatchedArrayMinMax(img);
334 bool useCachedComputations,
341 if (this->GetComponentSpace() == Superclass::ComponentSpaceEnum::RIEMANNIAN)
343 ComputeLogMapAndWeightedSquaredGeodesicDifference(
344 a, b, weight, useCachedComputations, cacheIndex, eigenValsCache, eigenVecsCache, diff, norm);
348 ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(
349 a, b, weight, useCachedComputations, cacheIndex, eigenValsCache, eigenVecsCache, diff, norm);
354 template <
typename PixelT>
359 bool useCachedComputations,
366 ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(
367 a, b, weight, useCachedComputations, cacheIndex, eigenValsCache, eigenVecsCache, diff, norm);
376 if (this->GetComponentSpace() == Superclass::ComponentSpaceEnum::RIEMANNIAN)
378 return this->AddExponentialMapUpdate(a, b);
382 return this->AddEuclideanUpdate(a, b);
387 template <
typename RealT>
391 return this->AddEuclideanUpdate(a, b);
395 EnforceConstraints();
398 Initialize()
override;
401 InitializeKernelSigma();
404 InitializePatchWeights()
override;
407 InitializePatchWeightsSmoothDisc();
410 InitializeIteration()
override;
413 ComputeKernelBandwidthUpdate()
override;
417 virtual ThreadDataStruct
418 ThreadedComputeSigmaUpdate(
const InputImageRegionType & regionToProcess,
419 const int itkNotUsed(threadId),
420 ThreadDataStruct threadData);
422 virtual RealArrayType
423 ResolveSigmaUpdate();
426 ComputeImageUpdate()
override;
428 virtual ThreadDataStruct
429 ThreadedComputeImageUpdate(
const InputImageRegionType & regionToProcess,
431 ThreadDataStruct threadData);
434 ComputeGradientJointEntropy(InstanceIdentifier
id,
436 BaseSamplerPointer & sampler,
437 ThreadDataStruct & threadData);
440 ApplyUpdate()
override;
443 ThreadedApplyUpdate(
const InputImageRegionType & regionToProcess,
const int itkNotUsed(threadId));
446 PostProcessOutput()
override;
449 SetThreadData(
int threadId,
const ThreadDataStruct & data);
451 virtual ThreadDataStruct
452 GetThreadData(
int threadId);
458 ComputeSigmaUpdateThreaderCallback(
void * arg);
463 ComputeImageUpdateThreaderCallback(
void * arg);
468 ApplyUpdateThreaderCallback(
void * arg);
470 template <
typename TInputImageType>
472 DispatchedMinMax(
const TInputImageType * img);
474 template <
typename TInputImageType>
476 DispatchedArrayMinMax(
const TInputImageType * img);
478 template <
typename TInputImageType>
480 DispatchedVectorMinMax(
const TInputImageType * img);
482 template <
typename TInputImageType>
484 DispatchedRiemannianMinMax(
const TInputImageType * img);
489 RiemannianMinMaxThreaderCallback(
void * arg);
492 ThreadedRiemannianMinMax(
const InputImageRegionType & regionToProcess,
493 const int itkNotUsed(threadId),
494 const InputImageType * img,
495 ThreadDataStruct threadData);
498 ResolveRiemannianMinMax();
501 ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(
const PixelType & a,
503 const RealArrayType & weight,
504 bool useCachedComputations,
506 EigenValuesCacheType & eigenValsCache,
507 EigenVectorsCacheType & eigenVecsCache,
509 RealArrayType & norm);
515 const RealArrayType & weight,
516 bool useCachedComputations,
518 EigenValuesCacheType & eigenValsCache,
519 EigenVectorsCacheType & eigenVecsCache,
520 RealType & symMatrixLogMap,
521 RealArrayType & geodesicDist);
523 template <
typename TensorValueT>
530 AddEuclideanUpdate(
const RealType & a,
const RealType & b);
543 std::vector<ThreadDataStruct> m_ThreadData{};
548 unsigned int m_NumPixelComponents{ 0 };
549 unsigned int m_NumIndependentComponents{ 0 };
550 unsigned int m_TotalNumberPixels{ 0 };
552 bool m_UseSmoothDiscPatchWeights{
true };
554 bool m_UseFastTensorComputations{
true };
557 bool m_KernelBandwidthSigmaIsSet{
false };
559 PixelType m_ZeroPixel{};
562 double m_KernelBandwidthFractionPixelsForEstimation{ 0.20 };
563 bool m_ComputeConditionalDerivatives{
false };
565 double m_MinProbability{};
566 unsigned int m_SigmaUpdateDecimationFactor{};
567 double m_SigmaUpdateConvergenceTolerance{ 0.01 };
569 double m_KernelBandwidthMultiplicationFactor{ 1.0 };
573 bool m_NoiseSigmaIsSet{
false };
580 #ifndef ITK_MANUAL_INSTANTIATION
581 # include "itkPatchBasedDenoisingImageFilter.hxx"