17 #ifndef __itkBinaryThinningImageFilter_txx
18 #define __itkBinaryThinningImageFilter_txx
34 template <
class TInputImage,
class TOutputImage>
39 this->SetNumberOfRequiredOutputs( 1 );
42 this->SetNthOutput( 0, thinImage.GetPointer() );
49 template <
class TInputImage,
class TOutputImage>
51 TInputImage,TOutputImage>::OutputImageType *
65 template <
class TInputImage,
class TOutputImage>
71 itkDebugMacro(<<
"PrepareData Start");
77 thinImage->SetBufferedRegion( thinImage->GetRequestedRegion() );
78 thinImage->Allocate();
80 typename OutputImageType::RegionType region = thinImage->GetRequestedRegion();
89 itkDebugMacro(<<
"PrepareData: Copy input to output");
106 itkDebugMacro(<<
"PrepareData End");
112 template <
class TInputImage,
class TOutputImage>
117 itkDebugMacro( <<
"ComputeThinImage Start");
120 typename OutputImageType::RegionType region = thinImage->GetRequestedRegion();
129 OffsetType o2 = {{0,-1}};
130 OffsetType o3 = {{1,-1}};
131 OffsetType o4 = {{1,0}};
132 OffsetType o5 = {{1,1}};
133 OffsetType o6 = {{0,1}};
134 OffsetType o7 = {{-1,1 }};
135 OffsetType o8 = {{-1,0}};
136 OffsetType o9 = {{-1,-1}};
153 std::vector < IndexType > pixelsToDelete;
154 typename std::vector < IndexType >::iterator pixelsToDeleteIt;
157 bool noChange =
false;
162 for (
int step = 1; step <= 4; step++)
164 pixelsToDelete.clear();
195 PixelType numberOfOnNeighbors = p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9;
197 if ( numberOfOnNeighbors > 1 && numberOfOnNeighbors < 7)
212 vcl_abs(static_cast<int>(p3 - p2)) + vcl_abs(static_cast<int>(p4 - p3)) + vcl_abs(static_cast<int>(p5 - p4)) + vcl_abs(static_cast<int>(p6 - p5)) +
213 vcl_abs(static_cast<int>(p7 - p6)) + vcl_abs(static_cast<int>(p8 - p7)) + vcl_abs(static_cast<int>(p9 - p8)) + vcl_abs(static_cast<int>(p2 - p9))
216 if (transitions == 1)
234 if (p4 == 0 || p6 == 0)
244 if (p2 == 0 && p8 == 0)
263 if (p2 == 0 || p8 == 0)
271 if (p4 == 0 && p6 == 0)
279 if (testA && testB && testC && testD)
281 pixelsToDelete.push_back( ot.
GetIndex() );
288 for (pixelsToDeleteIt=pixelsToDelete.begin();
289 pixelsToDeleteIt != pixelsToDelete.end();
292 thinImage->SetPixel(*pixelsToDeleteIt,0);
300 itkDebugMacro( <<
"ComputeThinImage End");
306 template <
class TInputImage,
class TOutputImage>
314 itkDebugMacro(<<
"GenerateData: Computing Thinning Image");
315 this->ComputeThinImage();