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,
29 const RealType magnitude, const RealType m_Extreme )
30{
31 // contact point algorithm
32 long koffset = 0, newcontact = 0; // how far away the search starts.
33
34 const long LineLength = LineBuf.size();
35 // negative half of the parabola
36 for( long pos = 0; pos < LineLength; pos++ )
37 {
38 RealType BaseVal = (RealType)m_Extreme; // the base value for
39 // comparison
40 for( long krange = koffset; krange <= 0; krange++ )
41 {
42 // difference needs to be paramaterised
43 RealType T = LineBuf[ pos + krange ] - magnitude * krange * krange;
44 // switch on template parameter - hopefully gets optimized away.
45 if( doDilate ? ( T >= BaseVal ) : ( T <= BaseVal ) )
46 {
47 BaseVal = T;
48 newcontact = krange;
49 }
50 }
51 tmpLineBuf[ pos ] = BaseVal;
52 koffset = newcontact - 1;
53 }
54 // positive half of parabola
55 koffset = newcontact = 0;
56 for( long pos = LineLength - 1; pos >= 0; pos-- )
57 {
58 RealType BaseVal = (RealType)m_Extreme; // the base value for comparison
59 for( long krange = koffset; krange >= 0; krange-- )
60 {
61 RealType T = tmpLineBuf[ pos + krange ] - magnitude * krange * krange;
62 if( doDilate ? ( T >= BaseVal ) : ( T <= BaseVal ) )
63 {
64 BaseVal = T;
65 newcontact = krange;
66 }
67 }
68 LineBuf[ pos ] = BaseVal;
69 koffset = newcontact + 1;
70 }
71}
72
73
74template< class TInIter, class TOutIter, class RealType,
75class OutputPixelType, bool doDilate >
76void
77doOneDimension( TInIter & inputIterator, TOutIter & outputIterator,
78 ProgressReporter & progress,
79 const long LineLength,
80 const unsigned direction,
81 const int m_MagnitudeSign,
82 const bool m_UseImageSpacing,
83 const RealType m_Extreme,
84 const RealType image_scale,
85 const RealType Sigma )
86{
87// typedef typename std::vector<RealType> LineBufferType;
88
89 // message from M.Starring suggested performance gain using Array
90 // instead of std::vector.
91 typedef typename itk::Array< RealType > LineBufferType;
92 RealType iscale = 1.0;
93 if( m_UseImageSpacing )
94 {
95 iscale = image_scale;
96 }
97 const RealType magnitude = m_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, doDilate >( LineBuf, tmpLineBuf, magnitude, m_Extreme );
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}
135#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 1667476801 for elastix by doxygen 1.9.4 elastix logo