ANIMA  4.0
animaNonLocalT2DistributionPatchSearcher.hxx
Go to the documentation of this file.
1 namespace anima
2 {
3 
4 template <class ImageType, class DataImageType>
5 NonLocalT2DistributionPatchSearcher <ImageType, DataImageType>
7 {
8  m_BetaParameter = 1.0;
9 
10  m_MeanMinThreshold = 0.95;
11  m_VarMinThreshold = 0.5;
12 }
13 
14 template <class ImageType, class DataImageType>
15 bool
17 ::TestPatchConformity(unsigned int index, const IndexType &refIndex, const IndexType &movingIndex)
18 {
19  unsigned int numTestImages = m_MeanImages.size();
20 
21  for (unsigned int i = 0;i < numTestImages;++i)
22  {
23  double refMeanValue = m_MeanImages[i]->GetPixel(refIndex);
24  double floMeanValue = m_MeanImages[i]->GetPixel(movingIndex);
25 
26  double refVarValue = m_VarImages[i]->GetPixel(refIndex);
27  double floVarValue = m_VarImages[i]->GetPixel(movingIndex);
28 
29  double meanRate = refMeanValue / floMeanValue;
30  double varianceRate = refVarValue / floVarValue;
31 
32  bool testRate = ( meanRate > m_MeanMinThreshold ) && ( meanRate < ( 1.0 / m_MeanMinThreshold ) ) &&
33  ( varianceRate > m_VarMinThreshold ) && ( varianceRate < ( 1.0 / m_VarMinThreshold ) );
34 
35  if (!testRate)
36  return false;
37  }
38 
39  return true;
40 }
41 
42 template <class ImageType, class DataImageType>
43 double
45 ::ComputeWeightValue(unsigned int index, ImageRegionType &refPatch, ImageRegionType &movingPatch)
46 {
47  typedef itk::ImageRegionConstIteratorWithIndex< DataImageType > InIteratorType;
48 
49  unsigned int numTestImages = m_PatchTestImages.size();
50  double globalWeightValue = 0.0;
51 
52  for (unsigned int i = 0;i < numTestImages;++i)
53  {
54  InIteratorType tmpIt (m_PatchTestImages[i], refPatch);
55  InIteratorType tmpMovingIt (m_PatchTestImages[i], movingPatch);
56 
57  double tmpDiffValue;
58 
59  double weightValue = 0.0;
60  unsigned int numVoxels = 0;
61 
62  while (!tmpIt.IsAtEnd())
63  {
64  tmpDiffValue = (double)tmpIt.Get() - (double)tmpMovingIt.Get();
65  weightValue += tmpDiffValue * tmpDiffValue;
66 
67  ++numVoxels;
68  ++tmpIt;
69  ++tmpMovingIt;
70  }
71 
72  globalWeightValue -= weightValue / (2.0 * m_BetaParameter * m_NoiseCovariances[i] * numVoxels);
73  }
74 
75  return std::exp(globalWeightValue / numTestImages);
76 }
77 
78 } // end namespace anima