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);
381 return this->AddEuclideanUpdate(a, b);
384 template <
typename RealT>
388 return this->AddEuclideanUpdate(a, b);
392 EnforceConstraints();
395 Initialize()
override;
398 InitializeKernelSigma();
401 InitializePatchWeights()
override;
404 InitializePatchWeightsSmoothDisc();
407 InitializeIteration()
override;
410 ComputeKernelBandwidthUpdate()
override;
414 virtual ThreadDataStruct
415 ThreadedComputeSigmaUpdate(
const InputImageRegionType & regionToProcess,
416 const int itkNotUsed(threadId),
417 ThreadDataStruct threadData);
419 virtual RealArrayType
420 ResolveSigmaUpdate();
423 ComputeImageUpdate()
override;
425 virtual ThreadDataStruct
426 ThreadedComputeImageUpdate(
const InputImageRegionType & regionToProcess,
428 ThreadDataStruct threadData);
431 ComputeGradientJointEntropy(InstanceIdentifier
id,
433 BaseSamplerPointer & sampler,
434 ThreadDataStruct & threadData);
437 ApplyUpdate()
override;
440 ThreadedApplyUpdate(
const InputImageRegionType & regionToProcess,
const int itkNotUsed(threadId));
443 PostProcessOutput()
override;
446 SetThreadData(
int threadId,
const ThreadDataStruct & data);
448 virtual ThreadDataStruct
449 GetThreadData(
int threadId);
455 ComputeSigmaUpdateThreaderCallback(
void * arg);
460 ComputeImageUpdateThreaderCallback(
void * arg);
465 ApplyUpdateThreaderCallback(
void * arg);
467 template <
typename TInputImageType>
469 DispatchedMinMax(
const TInputImageType * img);
471 template <
typename TInputImageType>
473 DispatchedArrayMinMax(
const TInputImageType * img);
475 template <
typename TInputImageType>
477 DispatchedVectorMinMax(
const TInputImageType * img);
479 template <
typename TInputImageType>
481 DispatchedRiemannianMinMax(
const TInputImageType * img);
486 RiemannianMinMaxThreaderCallback(
void * arg);
489 ThreadedRiemannianMinMax(
const InputImageRegionType & regionToProcess,
490 const int itkNotUsed(threadId),
491 const InputImageType * img,
492 ThreadDataStruct threadData);
495 ResolveRiemannianMinMax();
498 ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(
const PixelType & a,
500 const RealArrayType & weight,
501 bool useCachedComputations,
503 EigenValuesCacheType & eigenValsCache,
504 EigenVectorsCacheType & eigenVecsCache,
506 RealArrayType & norm);
512 const RealArrayType & weight,
513 bool useCachedComputations,
515 EigenValuesCacheType & eigenValsCache,
516 EigenVectorsCacheType & eigenVecsCache,
517 RealType & symMatrixLogMap,
518 RealArrayType & geodesicDist);
520 template <
typename TensorValueT>
527 AddEuclideanUpdate(
const RealType & a,
const RealType & b);
540 std::vector<ThreadDataStruct> m_ThreadData{};
545 unsigned int m_NumPixelComponents{ 0 };
546 unsigned int m_NumIndependentComponents{ 0 };
547 unsigned int m_TotalNumberPixels{ 0 };
549 bool m_UseSmoothDiscPatchWeights{
true };
551 bool m_UseFastTensorComputations{
true };
554 bool m_KernelBandwidthSigmaIsSet{
false };
556 PixelType m_ZeroPixel{};
559 double m_KernelBandwidthFractionPixelsForEstimation{ 0.20 };
560 bool m_ComputeConditionalDerivatives{
false };
562 double m_MinProbability{};
563 unsigned int m_SigmaUpdateDecimationFactor{};
564 double m_SigmaUpdateConvergenceTolerance{ 0.01 };
566 double m_KernelBandwidthMultiplicationFactor{ 1.0 };
570 bool m_NoiseSigmaIsSet{
false };
577 #ifndef ITK_MANUAL_INSTANTIATION
578 # include "itkPatchBasedDenoisingImageFilter.hxx"