18#ifndef itkPatchBasedDenoisingImageFilter_h
19#define itkPatchBasedDenoisingImageFilter_h
35#include "ITKDenoisingExport.h"
61template <
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);
220 itkGetConstMacro(NumIndependentComponents,
unsigned int);
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);
419 const int itkNotUsed(threadId),
470 template <
typename TInputImageType>
474 template <
typename TInputImageType>
478 template <
typename TInputImageType>
482 template <
typename TInputImageType>
493 const int itkNotUsed(threadId),
504 bool useCachedComputations,
516 bool useCachedComputations,
523 template <
typename TensorValueT>
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 };
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"
Represent a diffusion tensor as used in DTI images.
Simulate a standard C array with copy semantics.
A multi-dimensional iterator templated over image type that walks a region of pixels.
A multi-dimensional iterator templated over image type that walks a region of pixels.
Base class for all process objects that output image data.
TInputImage InputImageType
typename InputImageType::RegionType InputImageRegionType
Templated n-dimensional image class.
Control indentation during Print() invocation.
A templated class holding a M x N size Matrix.
Define additional traits for native types such as int or float.
Base class for patch-based denoising algorithms.
typename itk::Statistics::ImageToNeighborhoodSampleAdaptor< OutputImageType, BoundaryConditionType > ListAdaptorType
OutputPixelType PixelType
Derived class implementing a specific patch-based denoising algorithm, as detailed below.
void DispatchedArrayMinMax(const TInputImageType *img)
virtual void EmptyCaches()
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION RiemannianMinMaxThreaderCallback(void *arg)
void Compute3x3EigenAnalysis(const DiffusionTensor3D< TensorValueT > &spdMatrix, FixedArray< TensorValueT, 3 > &eigenVals, Matrix< TensorValueT, 3, 3 > &eigenVecs)
void PrintSelf(std::ostream &os, Indent indent) const override
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ComputeImageUpdateThreaderCallback(void *arg)
void DispatchedMinMax(const TInputImageType *img)
DisableIfMultiComponent< typenameTImageType::PixelType >::type ComputeMinMax(const TImageType *img)
void ComputeDifferenceAndWeightedSquaredNorm(const DiffusionTensor3D< PixelValueType > &a, const DiffusionTensor3D< PixelValueType > &b, const RealArrayType &weight, bool useCachedComputations, SizeValueType cacheIndex, EigenValuesCacheType &eigenValsCache, EigenVectorsCacheType &eigenVecsCache, RealType &diff, RealArrayType &norm)
ListAdaptorType PatchSampleType
void ComputeMinMax(const Image< DiffusionTensor3D< PixelValueType >, ImageDimension > *img)
virtual ThreadDataStruct ThreadedComputeSigmaUpdate(const InputImageRegionType ®ionToProcess, const int, ThreadDataStruct threadData)
virtual void InitializeKernelSigma()
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ApplyUpdateThreaderCallback(void *arg)
DisableIfMultiComponent< T, T >::type GetComponent(const T pix, unsigned int) const
A method to generically get a component.
virtual ThreadDataStruct ThreadedComputeImageUpdate(const InputImageRegionType ®ionToProcess, const int threadId, ThreadDataStruct threadData)
virtual void SetThreadData(int threadId, const ThreadDataStruct &data)
void ComputeLogMapAndWeightedSquaredGeodesicDifference(const DiffusionTensor3D< PixelValueType > &spdMatrixA, const DiffusionTensor3D< PixelValueType > &spdMatrixB, const RealArrayType &weight, bool useCachedComputations, SizeValueType cacheIndex, EigenValuesCacheType &eigenValsCache, EigenVectorsCacheType &eigenVecsCache, RealType &symMatrixLogMap, RealArrayType &geodesicDist)
void ComputeImageUpdate() override
std::vector< EigenVectorsMatrixType > EigenVectorsCacheType
void PostProcessOutput() override
virtual void InitializePatchWeightsSmoothDisc()
typename std::enable_if<!std::is_same_v< T, typename NumericTraits< T >::ValueType >, U > EnableIfMultiComponent
RealType AddUpdate(const RealT &a, const RealType &b)
typename BaseSamplerType::Pointer BaseSamplerPointer
PatchBasedDenoisingImageFilter()
void CopyInputToOutput() override
virtual ThreadDataStruct GetThreadData(int threadId)
void ComputeKernelBandwidthUpdate() override
void InitializePatchWeights() override
void SetKernelBandwidthSigma(const RealArrayType &kernelSigma)
void InitializeIteration() override
void ApplyUpdate() override
RealType AddExponentialMapUpdate(const DiffusionTensor3D< RealValueType > &spdMatrix, const DiffusionTensor3D< RealValueType > &symMatrix)
virtual void ResolveRiemannianMinMax()
void ComputeDifferenceAndWeightedSquaredNorm(const PixelT &a, const PixelT &b, const RealArrayType &weight, bool useCachedComputations, SizeValueType cacheIndex, EigenValuesCacheType &eigenValsCache, EigenVectorsCacheType &eigenVecsCache, RealType &diff, RealArrayType &norm)
~PatchBasedDenoisingImageFilter() override
virtual void EnforceConstraints()
RealType AddEuclideanUpdate(const RealType &a, const RealType &b)
void ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(const PixelType &a, const PixelType &b, const RealArrayType &weight, bool useCachedComputations, SizeValueType cacheIndex, EigenValuesCacheType &eigenValsCache, EigenVectorsCacheType &eigenVecsCache, RealType &diff, RealArrayType &norm)
typename std::enable_if< std::is_same_v< T, typename NumericTraits< T >::ValueType >, U > DisableIfMultiComponent
virtual void ThreadedApplyUpdate(const InputImageRegionType ®ionToProcess, const int)
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ComputeSigmaUpdateThreaderCallback(void *arg)
void SetComponent(T &pix, unsigned int idx, typename EnableIfMultiComponent< T, RealValueType >::type val) const
void Initialize() override
EnableIfMultiComponent< T, typenameNumericTraits< T >::ValueType >::type GetComponent(const T &pix, unsigned int idx) const
typename NumericTraits< PixelValueType >::RealType RealValueType
EnableIfMultiComponent< typenameTImageType::PixelType >::type ComputeMinMax(const TImageType *img)
void AllocateUpdateBuffer() override
void SetNoiseSigma(const RealType &sigma)
typename NumericTraits< PixelType >::RealType RealType
std::vector< EigenValuesArrayType > EigenValuesCacheType
typename BaseSamplerType::InstanceIdentifier InstanceIdentifier
void SetComponent(T &pix, unsigned int, typename DisableIfMultiComponent< T, RealValueType >::type val) const
A method to generically set a component.
virtual RealArrayType ResolveSigmaUpdate()
void DispatchedVectorMinMax(const TInputImageType *img)
void DispatchedRiemannianMinMax(const TInputImageType *img)
virtual RealType ComputeGradientJointEntropy(InstanceIdentifier id, typename ListAdaptorType::Pointer &inList, BaseSamplerPointer &sampler, ThreadDataStruct &threadData)
void GenerateInputRequestedRegion() override
ThreadDataStruct ThreadedRiemannianMinMax(const InputImageRegionType ®ionToProcess, const int, const InputImageType *img, ThreadDataStruct threadData)
RealType AddUpdate(const DiffusionTensor3D< RealValueType > &a, const RealType &b)
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
This an abstract subsampler that constrains subsamples to be contained within a given image region.
typename TSample::InstanceIdentifier InstanceIdentifier
SmartPointer< Self > Pointer
ImageBaseType::RegionType RegionType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
itk::ITK_THREAD_RETURN_TYPE ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
RealArrayType entropySecondDerivative
EigenValuesCacheType eigenValsCache
BaseSamplerPointer sampler
ShortArrayType validDerivatives
EigenVectorsCacheType eigenVecsCache
ShortArrayType validNorms
RealArrayType entropyFirstDerivative
PatchBasedDenoisingImageFilter * Filter