-
-
Notifications
You must be signed in to change notification settings - Fork 661
/
itkBinaryPruningImageFilter.hxx
161 lines (137 loc) · 4.65 KB
/
itkBinaryPruningImageFilter.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkBinaryPruningImageFilter_hxx
#define itkBinaryPruningImageFilter_hxx
#include <iostream>
#include "itkImageRegionIterator.h"
namespace itk
{
/**
* Constructor
*/
template <typename TInputImage, typename TOutputImage>
BinaryPruningImageFilter<TInputImage, TOutputImage>::BinaryPruningImageFilter()
{
this->SetNumberOfRequiredOutputs(1);
OutputImagePointer pruneImage = OutputImageType::New();
this->SetNthOutput(0, pruneImage.GetPointer());
m_Iteration = 3;
}
/**
* Return the pruning Image pointer
*/
template <typename TInputImage, typename TOutputImage>
auto
BinaryPruningImageFilter<TInputImage, TOutputImage>::GetPruning() -> OutputImageType *
{
return dynamic_cast<OutputImageType *>(this->ProcessObject::GetOutput(0));
}
/**
* Prepare data for computation
*/
template <typename TInputImage, typename TOutputImage>
void
BinaryPruningImageFilter<TInputImage, TOutputImage>::PrepareData()
{
itkDebugMacro("PrepareData Start");
OutputImagePointer pruneImage = GetPruning();
InputImagePointer inputImage = dynamic_cast<const TInputImage *>(ProcessObject::GetInput(0));
pruneImage->SetBufferedRegion(pruneImage->GetRequestedRegion());
pruneImage->Allocate();
typename OutputImageType::RegionType region = pruneImage->GetRequestedRegion();
ImageRegionConstIterator<TInputImage> it(inputImage, region);
ImageRegionIterator<TOutputImage> ot(pruneImage, region);
itkDebugMacro("PrepareData: Copy input to output");
while (!ot.IsAtEnd())
{
ot.Set(static_cast<typename OutputImageType::PixelType>(it.Get()));
++it;
++ot;
}
itkDebugMacro("PrepareData End");
}
/**
* Post processing for computing thinning
*/
template <typename TInputImage, typename TOutputImage>
void
BinaryPruningImageFilter<TInputImage, TOutputImage>::ComputePruneImage()
{
itkDebugMacro("ComputeThinImage Start");
OutputImagePointer pruneImage = GetPruning();
typename OutputImageType::RegionType region = pruneImage->GetRequestedRegion();
typename NeighborhoodIteratorType::RadiusType radius;
radius.Fill(1);
NeighborhoodIteratorType ot(radius, pruneImage, region);
typename NeighborhoodIteratorType::OffsetType offset1 = { { -1, -1 } };
typename NeighborhoodIteratorType::OffsetType offset2 = { { -1, 0 } };
typename NeighborhoodIteratorType::OffsetType offset3 = { { -1, 1 } };
typename NeighborhoodIteratorType::OffsetType offset4 = { { 0, 1 } };
typename NeighborhoodIteratorType::OffsetType offset5 = { { 1, 1 } };
typename NeighborhoodIteratorType::OffsetType offset6 = { { 1, 0 } };
typename NeighborhoodIteratorType::OffsetType offset7 = { { 1, -1 } };
typename NeighborhoodIteratorType::OffsetType offset8 = { { 0, -1 } };
unsigned int count = 0;
while (count < m_Iteration)
{
ot.GoToBegin();
while (!ot.IsAtEnd())
{
if (ot.GetCenterPixel())
{
PixelType genus;
genus = ot.GetPixel(offset1) + ot.GetPixel(offset2);
genus += ot.GetPixel(offset3) + ot.GetPixel(offset4);
genus += ot.GetPixel(offset5) + ot.GetPixel(offset6);
genus += ot.GetPixel(offset7) + ot.GetPixel(offset8);
if (genus < 2)
{
genus = 0;
ot.SetCenterPixel(genus);
}
}
++ot;
}
++count;
}
itkDebugMacro("ComputeThinImage End");
}
/**
* Generate PruneImage
*/
template <typename TInputImage, typename TOutputImage>
void
BinaryPruningImageFilter<TInputImage, TOutputImage>::GenerateData()
{
this->PrepareData();
itkDebugMacro("GenerateData: Computing Thinning Image");
this->ComputePruneImage();
} // end GenerateData()
/**
* Print Self
*/
template <typename TInputImage, typename TOutputImage>
void
BinaryPruningImageFilter<TInputImage, TOutputImage>::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "Pruning image: " << std::endl;
os << indent << "Iteration: " << m_Iteration << std::endl;
}
} // end namespace itk
#endif