go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkParabolicMorphUtils.h
Go to the documentation of this file.
1 #ifndef __itkParabolicUtils_h
2 #define __itkParabolicUtils_h
3 
4 #include <itkArray.h>
5 
6 #include "itkProgressReporter.h"
7 namespace itk
8 {
9 template< class LineBufferType, class RealType, bool doDilate >
10 void
11 DoLine( LineBufferType & LineBuf, LineBufferType & tmpLineBuf,
12  const RealType magnitude, const RealType m_Extreme )
13 {
14  // contact point algorithm
15  long koffset = 0, newcontact = 0; // how far away the search starts.
16 
17  const long LineLength = LineBuf.size();
18  // negative half of the parabola
19  for( long pos = 0; pos < LineLength; pos++ )
20  {
21  RealType BaseVal = (RealType)m_Extreme; // the base value for
22  // comparison
23  for( long krange = koffset; krange <= 0; krange++ )
24  {
25  // difference needs to be paramaterised
26  RealType T = LineBuf[ pos + krange ] - magnitude * krange * krange;
27  // switch on template parameter - hopefully gets optimized away.
28  if( doDilate ? ( T >= BaseVal ) : ( T <= BaseVal ) )
29  {
30  BaseVal = T;
31  newcontact = krange;
32  }
33  }
34  tmpLineBuf[ pos ] = BaseVal;
35  koffset = newcontact - 1;
36  }
37  // positive half of parabola
38  koffset = newcontact = 0;
39  for( long pos = LineLength - 1; pos >= 0; pos-- )
40  {
41  RealType BaseVal = (RealType)m_Extreme; // the base value for comparison
42  for( long krange = koffset; krange >= 0; krange-- )
43  {
44  RealType T = tmpLineBuf[ pos + krange ] - magnitude * krange * krange;
45  if( doDilate ? ( T >= BaseVal ) : ( T <= BaseVal ) )
46  {
47  BaseVal = T;
48  newcontact = krange;
49  }
50  }
51  LineBuf[ pos ] = BaseVal;
52  koffset = newcontact + 1;
53  }
54 }
55 
56 
57 template< class TInIter, class TOutIter, class RealType,
58 class OutputPixelType, bool doDilate >
59 void
60 doOneDimension( TInIter & inputIterator, TOutIter & outputIterator,
61  ProgressReporter & progress,
62  const long LineLength,
63  const unsigned direction,
64  const int m_MagnitudeSign,
65  const bool m_UseImageSpacing,
66  const RealType m_Extreme,
67  const RealType image_scale,
68  const RealType Sigma )
69 {
70 // typedef typename std::vector<RealType> LineBufferType;
71 
72  // message from M.Starring suggested performance gain using Array
73  // instead of std::vector.
74  typedef typename itk::Array< RealType > LineBufferType;
75  RealType iscale = 1.0;
76  if( m_UseImageSpacing )
77  {
78  iscale = image_scale;
79  }
80  const RealType magnitude = m_MagnitudeSign * 1.0 / ( 2.0 * Sigma / ( iscale * iscale ) );
81  LineBufferType LineBuf( LineLength );
82  LineBufferType tmpLineBuf( LineLength );
83  inputIterator.SetDirection( direction );
84  outputIterator.SetDirection( direction );
85  inputIterator.GoToBegin();
86  outputIterator.GoToBegin();
87 
88  while( !inputIterator.IsAtEnd() && !outputIterator.IsAtEnd() )
89  {
90  // process this direction
91  // fetch the line into the buffer - this methodology is like
92  // the gaussian filters
93  unsigned int i = 0;
94  while( !inputIterator.IsAtEndOfLine() )
95  {
96  LineBuf[ i++ ] = static_cast< RealType >( inputIterator.Get() );
97  ++inputIterator;
98  }
99 
100  DoLine< LineBufferType, RealType, doDilate >( LineBuf, tmpLineBuf, magnitude, m_Extreme );
101  // copy the line back
102  unsigned int j = 0;
103  while( !outputIterator.IsAtEndOfLine() )
104  {
105  outputIterator.Set( static_cast< OutputPixelType >( LineBuf[ j++ ] ) );
106  ++outputIterator;
107  }
108 
109  // now onto the next line
110  inputIterator.NextLine();
111  outputIterator.NextLine();
112  progress.CompletedPixel();
113  }
114 }
115 
116 
117 }
118 #endif
void DoLine(LineBufferType &LineBuf, LineBufferType &tmpLineBuf, const RealType magnitude, const RealType m_Extreme)
void doOneDimension(TInIter &inputIterator, TOutIter &outputIterator, ProgressReporter &progress, const long LineLength, const unsigned direction, const int m_MagnitudeSign, const bool m_UseImageSpacing, const RealType m_Extreme, const RealType image_scale, const RealType Sigma)


Generated on 11-03-2014 for elastix by doxygen 1.8.6 elastix logo