ANIMA  4.0
animaMCMBlockMatchInitializer.hxx
Go to the documentation of this file.
1 #pragma once
3 
4 #include <itkImageRegionConstIterator.h>
5 #include <itkImageRegionIteratorWithIndex.h>
6 
7 #include <itkExpNegativeImageFilter.h>
8 #include <itkDanielssonDistanceMapImageFilter.h>
9 #include <itkGrayscaleDilateImageFilter.h>
10 #include <itkBinaryBallStructuringElement.h>
11 
12 namespace anima
13 {
14 
15 template <class PixelType, unsigned int NDimensions>
16 void
18 ::AddReferenceImage(itk::ImageBase <NDimensions> *refImage)
19 {
20  this->Superclass::AddReferenceImage(refImage);
21 
22  MCMImageType *castImage = dynamic_cast <MCMImageType *> (refImage);
23  if (castImage != 0)
24  m_ReferenceModels.push_back(castImage->GetDescriptionModel());
25 }
26 
27 template <class PixelType, unsigned int NDimensions>
28 void
30 ::InitializeThreading(unsigned int maskIndex, BlockGeneratorThreadStruct *&workStr)
31 {
33  workStr = tmpStr;
34  this->Superclass::InitializeThreading(maskIndex,workStr);
35 
36  tmpStr->ref_models.resize(this->GetNumberOfThreads());
37  for (unsigned int i = 0;i < this->GetNumberOfThreads();++i)
38  {
39  std::vector <MCModelPointer> ref_models(m_ReferenceModels.size());
40  for (unsigned int j = 0;j < m_ReferenceModels.size();++j)
41  ref_models[j] = m_ReferenceModels[j]->Clone();
42 
43  tmpStr->ref_models[i] = ref_models;
44  }
45 }
46 
47 template <class PixelType, unsigned int NDimensions>
49 ::CheckOrientedModelVariance(unsigned int imageIndex, ImageRegionType &region, double &blockVariance,
50  BlockGeneratorThreadStruct *workStr, unsigned int threadId)
51 {
52  MCMImageType *refImage = dynamic_cast <MCMImageType *> (this->GetReferenceVectorImage(imageIndex));
53  MCMBlockGeneratorThreadStruct *tmpStr = dynamic_cast <MCMBlockGeneratorThreadStruct *> (workStr);
54 
55  itk::ImageRegionConstIterator <MCMImageType> refItr(refImage,region);
56  typedef typename MCMImageType::PixelType VectorType;
57 
58  MCModelPointer refModel = tmpStr->ref_models[threadId][imageIndex];
59  unsigned int nbPts = 0;
60  unsigned int numIsoCompartments = refModel->GetNumberOfIsotropicCompartments();
61 
62  double meanVal = 0;
63  blockVariance = 0;
64  while (!refItr.IsAtEnd())
65  {
66  refModel->SetModelVector(refItr.Get());
67 
68  // Here we sum all isotropic compartment weights
69  double tmpVal = 0;
70  for (unsigned int i = 0;i < numIsoCompartments;++i)
71  tmpVal += refModel->GetCompartmentWeight(i);
72 
73  meanVal += tmpVal;
74  blockVariance += tmpVal * tmpVal;
75 
76  ++nbPts;
77  ++refItr;
78  }
79 
80  if (nbPts <= 1)
81  return false;
82 
83  blockVariance = (blockVariance - meanVal * meanVal / nbPts) / (nbPts - 1.0);
84 
85  if (blockVariance > this->GetOrientedModelVarianceThreshold())
86  return true;
87  else
88  return false;
89 }
90 
91 }// end of namespace anima
MCMPointer & GetDescriptionModel()
void InitializeThreading(unsigned int maskIndex, BlockGeneratorThreadStruct *&workStr) ITK_OVERRIDE
void AddReferenceImage(itk::ImageBase< NDimensions > *refImage) ITK_OVERRIDE
ScalarImageType::RegionType ImageRegionType
bool CheckOrientedModelVariance(unsigned int imageIndex, ImageRegionType &region, double &blockVariance, BlockGeneratorThreadStruct *workStr, unsigned int threadId) ITK_OVERRIDE