Orfeo Toolbox  3.16
itkSparseFieldFourthOrderLevelSetImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkSparseFieldFourthOrderLevelSetImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-18 16:11:13 $
7  Version: $Revision: 1.10 $
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 #ifndef __itkSparseFieldFourthOrderLevelSetImageFilter_txx
18 #define __itkSparseFieldFourthOrderLevelSetImageFilter_txx
19 
25 #include "itkSparseImage.h"
26 #include "itkNumericTraits.h"
27 
28 namespace itk {
29 
30 template <class TInputImage, class TOutputImage>
31 const unsigned long
32 SparseFieldFourthOrderLevelSetImageFilter <TInputImage, TOutputImage>
33 ::m_NumVertex = 1 << ImageDimension;
34 
35 template <class TInputImage, class TOutputImage>
36 const typename SparseFieldFourthOrderLevelSetImageFilter <TInputImage,
37  TOutputImage>::ValueType
38 SparseFieldFourthOrderLevelSetImageFilter <TInputImage, TOutputImage>
39 ::m_DimConst = static_cast <ValueType> (2.0/m_NumVertex);
40 
41 template<class TInputImage, class TOutputImage>
44 {
45  m_RefitIteration = 0;
46  m_LevelSetFunction = 0;
47  m_ConvergenceFlag = false;
48 
49  this->SetIsoSurfaceValue(0);
50  m_MaxRefitIteration = 100;
51  m_MaxNormalIteration = 25;
52  m_RMSChangeNormalProcessTrigger = NumericTraits<ValueType>::Zero;
53  m_CurvatureBandWidth = static_cast<ValueType>(ImageDimension) + 0.5;
54  m_NormalProcessType = 0;
55  m_NormalProcessConductance = NumericTraits<ValueType>::Zero;
56  m_NormalProcessUnsharpFlag = false;
57  m_NormalProcessUnsharpWeight = NumericTraits<ValueType>::Zero;
58 }
59 
60 template<class TInputImage, class TOutputImage>
61 void
63 ::PrintSelf(std::ostream& os, Indent indent) const
64 {
65  Superclass::PrintSelf(os, indent);
66  os << indent << "MaxRefitIteration: " << m_MaxRefitIteration << std::endl;
67  os << indent << "MaxNormalIteration: " << m_MaxNormalIteration << std::endl;
68  os << indent << "CurvatureBandWidth: " << m_CurvatureBandWidth << std::endl;
69 
70  os << indent << "RMSChangeNormalProcessTrigger: "
71  << m_RMSChangeNormalProcessTrigger<<std::endl;
72 
73  os << indent << "NormalProcessType: " << m_NormalProcessType << std::endl;
74 
75  os << indent <<"NormalProcessConductance: "
76  << m_NormalProcessConductance<<std::endl;
77 
78  os << indent << "NormalProcessUnsharpFlag: "
79  << m_NormalProcessUnsharpFlag << std::endl;
80 
81  os << indent <<"NormalProcessUnsharpWeight: "
82  << m_NormalProcessUnsharpWeight<<std::endl;
83 }
84 
85 template<class TInputImage, class TOutputImage>
88 {
89  m_LevelSetFunction = lsf;
90  Superclass::SetDifferenceFunction(lsf);
91 }
92 
93 template<class TInputImage, class TOutputImage>
95 ::ValueType
98 {
99  unsigned int j, k;
100  unsigned int counter;
101  unsigned long position, stride[ImageDimension], indicator[ImageDimension];
102  const unsigned long center = it.Size() / 2;
103  NormalVectorType normalvector;
104  ValueType curvature;
105  bool flag = false;
106 
107  const NeighborhoodScalesType neighborhoodScales = this->GetDifferenceFunction()->ComputeNeighborhoodScales();
108 
109  for( j = 0; j < ImageDimension; j++ )
110  {
111  stride[j] = it.GetStride( (unsigned long) j);
112  indicator[j] = 1 << j;
113  }
114 
115  curvature = NumericTraits<ValueType>::Zero;
116 
117  for (counter = 0; counter < m_NumVertex; counter++)
118  {
119  position = center;
120  for (k = 0; k < ImageDimension; k++)
121  {
122  if (counter & indicator[k])
123  {
124  position -= stride[k];
125  }
126  }
127  if (it.GetPixel (position) == 0)
128  {
129  flag = true;
130  }
131  else
132  {
133  normalvector = it.GetPixel (position)->m_Data;
134  for (j = 0; j < ImageDimension; j++) // derivative axis
135  {
136  if ( counter & indicator[j] )
137  {
138  curvature -= normalvector[j] * neighborhoodScales[j];
139  }
140  else
141  {
142  curvature += normalvector[j] * neighborhoodScales[j];
143  }
144  } // end derivative axis
145  }
146  } // end counter
147 
148  if (flag == true) curvature = NumericTraits<ValueType>::Zero;
149  curvature *= m_DimConst;
150  return curvature;
151 }
152 
153 template<class TInputImage, class TOutputImage>
154 void
157  SparseImageType *sparseImage ) const
158 {
159  typedef ImageRegionConstIterator <OutputImageType> DistanceImageIteratorType;
160 
161  DistanceImageIteratorType distanceImageIterator (
162  distanceImage,
163  distanceImage->GetRequestedRegion());
164  unsigned int j;
165  typename SparseImageIteratorType::RadiusType radius;
166  for( j = 0; j < ImageDimension; j++ )
167  {
168  radius[j] = 1;
169  }
171  sparseImageIterator (radius,sparseImage,
172  sparseImage->GetRequestedRegion());
173 
174  ValueType distance;
175  NodeType* node;
176 
177  sparseImageIterator.GoToBegin();
178  distanceImageIterator.GoToBegin();
179  while ( !distanceImageIterator.IsAtEnd() )
180  {
181  distance = distanceImageIterator.Value();
182  node = sparseImageIterator.GetCenterPixel();
183  if ( (distance >= -m_CurvatureBandWidth )&&
184  (distance <= m_CurvatureBandWidth ) )
185  {
186  node->m_Curvature =
187  ComputeCurvatureFromSparseImageNeighborhood (sparseImageIterator);
188  node->m_CurvatureFlag = true;
189  }
190  else
191  {
192  if (node != 0)
193  {
194  node->m_CurvatureFlag = false;
195  }
196  }
197  ++sparseImageIterator;
198  ++distanceImageIterator;
199  }
200 }
201 
202 template<class TInputImage, class TOutputImage>
203 bool
206 {
207  typename LayerType::Iterator layerIt;
208  typename SparseImageType::Pointer
209  im = m_LevelSetFunction->GetSparseTargetImage();
210  bool flag = false;
211  NodeType *node;
212 
213  layerIt = this->m_Layers[0]->Begin();
214  while (layerIt != this->m_Layers[0]->End() )
215  {
216  node = im->GetPixel(layerIt->m_Value);
217  if ((node == 0)||
218  (node->m_CurvatureFlag == false))
219  {
220  //level set touching edge of normal band
221  flag = true;
222  break;
223  }
224  ++layerIt;
225  }
226  return flag;
227 }
228 
229 template<class TInputImage, class TOutputImage>
230 void
233 {
234  typename NormalVectorFilterType::Pointer NormalVectorFilter;
235  typename NormalVectorFunctionType::Pointer NormalVectorFunction;
236 
237  ValueType temp = static_cast<ValueType>(ImageDimension);
238 
239  NormalVectorFilter = NormalVectorFilterType::New();
240  NormalVectorFunction = NormalVectorFunctionType::New();
241  NormalVectorFunction->SetNormalProcessType ( m_NormalProcessType );
242  NormalVectorFunction->SetConductanceParameter ( m_NormalProcessConductance );
243  NormalVectorFilter->SetNormalFunction ( NormalVectorFunction );
244  NormalVectorFilter->SetIsoLevelLow (-m_CurvatureBandWidth-temp );
245  NormalVectorFilter->SetIsoLevelHigh ( m_CurvatureBandWidth+temp );
246  NormalVectorFilter->SetMaxIteration ( m_MaxNormalIteration );
247  NormalVectorFilter->SetUnsharpMaskingFlag (m_NormalProcessUnsharpFlag);
248  NormalVectorFilter->SetUnsharpMaskingWeight (m_NormalProcessUnsharpWeight);
249 
250  // Move the pixel container and image information of the image we are working
251  // on into a temporary image to use as the input to the mini-pipeline. This
252  // avoids a complete copy of the image.
253  typename OutputImageType::Pointer phi = this->GetOutput();
254  typename OutputImageType::Pointer tmp = OutputImageType::New();
255  tmp->SetRequestedRegion( phi->GetRequestedRegion() );
256  tmp->SetBufferedRegion( phi->GetBufferedRegion() );
257  tmp->SetLargestPossibleRegion( phi->GetLargestPossibleRegion() );
258  tmp->SetPixelContainer( phi->GetPixelContainer() );
259  tmp->CopyInformation( phi );
260 
261  NormalVectorFilter->SetInput(tmp);
262  NormalVectorFilter->Update();
263 
264  typename SparseImageType::Pointer SparseNormalImage
265  = NormalVectorFilter->GetOutput();
266 
267  this->ComputeCurvatureTarget(tmp, SparseNormalImage);
268  m_LevelSetFunction->SetSparseTargetImage(SparseNormalImage);
269 }
270 
271 } // end namespace itk
272 
273 #endif

Generated at Sun Feb 3 2013 00:07:53 for Orfeo Toolbox with doxygen 1.8.1.1