go home Home | Main Page | Topics | 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 <typename LineBufferType, typename RealType, typename TInputPixel, bool doDilate>
27void
28DoLine(LineBufferType & LineBuf, LineBufferType & tmpLineBuf, const RealType magnitude)
29{
30 static constexpr RealType extreme =
31 doDilate ? NumericTraits<TInputPixel>::NonpositiveMin() : NumericTraits<TInputPixel>::max();
32
33 // contact point algorithm
34 long koffset = 0, newcontact = 0; // how far away the search starts.
35
36 const long LineLength = LineBuf.size();
37 // negative half of the parabola
38 for (long pos = 0; pos < LineLength; ++pos)
39 {
40 RealType BaseVal = extreme; // the base value for comparison
41 for (long krange = koffset; krange <= 0; ++krange)
42 {
43 // difference needs to be paramaterised
44 RealType T = LineBuf[pos + krange] - magnitude * krange * krange;
45 // switch on template parameter - hopefully gets optimized away.
46 if (doDilate ? (T >= BaseVal) : (T <= BaseVal))
47 {
48 BaseVal = T;
49 newcontact = krange;
50 }
51 }
52 tmpLineBuf[pos] = BaseVal;
53 koffset = newcontact - 1;
54 }
55 // positive half of parabola
56 koffset = newcontact = 0;
57 for (long pos = LineLength - 1; pos >= 0; pos--)
58 {
59 RealType BaseVal = extreme; // the base value for comparison
60 for (long krange = koffset; krange >= 0; krange--)
61 {
62 RealType T = tmpLineBuf[pos + krange] - magnitude * krange * krange;
63 if (doDilate ? (T >= BaseVal) : (T <= BaseVal))
64 {
65 BaseVal = T;
66 newcontact = krange;
67 }
68 }
69 LineBuf[pos] = BaseVal;
70 koffset = newcontact + 1;
71 }
72}
73
74
75template <typename TInIter,
76 typename TOutIter,
77 typename RealType,
78 typename TInputPixel,
79 typename OutputPixelType,
80 bool doDilate>
81void
82doOneDimension(TInIter & inputIterator,
83 TOutIter & outputIterator,
84 ProgressReporter & progress,
85 const long LineLength,
86 const unsigned direction,
87 const bool m_UseImageSpacing,
88 const RealType image_scale,
89 const RealType Sigma)
90{
91 // using LineBufferType = typename std::vector<RealType>;
92
93 // message from M.Starring suggested performance gain using Array
94 // instead of std::vector.
95 using LineBufferType = typename itk::Array<RealType>;
96 RealType iscale = 1.0;
97 if (m_UseImageSpacing)
98 {
99 iscale = image_scale;
100 }
101 constexpr int magnitudeSign = doDilate ? 1 : -1;
102 const RealType magnitude = magnitudeSign * 1.0 / (2.0 * Sigma / (iscale * iscale));
103 LineBufferType LineBuf(LineLength);
104 LineBufferType tmpLineBuf(LineLength);
105 inputIterator.SetDirection(direction);
106 outputIterator.SetDirection(direction);
107 inputIterator.GoToBegin();
108 outputIterator.GoToBegin();
109
110 while (!inputIterator.IsAtEnd() && !outputIterator.IsAtEnd())
111 {
112 // process this direction
113 // fetch the line into the buffer - this methodology is like
114 // the gaussian filters
115 unsigned int i = 0;
116 while (!inputIterator.IsAtEndOfLine())
117 {
118 LineBuf[i++] = static_cast<RealType>(inputIterator.Get());
119 ++inputIterator;
120 }
121
122 DoLine<LineBufferType, RealType, TInputPixel, doDilate>(LineBuf, tmpLineBuf, magnitude);
123 // copy the line back
124 unsigned int j = 0;
125 while (!outputIterator.IsAtEndOfLine())
126 {
127 outputIterator.Set(static_cast<OutputPixelType>(LineBuf[j++]));
128 ++outputIterator;
129 }
130
131 // now onto the next line
132 inputIterator.NextLine();
133 outputIterator.NextLine();
134 progress.CompletedPixel();
135 }
136}
137
138
139} // namespace itk
140#endif
void DoLine(LineBufferType &LineBuf, LineBufferType &tmpLineBuf, const RealType magnitude)
void doOneDimension(TInIter &inputIterator, TOutIter &outputIterator, ProgressReporter &progress, const long LineLength, const unsigned direction, const bool m_UseImageSpacing, const RealType image_scale, const RealType Sigma)


Generated on 26-02-2026 for elastix by doxygen 1.16.1 (669aeeefca743c148e2d935b3d3c69535c7491e6) elastix logo