18 #ifndef itkPatchBasedDenoisingImageFilter_h
19 #define itkPatchBasedDenoisingImageFilter_h
32 #include <type_traits>
35 #include "ITKDenoisingExport.h"
61 template <
typename TInputImage,
typename TOutputImage>
87 static constexpr
unsigned int ImageDimension = Superclass::ImageDimension;
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>
244 typename std::enable_if<std::is_same<T, typename NumericTraits<T>::ValueType>::value, U>;
246 template <
typename T,
typename U =
void>
248 typename std::enable_if<!std::is_same<T, typename NumericTraits<T>::ValueType>::value, U>;
257 template <
typename T>
270 template <
typename T>
271 typename EnableIfMultiComponent<T, typename NumericTraits<T>::ValueType>::type
278 template <
typename T>
281 unsigned int itkNotUsed(idx),
287 template <
typename T>
300 if (this->GetComponentSpace() == Superclass::ComponentSpaceEnum::RIEMANNIAN)
302 DispatchedRiemannianMinMax(img);
306 DispatchedArrayMinMax(img);
310 template <
typename TImageType>
311 typename DisableIfMultiComponent<typename TImageType::PixelType>::type
314 DispatchedMinMax(img);
317 template <
typename TImageType>
318 typename EnableIfMultiComponent<typename TImageType::PixelType>::type
321 DispatchedArrayMinMax(img);
336 bool useCachedComputations,
343 if (this->GetComponentSpace() == Superclass::ComponentSpaceEnum::RIEMANNIAN)
345 ComputeLogMapAndWeightedSquaredGeodesicDifference(
346 a, b, weight, useCachedComputations, cacheIndex, eigenValsCache, eigenVecsCache, diff, norm);
350 ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(
351 a, b, weight, useCachedComputations, cacheIndex, eigenValsCache, eigenVecsCache, diff, norm);
356 template <
typename PixelT>
361 bool useCachedComputations,
368 ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(
369 a, b, weight, useCachedComputations, cacheIndex, eigenValsCache, eigenVecsCache, diff, norm);
378 if (this->GetComponentSpace() == Superclass::ComponentSpaceEnum::RIEMANNIAN)
380 return this->AddExponentialMapUpdate(a, b);
384 return this->AddEuclideanUpdate(a, b);
389 template <
typename RealT>
393 return this->AddEuclideanUpdate(a, b);
397 EnforceConstraints();
400 Initialize()
override;
403 InitializeKernelSigma();
406 InitializePatchWeights()
override;
409 InitializePatchWeightsSmoothDisc();
412 InitializeIteration()
override;
415 ComputeKernelBandwidthUpdate()
override;
419 virtual ThreadDataStruct
420 ThreadedComputeSigmaUpdate(
const InputImageRegionType & regionToProcess,
421 const int itkNotUsed(threadId),
422 ThreadDataStruct threadData);
424 virtual RealArrayType
425 ResolveSigmaUpdate();
428 ComputeImageUpdate()
override;
430 virtual ThreadDataStruct
431 ThreadedComputeImageUpdate(
const InputImageRegionType & regionToProcess,
433 ThreadDataStruct threadData);
436 ComputeGradientJointEntropy(InstanceIdentifier
id,
437 typename ListAdaptorType::Pointer & inList,
438 BaseSamplerPointer & sampler,
439 ThreadDataStruct & threadData);
442 ApplyUpdate()
override;
445 ThreadedApplyUpdate(
const InputImageRegionType & regionToProcess,
const int itkNotUsed(threadId));
448 PostProcessOutput()
override;
451 SetThreadData(
int threadId,
const ThreadDataStruct & data);
453 virtual ThreadDataStruct
454 GetThreadData(
int threadId);
460 ComputeSigmaUpdateThreaderCallback(
void * arg);
465 ComputeImageUpdateThreaderCallback(
void * arg);
470 ApplyUpdateThreaderCallback(
void * arg);
472 template <
typename TInputImageType>
474 DispatchedMinMax(
const TInputImageType * img);
476 template <
typename TInputImageType>
478 DispatchedArrayMinMax(
const TInputImageType * img);
480 template <
typename TInputImageType>
482 DispatchedVectorMinMax(
const TInputImageType * img);
484 template <
typename TInputImageType>
486 DispatchedRiemannianMinMax(
const TInputImageType * img);
491 RiemannianMinMaxThreaderCallback(
void * arg);
494 ThreadedRiemannianMinMax(
const InputImageRegionType & regionToProcess,
495 const int itkNotUsed(threadId),
496 const InputImageType * img,
497 ThreadDataStruct threadData);
500 ResolveRiemannianMinMax();
503 ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(
const PixelType & a,
505 const RealArrayType & weight,
506 bool useCachedComputations,
508 EigenValuesCacheType & eigenValsCache,
509 EigenVectorsCacheType & eigenVecsCache,
511 RealArrayType & norm);
517 const RealArrayType & weight,
518 bool useCachedComputations,
520 EigenValuesCacheType & eigenValsCache,
521 EigenVectorsCacheType & eigenVecsCache,
522 RealType & symMatrixLogMap,
523 RealArrayType & geodesicDist);
525 template <
typename TensorValueT>
532 AddEuclideanUpdate(
const RealType & a,
const RealType & b);
550 unsigned int m_NumPixelComponents{ 0 };
551 unsigned int m_NumIndependentComponents{ 0 };
552 unsigned int m_TotalNumberPixels{ 0 };
554 bool m_UseSmoothDiscPatchWeights{
true };
556 bool m_UseFastTensorComputations{
true };
559 bool m_KernelBandwidthSigmaIsSet{
false };
564 double m_KernelBandwidthFractionPixelsForEstimation{ 0.20 };
565 bool m_ComputeConditionalDerivatives{
false };
569 double m_SigmaUpdateConvergenceTolerance{ 0.01 };
571 double m_KernelBandwidthMultiplicationFactor{ 1.0 };
575 bool m_NoiseSigmaIsSet{
false };
582 #ifndef ITK_MANUAL_INSTANTIATION
583 # include "itkPatchBasedDenoisingImageFilter.hxx"