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, class 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 <class TInIter, class TOutIter, class RealType, class TInputPixel, class OutputPixelType, bool doDilate>
76void
77doOneDimension(TInIter & inputIterator,
78 TOutIter & outputIterator,
79 ProgressReporter & progress,
80 const long LineLength,
81 const unsigned direction,
82 const bool m_UseImageSpacing,
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 constexpr int magnitudeSign = doDilate ? 1 : -1;
97 const RealType magnitude = magnitudeSign * 1.0 / (2.0 * Sigma / (iscale * iscale));
98 LineBufferType LineBuf(LineLength);
99 LineBufferType tmpLineBuf(LineLength);
100 inputIterator.SetDirection(direction);
101 outputIterator.SetDirection(direction);
102 inputIterator.GoToBegin();
103 outputIterator.GoToBegin();
104
105 while (!inputIterator.IsAtEnd() && !outputIterator.IsAtEnd())
106 {
107 // process this direction
108 // fetch the line into the buffer - this methodology is like
109 // the gaussian filters
110 unsigned int i = 0;
111 while (!inputIterator.IsAtEndOfLine())
112 {
113 LineBuf[i++] = static_cast<RealType>(inputIterator.Get());
114 ++inputIterator;
115 }
116
117 DoLine<LineBufferType, RealType, TInputPixel, doDilate>(LineBuf, tmpLineBuf, magnitude);
118 // copy the line back
119 unsigned int j = 0;
120 while (!outputIterator.IsAtEndOfLine())
121 {
122 outputIterator.Set(static_cast<OutputPixelType>(LineBuf[j++]));
123 ++outputIterator;
124 }
125
126 // now onto the next line
127 inputIterator.NextLine();
128 outputIterator.NextLine();
129 progress.CompletedPixel();
130 }
131}
132
133
134} // namespace itk
135#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 2024-07-17 for elastix by doxygen 1.11.0 (9b424b03c9833626cd435af22a444888fbbb192d) elastix logo