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/*=========================================================================
2 *
3 * Copyright Insight Software Consortium
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkParabolicUtils_h
19#define itkParabolicUtils_h
20
21#include <itkArray.h>
22
23#include "itkProgressReporter.h"
24namespace itk
25{
26template <class LineBufferType, class RealType, bool doDilate>
27void
28DoLine(LineBufferType & LineBuf, LineBufferType & tmpLineBuf, const RealType magnitude, const RealType m_Extreme)
29{
30 // contact point algorithm
31 long koffset = 0, newcontact = 0; // how far away the search starts.
32
33 const long LineLength = LineBuf.size();
34 // negative half of the parabola
35 for (long pos = 0; pos < LineLength; ++pos)
36 {
37 RealType BaseVal = (RealType)m_Extreme; // the base value for
38 // comparison
39 for (long krange = koffset; krange <= 0; ++krange)
40 {
41 // difference needs to be paramaterised
42 RealType T = LineBuf[pos + krange] - magnitude * krange * krange;
43 // switch on template parameter - hopefully gets optimized away.
44 if (doDilate ? (T >= BaseVal) : (T <= BaseVal))
45 {
46 BaseVal = T;
47 newcontact = krange;
48 }
49 }
50 tmpLineBuf[pos] = BaseVal;
51 koffset = newcontact - 1;
52 }
53 // positive half of parabola
54 koffset = newcontact = 0;
55 for (long pos = LineLength - 1; pos >= 0; pos--)
56 {
57 RealType BaseVal = (RealType)m_Extreme; // the base value for comparison
58 for (long krange = koffset; krange >= 0; krange--)
59 {
60 RealType T = tmpLineBuf[pos + krange] - magnitude * krange * krange;
61 if (doDilate ? (T >= BaseVal) : (T <= BaseVal))
62 {
63 BaseVal = T;
64 newcontact = krange;
65 }
66 }
67 LineBuf[pos] = BaseVal;
68 koffset = newcontact + 1;
69 }
70}
71
72
73template <class TInIter, class TOutIter, class RealType, class OutputPixelType, bool doDilate>
74void
75doOneDimension(TInIter & inputIterator,
76 TOutIter & outputIterator,
77 ProgressReporter & progress,
78 const long LineLength,
79 const unsigned direction,
80 const int m_MagnitudeSign,
81 const bool m_UseImageSpacing,
82 const RealType m_Extreme,
83 const RealType image_scale,
84 const RealType Sigma)
85{
86 // using LineBufferType = typename std::vector<RealType>;
87
88 // message from M.Starring suggested performance gain using Array
89 // instead of std::vector.
90 using LineBufferType = typename itk::Array<RealType>;
91 RealType iscale = 1.0;
92 if (m_UseImageSpacing)
93 {
94 iscale = image_scale;
95 }
96 const RealType magnitude = m_MagnitudeSign * 1.0 / (2.0 * Sigma / (iscale * iscale));
97 LineBufferType LineBuf(LineLength);
98 LineBufferType tmpLineBuf(LineLength);
99 inputIterator.SetDirection(direction);
100 outputIterator.SetDirection(direction);
101 inputIterator.GoToBegin();
102 outputIterator.GoToBegin();
103
104 while (!inputIterator.IsAtEnd() && !outputIterator.IsAtEnd())
105 {
106 // process this direction
107 // fetch the line into the buffer - this methodology is like
108 // the gaussian filters
109 unsigned int i = 0;
110 while (!inputIterator.IsAtEndOfLine())
111 {
112 LineBuf[i++] = static_cast<RealType>(inputIterator.Get());
113 ++inputIterator;
114 }
115
116 DoLine<LineBufferType, RealType, doDilate>(LineBuf, tmpLineBuf, magnitude, m_Extreme);
117 // copy the line back
118 unsigned int j = 0;
119 while (!outputIterator.IsAtEndOfLine())
120 {
121 outputIterator.Set(static_cast<OutputPixelType>(LineBuf[j++]));
122 ++outputIterator;
123 }
124
125 // now onto the next line
126 inputIterator.NextLine();
127 outputIterator.NextLine();
128 progress.CompletedPixel();
129 }
130}
131
132
133} // namespace itk
134#endif
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)
void DoLine(LineBufferType &LineBuf, LineBufferType &tmpLineBuf, const RealType magnitude, const RealType m_Extreme)


Generated on 2023-01-13 for elastix by doxygen 1.9.6 elastix logo