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