18 #ifndef __itkRegionBasedLevelSetFunction_txx
19 #define __itkRegionBasedLevelSetFunction_txx
26 template <
class TInput,
30 RegionBasedLevelSetFunction< TInput, TFeature, TSharedData >
31 ::m_WaveDT = 1.0/(2.0 * ImageDimension);
33 template <
class TInput,
37 RegionBasedLevelSetFunction< TInput, TFeature, TSharedData >
38 ::m_DT = 1.0/(2.0 * ImageDimension);
40 template <
class TInput,
43 RegionBasedLevelSetFunction< TInput,
48 m_Lambda1 = NumericTraits<ScalarValueType>::One;
49 m_Lambda2 = NumericTraits<ScalarValueType>::One;
51 m_OverlapPenaltyWeight = NumericTraits<ScalarValueType>::Zero;
52 m_AreaWeight = NumericTraits<ScalarValueType>::Zero;
53 m_VolumeMatchingWeight = NumericTraits<ScalarValueType>::Zero;
54 m_ReinitializationSmoothingWeight = NumericTraits<ScalarValueType>::Zero;
55 m_CurvatureWeight = m_AdvectionWeight = NumericTraits<ScalarValueType>::Zero;
56 m_Volume = NumericTraits<ScalarValueType>::Zero;
65 for(
unsigned int i = 0; i < ImageDimension; i++)
71 template <
class TInput,
class TFeature,
class TSharedData >
77 for (
unsigned int i = 0; i < ImageDimension; ++i)
79 ans[i] = NumericTraits<ScalarValueType>::Zero;
85 template <
class TInput,
class TFeature,
class TSharedData >
88 ::m_ZeroVectorConstant =
92 template <
class TInput,
100 InputImagePointer hBuffer = this->m_SharedData->m_LevelSetDataPointerVector[this->m_FunctionId]->m_HeavisideFunctionOfLevelSetImage;
104 ConstImageIteratorType constIt( contourImage, contourImage->GetRequestedRegion() );
107 ImageIteratorType It( hBuffer, hBuffer->GetRequestedRegion() );
112 while( !constIt.IsAtEnd() )
122 template <
class TInput,
132 this->ComputeHImage();
133 this->m_UpdateC =
false;
137 if ( !this->m_UpdateC )
139 this->ComputeParameters();
140 this->m_UpdateC =
true;
142 this->UpdateSharedDataParameters();
148 template <
class TInput,
190 template <
class TInput,
191 class TFeature,
class TSharedData >
193 TFeature, TSharedData >::
196 TFeature, TSharedData >::
206 for (i = 0; i < ImageDimension; i++)
208 for(j = 0; j < ImageDimension; j++)
232 template <
class TInput,
245 for (i = 0; i < ImageDimension; i++)
247 const unsigned int positionA =
248 static_cast< unsigned int >( this->m_Center + this->m_xStride[i] );
249 const unsigned int positionB =
250 static_cast< unsigned int >( this->m_Center - this->m_xStride[i] );
252 gd->
m_dx[i] = 0.5 * ( this->m_InvSpacing[i] ) *
255 ( it.
GetPixel( positionA ) - inputValue );
257 ( inputValue - it.
GetPixel( positionB ) );
261 gd->
m_dxy[i][i] = ( this->m_InvSpacing[i] ) *
264 for (j = i+1; j < ImageDimension; j++ )
266 const unsigned int positionAa =
static_cast<unsigned int>(
267 this->m_Center - this->m_xStride[i] - this->m_xStride[j] );
268 const unsigned int positionBa =
static_cast<unsigned int>(
269 this->m_Center - this->m_xStride[i] + this->m_xStride[j] );
270 const unsigned int positionCa =
static_cast<unsigned int>(
271 this->m_Center + this->m_xStride[i] - this->m_xStride[j] );
272 const unsigned int positionDa =
static_cast<unsigned int>(
273 this->m_Center + this->m_xStride[i] + this->m_xStride[j] );
276 ( this->m_InvSpacing[i] ) * ( this->m_InvSpacing[j] ) *
284 template <
class TInput,
300 ScalarValueType x_energy, advection_term = NumericTraits<ScalarValueType>::Zero;
305 ComputeHessian( it, gd );
307 ScalarValueType dh = m_DomainFunction->EvaluateDerivative( - inputValue );
312 ( this->m_CurvatureWeight != NumericTraits< ScalarValueType >::Zero ) )
314 curvature = this->ComputeCurvature( it, offset, gd );
315 curvature_term = this->m_CurvatureWeight * curvature *
316 this->CurvatureSpeed(it,offset, gd) * dh;
324 if( this->m_ReinitializationSmoothingWeight != NumericTraits<ScalarValueType>::Zero )
326 laplacian_term = this->ComputeLaplacian( gd ) - curvature;
328 laplacian_term *= this->m_ReinitializationSmoothingWeight *
329 this->LaplacianSmoothingSpeed(it,offset, gd);
332 if ( ( dh != 0. ) && ( m_AdvectionWeight != NumericTraits<ScalarValueType>::Zero ) )
334 advection_field = this->AdvectionField(it, offset, gd);
336 for(
unsigned int i = 0; i < ImageDimension; i++ )
338 x_energy = m_AdvectionWeight * advection_field[i];
341 if (x_energy > NumericTraits<ScalarValueType>::Zero )
347 advection_term += advection_field[i] * gd->
m_dx_forward[i];
353 advection_term *= m_AdvectionWeight*dh;
359 globalTerm = dh * this->ComputeGlobalTerm( inputValue, it.
GetIndex() );
366 static_cast< PixelType >( curvature_term + laplacian_term + globalTerm + advection_term );
378 template <
class TInput,
class TFeature,
class TSharedData >
387 for(
unsigned int i = 0; i < ImageDimension; i++ )
389 laplacian += gd->
m_dxy[i][i];
395 template <
class TInput,
class TFeature,
class TSharedData >
401 return 2 * ( this->m_SharedData->m_LevelSetDataPointerVector[this->m_FunctionId]->m_WeightedNumberOfPixelsInsideLevelSet - this->m_Volume );
409 template <
class TInput,
class TFeature,
class TSharedData >
424 this->m_FeatureImage->GetPixel ( inputIndex );
430 if( this->m_SharedData->m_FunctionCount > 1 )
432 featIndex = this->m_SharedData->m_LevelSetDataPointerVector[this->m_FunctionId]->GetFeatureIndex( inputIndex );
433 overlapTerm = this->m_OverlapPenaltyWeight *
434 ComputeOverlapParameters( featIndex, product );
437 ScalarValueType inTerm = this->m_Lambda1 * this->ComputeInternalTerm( featureVal, featIndex );
438 ScalarValueType outTerm = this->m_Lambda2 * product * this->ComputeExternalTerm( featureVal, featIndex );
441 ComputeVolumeRegularizationTerm() - this->m_AreaWeight;
443 ScalarValueType globalTerm = + inTerm - outTerm + overlapTerm + regularizationTerm;