ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkPatchBasedDenoisingImageFilter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkPatchBasedDenoisingImageFilter_h
19#define itkPatchBasedDenoisingImageFilter_h
20
24#include "itkVector.h"
25#include "itkVectorImage.h"
26#include "itkRGBPixel.h"
27#include "itkRGBAPixel.h"
29#include "itkFixedArray.h"
30#include "itkMatrix.h"
32#include <type_traits>
33
34#include <vector>
35#include "ITKDenoisingExport.h"
36
37namespace itk
38{
61template <typename TInputImage, typename TOutputImage>
62class ITK_TEMPLATE_EXPORT PatchBasedDenoisingImageFilter
63 : public PatchBasedDenoisingBaseImageFilter<TInputImage, TOutputImage>
64{
65public:
66 ITK_DISALLOW_COPY_AND_MOVE(PatchBasedDenoisingImageFilter);
68
74 using typename Superclass::OutputImagePointer;
75
77 itkNewMacro(Self);
78
80 itkOverrideGetNameOfClassMacro(PatchBasedDenoisingImageFilter);
81
83 using typename Superclass::InputImageType;
84 using typename Superclass::OutputImageType;
85
87 static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
88
90 using InputImageRegionType = typename InputImageType::RegionType;
91
95
98 using typename Superclass::PixelType;
99 using typename Superclass::PixelValueType;
100
106
108 using typename Superclass::ListAdaptorType;
109 using typename Superclass::PatchRadiusType;
112 using typename Superclass::PatchWeightsType;
113
118
126 using EigenValuesCacheType = std::vector<EigenValuesArrayType>;
127 using EigenVectorsCacheType = std::vector<EigenVectorsMatrixType>;
128
141
146 itkSetMacro(UseSmoothDiscPatchWeights, bool);
147 itkBooleanMacro(UseSmoothDiscPatchWeights);
148 itkGetConstMacro(UseSmoothDiscPatchWeights, bool);
150
155 void
157 itkGetConstMacro(KernelBandwidthSigma, RealArrayType);
159
164 itkSetClampMacro(KernelBandwidthFractionPixelsForEstimation, double, 0.01, 1.0);
165 itkGetConstReferenceMacro(KernelBandwidthFractionPixelsForEstimation, double);
167
170 itkSetMacro(ComputeConditionalDerivatives, bool);
171 itkBooleanMacro(ComputeConditionalDerivatives);
172 itkGetConstMacro(ComputeConditionalDerivatives, bool);
174
186 itkSetMacro(UseFastTensorComputations, bool);
187 itkBooleanMacro(UseFastTensorComputations);
188 itkGetConstMacro(UseFastTensorComputations, bool);
190
192 static constexpr unsigned int MaxSigmaUpdateIterations = 20;
193
200 itkSetClampMacro(KernelBandwidthMultiplicationFactor, double, 0.01, 100);
201 itkGetConstReferenceMacro(KernelBandwidthMultiplicationFactor, double);
203
207 void
208 SetNoiseSigma(const RealType & sigma);
209
210 itkGetConstMacro(NoiseSigma, RealType);
211
213 itkSetObjectMacro(Sampler, BaseSamplerType);
214 itkGetModifiableObjectMacro(Sampler, BaseSamplerType);
216
218 itkGetConstMacro(NumIndependentComponents, unsigned int);
219
220protected:
223 void
224 PrintSelf(std::ostream & os, Indent indent) const override;
225
227 virtual void
229
231 void
233
234 void
236
237 void
239
240 template <typename T, typename U = void>
241 using DisableIfMultiComponent = typename std::enable_if<std::is_same_v<T, typename NumericTraits<T>::ValueType>, U>;
242
243 template <typename T, typename U = void>
244 using EnableIfMultiComponent = typename std::enable_if<!std::is_same_v<T, typename NumericTraits<T>::ValueType>, U>;
245
246
253 template <typename T>
255 GetComponent(const T pix, unsigned int itkNotUsed(idx)) const
256 {
257 // The enable if idiom is used to overload this method for both
258 // scalars and multi-component types. By exploiting that
259 // NumericTraits' ValueType type alias (defines the per-element type
260 // for multi-component types ) is different then the parameterize
261 // type, the bracket operator is used only for multi-component
262 // types.
263 return pix;
264 }
265
266 template <typename T>
267 typename EnableIfMultiComponent<T, typename NumericTraits<T>::ValueType>::type
268 GetComponent(const T & pix, unsigned int idx) const
269 {
270 return pix[idx];
271 }
272
274 template <typename T>
275 void
277 unsigned int itkNotUsed(idx),
279 {
280 pix = val;
281 }
282
283 template <typename T>
284 void
285 SetComponent(T & pix, unsigned int idx, typename EnableIfMultiComponent<T, RealValueType>::type val) const
286 {
287 pix[idx] = val;
288 }
289
292
293 void
295 {
296 if (this->GetComponentSpace() == Superclass::ComponentSpaceEnum::RIEMANNIAN)
297 {
299 }
300 else
301 {
303 }
304 }
305
306 template <typename TImageType>
307 typename DisableIfMultiComponent<typename TImageType::PixelType>::type
308 ComputeMinMax(const TImageType * img)
309 {
310 DispatchedMinMax(img);
311 }
312
313 template <typename TImageType>
314 typename EnableIfMultiComponent<typename TImageType::PixelType>::type
315 ComputeMinMax(const TImageType * img)
316 {
318 }
319
328 void
331 const RealArrayType & weight,
332 bool useCachedComputations,
333 SizeValueType cacheIndex,
334 EigenValuesCacheType & eigenValsCache,
335 EigenVectorsCacheType & eigenVecsCache,
336 RealType & diff,
337 RealArrayType & norm)
338 {
339 if (this->GetComponentSpace() == Superclass::ComponentSpaceEnum::RIEMANNIAN)
340 {
342 a, b, weight, useCachedComputations, cacheIndex, eigenValsCache, eigenVecsCache, diff, norm);
343 }
344 else
345 {
347 a, b, weight, useCachedComputations, cacheIndex, eigenValsCache, eigenVecsCache, diff, norm);
348 }
349 }
350
351
352 template <typename PixelT>
353 void
355 const PixelT & b,
356 const RealArrayType & weight,
357 bool useCachedComputations,
358 SizeValueType cacheIndex,
359 EigenValuesCacheType & eigenValsCache,
360 EigenVectorsCacheType & eigenVecsCache,
361 RealType & diff,
362 RealArrayType & norm)
363 {
365 a, b, weight, useCachedComputations, cacheIndex, eigenValsCache, eigenVecsCache, diff, norm);
366 }
367
373 {
374 if (this->GetComponentSpace() == Superclass::ComponentSpaceEnum::RIEMANNIAN)
375 {
376 return this->AddExponentialMapUpdate(a, b);
377 }
378
379 return this->AddEuclideanUpdate(a, b);
380 }
381
382 template <typename RealT>
384 AddUpdate(const RealT & a, const RealType & b)
385 {
386 return this->AddEuclideanUpdate(a, b);
387 }
388
389 virtual void
391
392 void
393 Initialize() override;
394
395 virtual void
397
398 void
400
401 virtual void
403
404 void
406
407 void
408 ComputeKernelBandwidthUpdate() override; // derived from base class;
409
410 // define here
411
412 virtual ThreadDataStruct
414 const int itkNotUsed(threadId),
415 ThreadDataStruct threadData);
416
417 virtual RealArrayType
419
420 void
422
423 virtual ThreadDataStruct
425 const int threadId,
426 ThreadDataStruct threadData);
427
428 virtual RealType
430 typename ListAdaptorType::Pointer & inList,
431 BaseSamplerPointer & sampler,
432 ThreadDataStruct & threadData);
433
434 void
435 ApplyUpdate() override;
436
437 virtual void
438 ThreadedApplyUpdate(const InputImageRegionType & regionToProcess, const int itkNotUsed(threadId));
439
440 void
442 {}
443
444 virtual void
445 SetThreadData(int threadId, const ThreadDataStruct & data);
446
447 virtual ThreadDataStruct
448 GetThreadData(int threadId);
449
450private:
455
460
465
466 template <typename TInputImageType>
467 void
468 DispatchedMinMax(const TInputImageType * img);
469
470 template <typename TInputImageType>
471 void
472 DispatchedArrayMinMax(const TInputImageType * img);
473
474 template <typename TInputImageType>
475 void
476 DispatchedVectorMinMax(const TInputImageType * img);
477
478 template <typename TInputImageType>
479 void
480 DispatchedRiemannianMinMax(const TInputImageType * img);
481
486
489 const int itkNotUsed(threadId),
490 const InputImageType * img,
491 ThreadDataStruct threadData);
492
493 virtual void
495
496 void
498 const PixelType & b,
499 const RealArrayType & weight,
500 bool useCachedComputations,
501 SizeValueType cacheIndex,
502 EigenValuesCacheType & eigenValsCache,
503 EigenVectorsCacheType & eigenVecsCache,
504 RealType & diff,
505 RealArrayType & norm);
506
508 void
510 const DiffusionTensor3D<PixelValueType> & spdMatrixB,
511 const RealArrayType & weight,
512 bool useCachedComputations,
513 SizeValueType cacheIndex,
514 EigenValuesCacheType & eigenValsCache,
515 EigenVectorsCacheType & eigenVecsCache,
516 RealType & symMatrixLogMap,
517 RealArrayType & geodesicDist);
518
519 template <typename TensorValueT>
520 void
522 FixedArray<TensorValueT, 3> & eigenVals,
523 Matrix<TensorValueT, 3, 3> & eigenVecs);
524
526 AddEuclideanUpdate(const RealType & a, const RealType & b);
527
531 const DiffusionTensor3D<RealValueType> & symMatrix);
532
538
539 std::vector<ThreadDataStruct> m_ThreadData{};
540
542 typename OutputImageType::Pointer m_UpdateBuffer{};
543
544 unsigned int m_NumPixelComponents{ 0 };
545 unsigned int m_NumIndependentComponents{ 0 };
546 unsigned int m_TotalNumberPixels{ 0 };
547
549
551
560 double m_MinSigma{};
566
569 bool m_NoiseSigmaIsSet{ false };
570
572 typename ListAdaptorType::Pointer m_SearchSpaceList{};
573};
574} // end namespace itk
575
576#ifndef ITK_MANUAL_INSTANTIATION
577# include "itkPatchBasedDenoisingImageFilter.hxx"
578#endif
579
580#endif
Array class with size defined at construction time.
Definition itkArray.h:48
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.
typename OutputImageType::Pointer OutputImagePointer
Templated n-dimensional image class.
Definition itkImage.h:89
Control indentation during Print() invocation.
Definition itkIndent.h:50
A templated class holding a M x N size Matrix.
Definition itkMatrix.h:53
typename NumericTraits< PixelType >::ValueType PixelValueType
typename itk::Statistics::ImageToNeighborhoodSampleAdaptor< OutputImageType, BoundaryConditionType > ListAdaptorType
virtual ComponentSpaceEnum GetComponentSpace() const
typename ListAdaptorType::NeighborhoodRadiusType PatchRadiusType
ConstNeighborhoodIterator< InputImageType, BoundaryConditionType > InputImagePatchIterator
virtual void ThreadedApplyUpdate(const InputImageRegionType &regionToProcess, const int threadId)
void DispatchedArrayMinMax(const TInputImageType *img)
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
PatchBasedDenoisingBaseImageFilter< TInputImage, TOutputImage > Superclass
ThreadDataStruct ThreadedRiemannianMinMax(const InputImageRegionType &regionToProcess, const int threadId, const InputImageType *img, ThreadDataStruct threadData)
virtual ThreadDataStruct ThreadedComputeSigmaUpdate(const InputImageRegionType &regionToProcess, const int threadId, ThreadDataStruct threadData)
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ComputeImageUpdateThreaderCallback(void *arg)
typename itk::Statistics::ImageToNeighborhoodSampleAdaptor< OutputImageType, BoundaryConditionType > ListAdaptorType
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)
void ComputeMinMax(const Image< DiffusionTensor3D< PixelValueType >, ImageDimension > *img)
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ApplyUpdateThreaderCallback(void *arg)
itk::Statistics::RegionConstrainedSubsampler< PatchSampleType, InputImageRegionType > BaseSamplerType
virtual ThreadDataStruct ThreadedComputeImageUpdate(const InputImageRegionType &regionToProcess, 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)
std::vector< EigenVectorsMatrixType > EigenVectorsCacheType
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)
DisableIfMultiComponent< T, T >::type GetComponent(const T pix, unsigned int idx) const
A method to generically get a component.
typename BaseSamplerType::Pointer BaseSamplerPointer
virtual ThreadDataStruct GetThreadData(int threadId)
void ComputeKernelBandwidthUpdate() override
void SetKernelBandwidthSigma(const RealArrayType &kernelSigma)
void SetComponent(T &pix, unsigned int idx, typename DisableIfMultiComponent< T, RealValueType >::type val) const
A method to generically set a component.
RealType AddExponentialMapUpdate(const DiffusionTensor3D< RealValueType > &spdMatrix, const DiffusionTensor3D< RealValueType > &symMatrix)
void ComputeDifferenceAndWeightedSquaredNorm(const PixelT &a, const PixelT &b, const RealArrayType &weight, bool useCachedComputations, SizeValueType cacheIndex, EigenValuesCacheType &eigenValsCache, EigenVectorsCacheType &eigenVecsCache, RealType &diff, RealArrayType &norm)
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
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ComputeSigmaUpdateThreaderCallback(void *arg)
void SetComponent(T &pix, unsigned int idx, typename EnableIfMultiComponent< T, RealValueType >::type val) const
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)
ImageRegionIterator< OutputImageType > OutputImageRegionIteratorType
typename InputImageType::RegionType InputImageRegionType
void SetNoiseSigma(const RealType &sigma)
typename NumericTraits< PixelType >::RealType RealType
std::vector< EigenValuesArrayType > EigenValuesCacheType
typename BaseSamplerType::InstanceIdentifier InstanceIdentifier
ImageRegionConstIterator< InputImageType > InputImageRegionConstIteratorType
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
RealType AddUpdate(const DiffusionTensor3D< RealValueType > &a, const RealType &b)
Implements transparent reference counting.
This an abstract subsampler that constrains subsamples to be contained within a given image region.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86
itk::ITK_THREAD_RETURN_TYPE ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION