1 #ifndef vil_flood_fill_h_ 2 #define vil_flood_fill_h_ 12 # include <vcl_msvc_warnings.h> 21 unsigned i,
unsigned j,
23 unsigned& ilo,
unsigned& ihi)
26 unsigned ni1=image.
ni()-1;
27 std::ptrdiff_t istep=image.
istep();
30 while (ilo>0 && *p==
v) { ilo--; *p=new_v; p-=istep; }
33 while (ihi<ni1 && *p==
v) { ihi++; *p=new_v; p+=istep;}
45 unsigned seed_i,
unsigned seed_j,
48 unsigned ni1=image.
ni()-1;
49 unsigned nj1=image.
nj()-1;
50 std::vector<std::pair<unsigned,unsigned> > q;
51 if (seed_i>ni1 || seed_j>nj1)
return;
54 q.emplace_back(seed_i,seed_j);
59 unsigned i=q[k].first, j=q[k].second;
70 for (
unsigned i1=ilo;i1<=ihi;++i1)
72 q.emplace_back(i1,j-1);
77 for (
unsigned i1=ilo;i1<=ihi;++i1)
79 q.emplace_back(i1,j+1);
98 unsigned seed_i,
unsigned seed_j,
100 std::vector<vil_chord>& region)
103 unsigned ni1=image.
ni()-1;
104 unsigned nj1=image.
nj()-1;
105 std::vector<std::pair<unsigned,unsigned> > q;
106 if (seed_i>ni1 || seed_j>nj1)
return;
109 q.emplace_back(seed_i,seed_j);
114 unsigned i=q[k].first, j=q[k].second;
122 region.emplace_back(ilo,ihi,j);
127 for (
unsigned i1=ilo;i1<=ihi;++i1)
128 if (image(i1,j-1)==
v)
129 q.emplace_back(i1,j-1);
134 for (
unsigned i1=ilo;i1<=ihi;++i1)
135 if (image(i1,j+1)==
v)
136 q.emplace_back(i1,j+1);
153 unsigned seed_i,
unsigned seed_j,
156 unsigned ni1=image.
ni()-1;
157 unsigned nj1=image.
nj()-1;
158 std::vector<std::pair<unsigned,unsigned> > q;
159 if (seed_i>ni1 || seed_j>nj1)
return;
162 q.emplace_back(seed_i,seed_j);
167 unsigned i=q[k].first, j=q[k].second;
181 for (
unsigned i1=ilo;i1<=ihi;++i1)
182 if (image(i1,j-1)==
v)
183 q.emplace_back(i1,j-1);
188 for (
unsigned i1=ilo;i1<=ihi;++i1)
189 if (image(i1,j+1)==
v)
190 q.emplace_back(i1,j+1);
209 unsigned seed_i,
unsigned seed_j,
211 std::vector<vil_chord>& region)
214 unsigned ni1=image.
ni()-1;
215 unsigned nj1=image.
nj()-1;
216 std::vector<std::pair<unsigned,unsigned> > q;
217 if (seed_i>ni1 || seed_j>nj1)
return;
220 q.emplace_back(seed_i,seed_j);
225 unsigned i=q[k].first, j=q[k].second;
233 region.emplace_back(ilo,ihi,j);
241 for (
unsigned i1=ilo;i1<=ihi;++i1)
242 if (image(i1,j-1)==
v)
243 q.emplace_back(i1,j-1);
248 for (
unsigned i1=ilo;i1<=ihi;++i1)
249 if (image(i1,j+1)==
v)
250 q.emplace_back(i1,j+1);
257 #endif // vil_flood_fill_h_ void vil_flood_fill4(vil_image_view< T > &image, unsigned seed_i, unsigned seed_j, T v, T new_v)
Flood fill on a 4-connected region.
Concrete view of image data of type T held in memory.
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
unsigned ni() const
Width.
unsigned nj() const
Height.
void vil_flood_fill_row(vil_image_view< T > &image, unsigned i, unsigned j, T v, T new_v, unsigned &ilo, unsigned &ihi)
Search along i direction either side for limits of pixels matching v.
A base class reference-counting view of some image data.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
Object to store information about position of a row of pixels.
void vil_flood_fill8(vil_image_view< T > &image, unsigned seed_i, unsigned seed_j, T v, T new_v)
Flood fill on a 8-connected region.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.