ANIMA  4.0
animaNonLocalMeansPatchSearcher.hxx
Go to the documentation of this file.
1 #pragma once
3 
4 namespace anima
5 {
6 
7 template <class ImageType, class DataImageType>
8 NonLocalMeansPatchSearcher <ImageType, DataImageType>
10 {
11  m_BetaParameter = 1.0;
12  m_NoiseCovariance = 1.0;
13 
14  m_MeanMinThreshold = 0.95;
15  m_VarMinThreshold = 0.5;
16 }
17 
18 template <class ImageType, class DataImageType>
19 bool
21 ::TestPatchConformity(unsigned int index, const IndexType &refIndex, const IndexType &movingIndex)
22 {
23  double refMeanValue = m_MeanImage->GetPixel(refIndex);
24  double floMeanValue = m_MeanImage->GetPixel(movingIndex);
25 
26  double refVarValue = m_VarImage->GetPixel(refIndex);
27  double floVarValue = m_VarImage->GetPixel(movingIndex);
28 
29  double meanRate = refMeanValue / floMeanValue;
30  double varianceRate = refVarValue / floVarValue;
31 
32  // Should we compute the weight value of this patch ?
33  if ( ( meanRate > m_MeanMinThreshold ) && ( meanRate < ( 1.0 / m_MeanMinThreshold ) ) &&
34  ( varianceRate > m_VarMinThreshold ) && ( varianceRate < ( 1.0 / m_VarMinThreshold ) ) )
35  return true;
36 
37  return false;
38 }
39 
40 template <class ImageType, class DataImageType>
41 double
43 ::ComputeWeightValue(unsigned int index, ImageRegionType &refPatch, ImageRegionType &movingPatch)
44 {
45  typedef itk::ImageRegionConstIteratorWithIndex< ImageType > InIteratorType;
46 
47  InIteratorType tmpIt (this->GetInputImage(), refPatch);
48  InIteratorType tmpMovingIt (this->GetComparisonImage(index), movingPatch);
49 
50  double tmpDiffValue;
51 
52  double weightValue = 0.0;
53  unsigned int numVoxels = 0;
54 
55  while (!tmpIt.IsAtEnd())
56  {
57  tmpDiffValue = (double)tmpIt.Get() - (double)tmpMovingIt.Get();
58  weightValue += tmpDiffValue * tmpDiffValue;
59 
60  ++numVoxels;
61  ++tmpIt;
62  ++tmpMovingIt;
63  }
64 
65  weightValue = std::exp(- weightValue / (2.0 * m_BetaParameter * m_NoiseCovariance * numVoxels));
66  return weightValue;
67 }
68 
69 } // end namespace anima