Orfeo Toolbox  3.16
itkScalarChanAndVeseLevelSetFunction.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkScalarChanAndVeseLevelSetFunction.txx,v $
5  Language: C++
6  Date: $Date: 2009-06-12 09:44:02 $
7  Version: $Revision: 1.21 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 #ifndef __itkScalarChanAndVeseLevelSetFunction_txx
19 #define __itkScalarChanAndVeseLevelSetFunction_txx
20 
22 
23 namespace itk {
24 
25 // Computes the foreground constant and background constant value. For the Dense
26 // image filter, this is called prior to the start of every iteration. For the
27 // sparse filter, this is only called one during initialization.
28 template < class TInputImage, class TFeatureImage, class TSharedData >
29 void
32 {
33  unsigned int fId = this->m_FunctionId;
34 
35  if ( this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_WeightedNumberOfPixelsInsideLevelSet > vnl_math::eps )
36  {
37  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_ForegroundConstantValues =
38  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_WeightedSumOfPixelValuesInsideLevelSet /
39  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_WeightedNumberOfPixelsInsideLevelSet;
40  }
41  else
42  {
43  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_ForegroundConstantValues = 0;
44  }
45 
46  if ( this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_WeightedNumberOfPixelsOutsideLevelSet > vnl_math::eps )
47  {
48  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_BackgroundConstantValues =
49  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_WeightedSumOfPixelValuesOutsideLevelSet /
50  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_WeightedNumberOfPixelsOutsideLevelSet;
51  }
52  else
53  {
54  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_BackgroundConstantValues = 0;
55  }
56 
57 }
58 
59 // update the foreground constant for pixel updates
60 // Called only when sparse filters are used to prevent iteration through the
61 // entire image
62 template < class TInputImage, class TFeatureImage, class TSharedData >
63 void
65 ::UpdateSharedDataInsideParameters( const unsigned int& iId,
66  const FeaturePixelType& iVal, const ScalarValueType& iChange )
67 {
68  // update the foreground constant calculation of the current level-set function
69  this->m_SharedData->m_LevelSetDataPointerVector[iId]->m_WeightedNumberOfPixelsInsideLevelSet += iChange;
70  this->m_SharedData->m_LevelSetDataPointerVector[iId]->m_WeightedSumOfPixelValuesInsideLevelSet += iVal * iChange;
71 }
72 
73 // update the background constant for pixel updates
74 // Called only when sparse filters are used to prevent iteration through the
75 // entire image
76 template < class TInputImage, class TFeatureImage, class TSharedData >
77 void
79 ::UpdateSharedDataOutsideParameters( const unsigned int& iId,
80  const FeaturePixelType& iVal, const ScalarValueType& iChange )
81 {
82  this->m_SharedData->m_LevelSetDataPointerVector[iId]->m_WeightedNumberOfPixelsOutsideLevelSet += iChange;
83  this->m_SharedData->m_LevelSetDataPointerVector[iId]->m_WeightedSumOfPixelValuesOutsideLevelSet += iVal * iChange;
84 }
85 
86 /* Calculates the numerator and denominator for c_i for each region. As part of
87 the optimization, it is called once at the beginning of the code, and then the
88 cNum and cDen are updated during the evolution without iterating through the
89 entire image. */
90 template < class TInputImage, class TFeatureImage, class TSharedData >
91 void
94 {
95  unsigned int fId = this->m_FunctionId;
96 
97  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_WeightedNumberOfPixelsInsideLevelSet = 0;
98  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_WeightedSumOfPixelValuesInsideLevelSet = 0;
99  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_ForegroundConstantValues = 0;
100  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_WeightedNumberOfPixelsOutsideLevelSet = 0;
101  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_WeightedSumOfPixelValuesOutsideLevelSet = 0;
102  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_BackgroundConstantValues = 0;
103 
104  ConstFeatureIteratorType fIt( this->m_FeatureImage, this->m_FeatureImage->GetLargestPossibleRegion() );
105 
106  FeaturePixelType featureVal;
107  FeatureIndexType globalIndex;
108  InputIndexType itInputIndex, inputIndex;
109  InputPixelType hVal;
110  ListPixelType L;
111 
112  fIt.GoToBegin();
113 
114  while( !fIt.IsAtEnd() )
115  {
116  featureVal = fIt.Get();
117  inputIndex = fIt.GetIndex();
118  InputPixelType prod = 1.;
119 
120  globalIndex = this->m_SharedData->m_LevelSetDataPointerVector[fId]->GetFeatureIndex( inputIndex );
121 
122  L = this->m_SharedData->m_NearestNeighborListImage->GetPixel( globalIndex );
123 
124  for( ListPixelConstIterator it = L.begin(); it != L.end(); ++it )
125  {
126  itInputIndex = this->m_SharedData->m_LevelSetDataPointerVector[*it]->GetIndex( globalIndex );
127  hVal = this->m_SharedData->m_LevelSetDataPointerVector[*it]->m_HeavisideFunctionOfLevelSetImage->GetPixel( itInputIndex );
128  prod *= ( 1. - hVal );
129 
130  if (*it == fId)
131  {
132  this->m_SharedData->m_LevelSetDataPointerVector[*it]->m_WeightedSumOfPixelValuesInsideLevelSet += featureVal * hVal;
133  this->m_SharedData->m_LevelSetDataPointerVector[*it]->m_WeightedNumberOfPixelsInsideLevelSet += hVal;
134  }
135  }
136 
137  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_WeightedSumOfPixelValuesOutsideLevelSet += featureVal * prod;
138  this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_WeightedNumberOfPixelsOutsideLevelSet += prod;
139 
140  ++fIt;
141  }
142 }
143 
144 
145 template < class TInputImage, class TFeatureImage, class TSharedData >
147 ::ScalarValueType
150  const FeatureIndexType& itkNotUsed(iIdx) )
151 {
152  const unsigned int fId = this->m_FunctionId;
153  const ScalarValueType cVals = this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_ForegroundConstantValues;
154  const ScalarValueType t = ( iValue - cVals );
155  return t * t;
156 }
157 
158 
159 template < class TInputImage, class TFeatureImage, class TSharedData >
161 ::ScalarValueType
164  const FeatureIndexType& itkNotUsed(iIdx) )
165 {
166  const unsigned int fId = this->m_FunctionId;
167  const ScalarValueType cBgrnd = this->m_SharedData->m_LevelSetDataPointerVector[fId]->m_BackgroundConstantValues; // background
168  const ScalarValueType t = ( iValue - cBgrnd );
169 
170  return t * t;
171 }
172 
173 
174 } // end namespace itk
175 #endif

Generated at Sun Feb 3 2013 00:04:24 for Orfeo Toolbox with doxygen 1.8.1.1