18 #ifndef itkPatchBasedDenoisingImageFilter_h
19 #define itkPatchBasedDenoisingImageFilter_h
32 #include <type_traits>
59 template <
typename TInputImage,
typename TOutputImage>
85 static constexpr
unsigned int ImageDimension = Superclass::ImageDimension;
145 itkSetMacro(UseSmoothDiscPatchWeights,
bool);
146 itkBooleanMacro(UseSmoothDiscPatchWeights);
147 itkGetConstMacro(UseSmoothDiscPatchWeights,
bool);
154 void SetKernelBandwidthSigma(
const RealArrayType& kernelSigma);
162 itkSetClampMacro(KernelBandwidthFractionPixelsForEstimation,
double, 0.01, 1.0);
163 itkGetConstReferenceMacro(KernelBandwidthFractionPixelsForEstimation,
double);
168 itkSetMacro(ComputeConditionalDerivatives,
bool);
169 itkBooleanMacro(ComputeConditionalDerivatives);
170 itkGetConstMacro(ComputeConditionalDerivatives,
bool);
186 itkSetMacro(UseFastTensorComputations,
bool);
187 itkBooleanMacro(UseFastTensorComputations);
188 itkGetConstMacro(UseFastTensorComputations,
bool);
192 static constexpr
unsigned int MaxSigmaUpdateIterations = 20;
200 itkSetClampMacro(KernelBandwidthMultiplicationFactor,
double, 0.01, 100);
201 itkGetConstReferenceMacro(KernelBandwidthMultiplicationFactor,
double);
207 void SetNoiseSigma(
const RealType& sigma);
209 itkGetConstMacro(NoiseSigma,
RealType);
217 itkGetConstMacro(NumIndependentComponents,
unsigned int);
222 void PrintSelf(std::ostream& os,
Indent indent)
const override;
225 virtual void EmptyCaches();
228 void AllocateUpdateBuffer()
override;
230 void CopyInputToOutput()
override;
232 void GenerateInputRequestedRegion()
override;
235 typename std::enable_if<std::is_same<T, typename NumericTraits<T>::ValueType>::value, U >;
238 typename std::enable_if<!std::is_same<T, typename NumericTraits<T>::ValueType>::value, U >;
247 template<
typename T>
250 unsigned int itkNotUsed( idx ) )
const
261 template<
typename T>
262 typename EnableIfMultiComponent<T, typename NumericTraits<T>::ValueType>::type
264 unsigned int idx )
const
270 template<
typename T >
273 unsigned int itkNotUsed( idx ),
279 template<
typename T >
293 if( this->GetComponentSpace() == Superclass::RIEMANNIAN )
295 DispatchedRiemannianMinMax(img);
299 DispatchedArrayMinMax(img);
303 template<
typename TImageType >
304 typename DisableIfMultiComponent<typename TImageType::PixelType>::type
307 DispatchedMinMax(img);
310 template<
typename TImageType >
311 typename EnableIfMultiComponent<typename TImageType::PixelType>::type
314 DispatchedArrayMinMax(img);
328 bool useCachedComputations,
334 if( this->GetComponentSpace() == Superclass::RIEMANNIAN )
336 ComputeLogMapAndWeightedSquaredGeodesicDifference(a, b, weight,
337 useCachedComputations, cacheIndex,
338 eigenValsCache, eigenVecsCache,
343 ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(a, b, weight,
344 useCachedComputations, cacheIndex,
345 eigenValsCache, eigenVecsCache,
351 template <
typename PixelT>
355 bool useCachedComputations,
361 ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(a, b, weight,
362 useCachedComputations, cacheIndex,
363 eigenValsCache, eigenVecsCache,
373 if( this->GetComponentSpace() == Superclass::RIEMANNIAN )
375 return this->AddExponentialMapUpdate(a, b);
379 return this->AddEuclideanUpdate(a, b);
384 template <
typename RealT>
388 return this->AddEuclideanUpdate(a, b);
391 virtual void EnforceConstraints();
393 void Initialize()
override;
395 virtual void InitializeKernelSigma();
397 void InitializePatchWeights()
override;
399 virtual void InitializePatchWeightsSmoothDisc();
401 void InitializeIteration()
override;
403 void ComputeKernelBandwidthUpdate()
override;
407 virtual ThreadDataStruct ThreadedComputeSigmaUpdate(
const InputImageRegionType& regionToProcess,
408 const int itkNotUsed(threadId),
409 ThreadDataStruct threadData);
411 virtual RealArrayType ResolveSigmaUpdate();
413 void ComputeImageUpdate()
override;
415 virtual ThreadDataStruct ThreadedComputeImageUpdate(
const InputImageRegionType& regionToProcess,
417 ThreadDataStruct threadData);
419 virtual RealType ComputeGradientJointEntropy(InstanceIdentifier
id,
420 typename ListAdaptorType::Pointer& inList,
421 BaseSamplerPointer& sampler,
422 ThreadDataStruct& threadData);
424 void ApplyUpdate()
override;
426 virtual void ThreadedApplyUpdate(
const InputImageRegionType& regionToProcess,
427 const int itkNotUsed(threadId) );
429 void PostProcessOutput()
override;
431 virtual void SetThreadData(
int threadId,
const ThreadDataStruct& data);
433 virtual ThreadDataStruct GetThreadData(
int threadId);
448 template <
typename TInputImageType>
449 void DispatchedMinMax(
const TInputImageType* img);
451 template <
typename TInputImageType>
452 void DispatchedArrayMinMax(
const TInputImageType* img);
454 template <
typename TInputImageType>
455 void DispatchedVectorMinMax(
const TInputImageType* img);
457 template <
typename TInputImageType>
458 void DispatchedRiemannianMinMax(
const TInputImageType* img);
464 ThreadDataStruct ThreadedRiemannianMinMax(
const InputImageRegionType& regionToProcess,
465 const int itkNotUsed(threadId),
466 const InputImageType* img,
467 ThreadDataStruct threadData);
469 virtual void ResolveRiemannianMinMax();
471 void ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(
const PixelType& a,
const PixelType& b,
472 const RealArrayType& weight,
473 bool useCachedComputations,
475 EigenValuesCacheType& eigenValsCache,
476 EigenVectorsCacheType& eigenVecsCache,
477 RealType& diff, RealArrayType& norm);
482 const RealArrayType& weight,
483 bool useCachedComputations,
485 EigenValuesCacheType& eigenValsCache,
486 EigenVectorsCacheType& eigenVecsCache,
487 RealType& symMatrixLogMap, RealArrayType& geodesicDist);
489 template <
typename TensorValueT>
494 RealType AddEuclideanUpdate(
const RealType& a,
const RealType& b);
511 unsigned int m_NumPixelComponents{ 0 };
512 unsigned int m_NumIndependentComponents{ 0 };
513 unsigned int m_TotalNumberPixels{ 0 };
515 bool m_UseSmoothDiscPatchWeights{
true };
517 bool m_UseFastTensorComputations{
true };
520 bool m_KernelBandwidthSigmaIsSet{
false };
525 double m_KernelBandwidthFractionPixelsForEstimation{ 0.20 };
526 bool m_ComputeConditionalDerivatives{
false };
530 double m_SigmaUpdateConvergenceTolerance{ 0.01 };
532 double m_KernelBandwidthMultiplicationFactor{ 1.0 };
536 bool m_NoiseSigmaIsSet{
false };
543 #ifndef ITK_MANUAL_INSTANTIATION
544 #include "itkPatchBasedDenoisingImageFilter.hxx"
ListAdaptorType::Pointer m_SearchSpaceList
A templated class holding a M x N size Matrix.
Derived class implementing a specific patch-based denoising algorithm, as detailed below...
PatchBasedDenoisingImageFilter * Filter
std::vector< EigenValuesArrayType > EigenValuesCacheType
typename TSample::InstanceIdentifier InstanceIdentifier
typename OutputImageType::Pointer OutputImagePointer
BaseSamplerPointer m_Sampler
Define numeric traits for std::vector.
RealArrayType entropyFirstDerivative
void ComputeDifferenceAndWeightedSquaredNorm(const PixelT &a, const PixelT &b, const RealArrayType &weight, bool useCachedComputations, SizeValueType cacheIndex, EigenValuesCacheType &eigenValsCache, EigenVectorsCacheType &eigenVecsCache, RealType &diff, RealArrayType &norm)
OutputImageType::Pointer m_UpdateBuffer
void SetComponent(T &pix, unsigned int, typename DisableIfMultiComponent< T, RealValueType >::type val) const
A method to generically set a component.
OutputPixelType PixelType
Base class for patch-based denoising algorithms.
unsigned long SizeValueType
DisableIfMultiComponent< typename TImageType::PixelType >::type ComputeMinMax(const TImageType *img)
typename Superclass::InputImageType InputImageType
RealArrayType m_IntensityRescaleInvFactor
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
itk::ITK_THREAD_RETURN_TYPE ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
Base class for all process objects that output image data.
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
EigenValuesCacheType eigenValsCache
RealArrayType m_KernelBandwidthSigma
typename NumericTraits< PixelType >::RealType RealType
typename std::enable_if<!std::is_same< T, typename NumericTraits< T >::ValueType >::value, U > EnableIfMultiComponent
typename::itk::Statistics::ImageToNeighborhoodSampleAdaptor< OutputImageType, BoundaryConditionType > ListAdaptorType
TInputImage InputImageType
Simulate a standard C array with copy semnatics.
PixelArrayType m_ImageMin
typename BaseSamplerType::Pointer BaseSamplerPointer
EnableIfMultiComponent< T, typename NumericTraits< T >::ValueType >::type GetComponent(const T &pix, unsigned int idx) const
typename NumericTraits< PixelType >::ValueType PixelValueType
RealType AddUpdate(const DiffusionTensor3D< RealValueType > &a, const RealType &b)
EigenVectorsCacheType eigenVecsCache
typename std::enable_if< std::is_same< T, typename NumericTraits< T >::ValueType >::value, U > DisableIfMultiComponent
EnableIfMultiComponent< typename TImageType::PixelType >::type ComputeMinMax(const TImageType *img)
void ComputeMinMax(const Image< DiffusionTensor3D< PixelValueType >, ImageDimension > *img)
This an abstract subsampler that constrains subsamples to be contained within a given image region...
A multi-dimensional iterator templated over image type that walks a region of pixels.
TOutputImage OutputImageType
RealType m_NoiseSigmaSquared
ListAdaptorType PatchSampleType
ShortArrayType validDerivatives
DisableIfMultiComponent< T, T >::type GetComponent(const T pix, unsigned int) const
A method to generically get a component.
BaseSamplerPointer sampler
std::vector< ThreadDataStruct > m_ThreadData
RealArrayType entropySecondDerivative
typename InputImageType::RegionType InputImageRegionType
ShortArrayType validNorms
typename NumericTraits< PixelValueType >::RealType RealValueType
void SetComponent(T &pix, unsigned int idx, typename EnableIfMultiComponent< T, RealValueType >::type val) const
Control indentation during Print() invocation.
ShortArrayType m_SigmaConverged
typename ListAdaptorType::NeighborhoodRadiusType PatchRadiusType
PixelArrayType m_ImageMax
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)
ImageBaseType::RegionType RegionType
Represent a diffusion tensor as used in DTI images.
std::vector< EigenVectorsMatrixType > EigenVectorsCacheType
Templated n-dimensional image class.
A multi-dimensional iterator templated over image type that walks a region of pixels.
unsigned int m_SigmaUpdateDecimationFactor
RealType AddUpdate(const RealT &a, const RealType &b)
typename BaseSamplerType::InstanceIdentifier InstanceIdentifier