11 # include <vcl_msvc_warnings.h> 27 unsigned ni = image.
ni(), nj = image.
nj();
29 &image(ni-1,nj-1), ni,nj,1,
44 unsigned ni = image.
ni();
45 unsigned nj = image.
nj();
47 std::ptrdiff_t istep = image.
istep(), jstep = image.
jstep();
48 std::ptrdiff_t o1 = -istep, o2 = -jstep-istep, o3 = -jstep, o4 = istep-jstep;
51 const float sqrt2 = std::sqrt(2.0f);
54 float* p0 = row0+istep;
55 for (
unsigned i=1;i<ni;++i,p0+=istep)
57 *p0 = std::min(p0[-istep]+1.0f,*p0);
63 for (
unsigned j=1;j<nj;++j,row0+=jstep)
66 *row0 = std::min(row0[o3]+1.0f,*row0);
67 *row0 = std::min(row0[o4]+sqrt2,*row0);
69 float* p0 = row0+istep;
70 for (
unsigned i=1;i<ni1;++i,p0+=istep)
72 *p0 = std::min(p0[o1]+1.0f ,*p0);
73 *p0 = std::min(p0[o2]+sqrt2,*p0);
74 *p0 = std::min(p0[o3]+1.0f ,*p0);
75 *p0 = std::min(p0[o4]+sqrt2,*p0);
79 *p0 = std::min(p0[o1]+1.0f ,*p0);
80 *p0 = std::min(p0[o2]+sqrt2,*p0);
81 *p0 = std::min(p0[o3]+1.0f ,*p0);
93 distance_image.
fill(max_dist);
104 unsigned ni = image.
ni();
105 unsigned nj = image.
nj();
107 std::ptrdiff_t istep = image.
istep(), jstep = image.
jstep();
113 std::ptrdiff_t o1 = -istep, o2 = -jstep-istep;
114 std::ptrdiff_t o3 = -jstep, o4 = istep-jstep;
115 std::ptrdiff_t o5 = -2*istep-jstep;
116 std::ptrdiff_t o6 = -istep-2*jstep;
117 std::ptrdiff_t o7 = istep-2*jstep;
118 std::ptrdiff_t o8 = 2*istep-jstep;
122 const float sqrt2 = std::sqrt(2.0f);
123 const float sqrt5 = std::sqrt(5.0f);
126 float* p0 = row0+istep;
127 for (
unsigned i=1;i<ni;++i,p0+=istep)
129 *p0 = std::min(p0[-istep]+1.0f,*p0);
136 *row0 = std::min(row0[o3]+1.0f,*row0);
137 *row0 = std::min(row0[o4]+sqrt5,*row0);
138 *row0 = std::min(row0[o8]+sqrt5,*row0);
141 *p0 = std::min(p0[o1]+1.0f,*p0);
142 *p0 = std::min(p0[o2]+sqrt2,*p0);
143 *p0 = std::min(p0[o3]+1.0f,*p0);
144 *p0 = std::min(p0[o4]+sqrt2,*p0);
145 *p0 = std::min(p0[o8]+sqrt5,*p0);
148 for (
unsigned i=2;i<ni2;++i,p0+=istep)
150 *p0 = std::min(p0[o1]+1.0f,*p0);
151 *p0 = std::min(p0[o2]+sqrt2,*p0);
152 *p0 = std::min(p0[o3]+1.0f,*p0);
153 *p0 = std::min(p0[o4]+sqrt2,*p0);
154 *p0 = std::min(p0[o5]+sqrt5,*p0);
155 *p0 = std::min(p0[o8]+sqrt5,*p0);
159 *p0 = std::min(p0[o1]+1.0f,*p0);
160 *p0 = std::min(p0[o2]+sqrt2,*p0);
161 *p0 = std::min(p0[o3]+1.0f,*p0);
162 *p0 = std::min(p0[o4]+sqrt2,*p0);
163 *p0 = std::min(p0[o5]+sqrt5,*p0);
167 *p0 = std::min(p0[o1]+1.0f,*p0);
168 *p0 = std::min(p0[o2]+sqrt2,*p0);
169 *p0 = std::min(p0[o3]+1.0f,*p0);
170 *p0 = std::min(p0[o5]+sqrt5,*p0);
175 for (
unsigned j=2;j<nj;++j,row0+=jstep)
178 *row0 = std::min(row0[o3]+1.0f,*row0);
179 *row0 = std::min(row0[o4]+sqrt2,*row0);
180 *row0 = std::min(row0[o7]+sqrt5,*row0);
181 *row0 = std::min(row0[o8]+sqrt5,*row0);
183 float* p0 = row0+istep;
185 *p0 = std::min(p0[o1]+1.0f,*p0);
186 *p0 = std::min(p0[o2]+sqrt2,*p0);
187 *p0 = std::min(p0[o3]+1.0f,*p0);
188 *p0 = std::min(p0[o4]+sqrt2,*p0);
189 *p0 = std::min(p0[o6]+sqrt5,*p0);
190 *p0 = std::min(p0[o7]+sqrt5,*p0);
191 *p0 = std::min(p0[o8]+sqrt5,*p0);
194 for (
unsigned i=2;i<ni2;++i,p0+=istep)
196 *p0 = std::min(p0[o1]+1.0f,*p0);
197 *p0 = std::min(p0[o2]+sqrt2,*p0);
198 *p0 = std::min(p0[o3]+1.0f,*p0);
199 *p0 = std::min(p0[o4]+sqrt2,*p0);
200 *p0 = std::min(p0[o5]+sqrt5,*p0);
201 *p0 = std::min(p0[o6]+sqrt5,*p0);
202 *p0 = std::min(p0[o7]+sqrt5,*p0);
203 *p0 = std::min(p0[o8]+sqrt5,*p0);
208 *p0 = std::min(p0[o1]+1.0f,*p0);
209 *p0 = std::min(p0[o2]+sqrt2,*p0);
210 *p0 = std::min(p0[o3]+1.0f,*p0);
211 *p0 = std::min(p0[o4]+sqrt2,*p0);
212 *p0 = std::min(p0[o5]+sqrt5,*p0);
213 *p0 = std::min(p0[o6]+sqrt5,*p0);
214 *p0 = std::min(p0[o7]+sqrt5,*p0);
218 *p0 = std::min(p0[o1]+1.0f,*p0);
219 *p0 = std::min(p0[o2]+sqrt2,*p0);
220 *p0 = std::min(p0[o3]+1.0f,*p0);
221 *p0 = std::min(p0[o5]+sqrt5,*p0);
222 *p0 = std::min(p0[o6]+sqrt5,*p0);
241 unsigned ni = image.
ni(), nj = image.
nj();
243 &image(ni-1,nj-1), ni,nj,1,
Various functions for manipulating image views.
Concrete view of image data of type T held in memory.
void fill(T value)
Fill view with given value.
void set_size(unsigned ni, unsigned nj) override
resize current planes to ni x nj.
void vil_distance_transform_one_way(vil_image_view< float > &image)
Compute directed distance function from zeros in original image.
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_distance_transform_r2(vil_image_view< float > &image)
Compute distance function from zeros in original image.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
unsigned nplanes() const
Number of planes.
const vil_memory_chunk_sptr & memory_chunk() const
Smart pointer to the object holding the data for this view.
void vil_distance_transform(vil_image_view< float > &image)
Compute distance function from zeros in original image.
void vil_fill_mask(vil_image_view< srcT > &image, const vil_image_view< bool > &mask, srcT value, bool b=true)
Writes given value into each pixel of image under the elements of the mask set to b.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.