2 #ifndef vil_line_filter_hxx_ 3 #define vil_line_filter_hxx_ 13 # include <vcl_msvc_warnings.h> 28 unsigned ni = image.
ni();
29 unsigned nj = image.
nj();
30 std::ptrdiff_t istep = image.
istep();
31 std::ptrdiff_t jstep = image.
jstep();
36 std::ptrdiff_t d_istep = line_dir.
istep();
37 std::ptrdiff_t d_jstep = line_dir.
jstep();
39 std::ptrdiff_t s_istep = line_str.
istep();
40 std::ptrdiff_t s_jstep = line_str.
jstep();
57 std::ptrdiff_t nistep = -istep;
58 std::ptrdiff_t njstep = -jstep;
59 std::ptrdiff_t xjstep = istep+jstep;
60 std::ptrdiff_t ynistep = jstep-istep;
61 std::ptrdiff_t xnjstep = istep-jstep;
62 std::ptrdiff_t ninjstep = -istep-jstep;
64 for (
int y=1;y<nj1;++y)
66 vxl_byte* d_row = d_data; d_row[0]=0; d_row+=d_istep;
67 float* s_row = s_data; s_row[0]=0; s_row+=s_istep;
68 const Type* i_row = im_data;
69 for (
int x=1;x<ni1;++x)
73 float f1 = float(i_row[nistep]) +float(i_row[istep]);
74 float f2 = float(i_row[ninjstep])+float(i_row[xjstep]);
75 float f3 = float(i_row[njstep]) +float(i_row[jstep]);
76 float f4 = float(i_row[ynistep]) +float(i_row[xnjstep]);
81 if (f2>max_f) { best_d=2; max_f=f2;}
82 if (f3>max_f) { best_d=3; max_f=f3;}
83 if (f4>max_f) { best_d=4; max_f=f4;}
85 float edge_s = 0.5f*max_f + (*i_row)/3.0f -(f1+f2+f3+f4)/6.0f;
86 if (edge_s>edge_thresh)
114 template <
class Type>
121 unsigned ni = image.
ni();
122 unsigned nj = image.
nj();
123 std::ptrdiff_t istep = image.
istep();
124 std::ptrdiff_t jstep = image.
jstep();
129 std::ptrdiff_t d_istep = line_dir.
istep();
130 std::ptrdiff_t d_jstep = line_dir.
jstep();
132 std::ptrdiff_t s_istep = line_str.
istep();
133 std::ptrdiff_t s_jstep = line_str.
jstep();
150 std::ptrdiff_t nistep = -istep;
151 std::ptrdiff_t njstep = -jstep;
152 std::ptrdiff_t xjstep = istep+jstep;
153 std::ptrdiff_t ynistep = jstep-istep;
154 std::ptrdiff_t xnjstep = istep-jstep;
155 std::ptrdiff_t ninjstep = -istep-jstep;
157 for (
int y=1;y<nj1;++y)
159 vxl_byte* d_row = d_data; d_row[0]=0; d_row+=d_istep;
160 float* s_row = s_data; s_row[0]=0; s_row+=s_istep;
161 const Type* i_row = im_data;
162 for (
int x=1;x<ni1;++x)
166 float f1 = float(i_row[nistep]) +float(i_row[istep]);
167 float f2 = float(i_row[ninjstep])+float(i_row[xjstep]);
168 float f3 = float(i_row[njstep]) +float(i_row[jstep]);
169 float f4 = float(i_row[xnjstep]) +float(i_row[ynistep]);
174 if (f2<min_f) { best_d=2; min_f=f2;}
175 if (f3<min_f) { best_d=3; min_f=f3;}
176 if (f4<min_f) { best_d=4; min_f=f4;}
178 float edge_s = (f1+f2+f3+f4)/6.0f - 0.5f*min_f - (*i_row)/3.0f;
179 if (edge_s>edge_thresh)
208 template <
class Type>
215 unsigned ni = image.
ni();
216 unsigned nj = image.
nj();
217 std::ptrdiff_t istep = image.
istep();
218 std::ptrdiff_t jstep = image.
jstep();
223 std::ptrdiff_t d_istep = line_dir.
istep();
224 std::ptrdiff_t d_jstep = line_dir.
jstep();
226 std::ptrdiff_t s_istep = line_str.
istep();
227 std::ptrdiff_t s_jstep = line_str.
jstep();
242 const Type* im_data = image.
top_left_ptr()+2*(jstep+istep);
248 std::ptrdiff_t i1a = -2*istep;
249 std::ptrdiff_t i1b = -istep;
250 std::ptrdiff_t i1c = istep;
251 std::ptrdiff_t i1d = 2*istep;
253 std::ptrdiff_t i2c = istep+jstep;
254 std::ptrdiff_t i2a = -2*i2c;
255 std::ptrdiff_t i2b = -1*i2c;
256 std::ptrdiff_t i2d = 2*i2c;
258 std::ptrdiff_t i3a = -2*jstep;
259 std::ptrdiff_t i3b = -1*jstep;
260 std::ptrdiff_t i3c = jstep;
261 std::ptrdiff_t i3d = 2*jstep;
263 std::ptrdiff_t i4c = istep-jstep;
264 std::ptrdiff_t i4a = -2*i4c;
265 std::ptrdiff_t i4b = -1*i4c;
266 std::ptrdiff_t i4d = 2*i4c;
268 for (
int y=2;y<nj2;++y)
270 vxl_byte* d_row = d_data; d_row[0]=0; d_row+=d_istep;d_row[0]=0; d_row+=d_istep;
271 float* s_row = s_data; s_row[0]=0; s_row+=s_istep;s_row[0]=0; s_row+=s_istep;
272 const Type* i_row = im_data;
273 for (
int x=2;x<ni2;++x)
277 float f1 = float(i_row[i1a])+float(i_row[i1b])+float(i_row[i1c])+float(i_row[i1d]);
278 float f2 = float(i_row[i2a])+float(i_row[i2b])+float(i_row[i2c])+float(i_row[i2d]);
279 float f3 = float(i_row[i3a])+float(i_row[i3b])+float(i_row[i3c])+float(i_row[i3d]);
280 float f4 = float(i_row[i4a])+float(i_row[i4b])+float(i_row[i4c])+float(i_row[i4d]);
285 if (f2>max_f) { best_d=2; max_f=f2;}
286 if (f3>max_f) { best_d=3; max_f=f3;}
287 if (f4>max_f) { best_d=4; max_f=f4;}
290 float edge_s = (17.0f/60) * max_f + 0.2f*(*i_row) -(f1+f2+f3+f4)/12;
291 if (edge_s>edge_thresh)
306 d_row[0]=0; d_row[d_istep]=0;
307 s_row[0]=0; s_row[s_istep]=0;
316 template <
class Type>
323 unsigned ni = image.
ni();
324 unsigned nj = image.
nj();
325 std::ptrdiff_t istep = image.
istep();
326 std::ptrdiff_t jstep = image.
jstep();
331 std::ptrdiff_t d_istep = line_dir.
istep();
332 std::ptrdiff_t d_jstep = line_dir.
jstep();
334 std::ptrdiff_t s_istep = line_str.
istep();
335 std::ptrdiff_t s_jstep = line_str.
jstep();
350 const Type* im_data = image.
top_left_ptr()+2*(jstep+istep);
356 std::ptrdiff_t i1a = -2*istep;
357 std::ptrdiff_t i1b = -istep;
358 std::ptrdiff_t i1c = istep;
359 std::ptrdiff_t i1d = 2*istep;
361 std::ptrdiff_t i2c = istep+jstep;
362 std::ptrdiff_t i2a = -2*i2c;
363 std::ptrdiff_t i2b = -1*i2c;
364 std::ptrdiff_t i2d = 2*i2c;
366 std::ptrdiff_t i3a = -2*jstep;
367 std::ptrdiff_t i3b = -1*jstep;
368 std::ptrdiff_t i3c = jstep;
369 std::ptrdiff_t i3d = 2*jstep;
371 std::ptrdiff_t i4c = istep-jstep;
372 std::ptrdiff_t i4a = -2*i4c;
373 std::ptrdiff_t i4b = -1*i4c;
374 std::ptrdiff_t i4d = 2*i4c;
376 for (
int y=2;y<nj2;++y)
378 vxl_byte* d_row = d_data; d_row[0]=0; d_row+=d_istep;d_row[0]=0; d_row+=d_istep;
379 float* s_row = s_data; s_row[0]=0; s_row+=s_istep;s_row[0]=0; s_row+=s_istep;
380 const Type* i_row = im_data;
381 for (
int x=2;x<ni2;++x)
385 float f1 = float(i_row[i1a])+float(i_row[i1b])+float(i_row[i1c])+float(i_row[i1d]);
386 float f2 = float(i_row[i2a])+float(i_row[i2b])+float(i_row[i2c])+float(i_row[i2d]);
387 float f3 = float(i_row[i3a])+float(i_row[i3b])+float(i_row[i3c])+float(i_row[i3d]);
388 float f4 = float(i_row[i4a])+float(i_row[i4b])+float(i_row[i4c])+float(i_row[i4d]);
393 if (f2<min_f) { best_d=2; min_f=f2;}
394 if (f3<min_f) { best_d=3; min_f=f3;}
395 if (f4<min_f) { best_d=4; min_f=f4;}
398 float edge_s = (f1+f2+f3+f4)/12 - (17.0f/60) * min_f - 0.2f*(*i_row);
399 if (edge_s>edge_thresh)
414 d_row[0]=0; d_row[d_istep]=0;
415 s_row[0]=0; s_row[s_istep]=0;
424 #undef VIL_LINE_FILTER_INSTANTIATE 425 #define VIL_LINE_FILTER_INSTANTIATE(T) \ 426 template class vil_line_filter<T > Various functions for manipulating image views.
Concrete view of image data of type T held in memory.
void set_size(unsigned ni, unsigned nj) override
resize current planes to ni x nj.
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
Find line-like structures in a 2D image.
unsigned ni() const
Width.
unsigned nj() const
Height.
void vil_fill_line(vil_image_view< T > &im, int ai, int aj, int bi, int bj, T value)
Fill line from (ai,aj) to (bi,bj) using Bresenham's algorithm.
void dark_lines_3x3(vil_image_view< vxl_byte > &line_dir, vil_image_view< float > &line_str, const vil_image_view< Type > &image, float edge_thresh=0.1f)
Find line like structures in image (dark lines on light backgrounds).
void light_lines_5x5(vil_image_view< vxl_byte > &line_dir, vil_image_view< float > &line_str, const vil_image_view< Type > &image, float edge_thresh=0.1f)
Find line like structures in image (light lines on dark backgrounds).
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
unsigned nplanes() const
Number of planes.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.
void light_lines_3x3(vil_image_view< vxl_byte > &line_dir, vil_image_view< float > &line_str, const vil_image_view< Type > &image, float edge_thresh=0.1f)
Find line like structures in image (light lines on dark backgrounds).
void dark_lines_5x5(vil_image_view< vxl_byte > &line_dir, vil_image_view< float > &line_str, const vil_image_view< Type > &image, float edge_thresh=0.1f)
Find line like structures in image (dark lines on light backgrounds).