10 # include <vcl_msvc_warnings.h> 20 unsigned ni = grad_i.
ni(), nj = grad_j.
nj();
21 assert(grad_j.
ni()==ni && grad_j.
nj()==nj);
25 const std::ptrdiff_t gi_istep = grad_i.
istep(), gi_jstep = grad_i.
jstep();
26 const std::ptrdiff_t gj_istep = grad_j.
istep(), gj_jstep = grad_j.
jstep();
27 const std::ptrdiff_t o_istep = orient_im.
istep(), o_jstep = orient_im.
jstep();
28 const std::ptrdiff_t gm_istep = grad_mag.
istep(), gm_jstep = grad_mag.
jstep();
30 const float * gi_row = &grad_i(0,0);
31 const float * gj_row = &grad_j(0,0);
32 float * o_row = &orient_im(0,0);
33 float * gm_row = &grad_mag(0,0);
35 for (
unsigned j=0;j<nj;++j, gi_row+=gi_jstep, gj_row+=gj_jstep,
36 o_row+=o_jstep, gm_row+=gm_jstep)
38 const float* pgi = gi_row;
39 const float* pgj = gj_row;
42 for (
unsigned i=0;i<ni;++i, pgi+=gi_istep, pgj+=gj_istep,
43 po+=o_istep, pgm+=gm_istep)
45 *po = std::atan2(*pgj,*pgi);
46 *pgm = std::sqrt(pgi[0]*pgi[0] + pgj[0]*pgj[0]);
60 unsigned n_orientations)
63 assert(n_orientations<=256);
64 unsigned ni = grad_i.
ni(), nj = grad_j.
nj();
65 assert(grad_j.
ni()==ni && grad_j.
nj()==nj);
69 const std::ptrdiff_t gi_istep = grad_i.
istep(), gi_jstep = grad_i.
jstep();
70 const std::ptrdiff_t gj_istep = grad_j.
istep(), gj_jstep = grad_j.
jstep();
71 const std::ptrdiff_t o_istep = orient_im.
istep(), o_jstep = orient_im.
jstep();
72 const std::ptrdiff_t gm_istep = grad_mag.
istep(), gm_jstep = grad_mag.
jstep();
74 const float * gi_row = &grad_i(0,0);
75 const float * gj_row = &grad_j(0,0);
76 vxl_byte * o_row = &orient_im(0,0);
77 float * gm_row = &grad_mag(0,0);
79 float scale = (2*n_orientations-1)/(6.28319f);
81 for (
unsigned j=0;j<nj;++j, gi_row+=gi_jstep, gj_row+=gj_jstep,
82 o_row+=o_jstep, gm_row+=gm_jstep)
84 const float* pgi = gi_row;
85 const float* pgj = gj_row;
88 for (
unsigned i=0;i<ni;++i, pgi+=gi_istep, pgj+=gj_istep,
89 po+=o_istep, pgm+=gm_istep)
93 int A2 = int((std::atan2(*pgj,*pgi)+3.14159)*scale);
94 *po = vxl_byte(((A2+1)/2)%n_orientations);
95 *pgm = std::sqrt(pgi[0]*pgi[0] + pgj[0]*pgj[0]);
113 float grad_threshold,
114 unsigned n_orientations)
117 assert(n_orientations<=256);
118 unsigned ni = grad_i.
ni(), nj = grad_j.
nj();
119 assert(grad_j.
ni()==ni && grad_j.
nj()==nj);
123 const std::ptrdiff_t gi_istep = grad_i.
istep(), gi_jstep = grad_i.
jstep();
124 const std::ptrdiff_t gj_istep = grad_j.
istep(), gj_jstep = grad_j.
jstep();
125 const std::ptrdiff_t o_istep = orient_im.
istep(), o_jstep = orient_im.
jstep();
126 const std::ptrdiff_t gm_istep = grad_mag.
istep(), gm_jstep = grad_mag.
jstep();
128 const float * gi_row = &grad_i(0,0);
129 const float * gj_row = &grad_j(0,0);
130 vxl_byte * o_row = &orient_im(0,0);
131 float * gm_row = &grad_mag(0,0);
133 float scale = (2*n_orientations-1)/(6.28319f);
135 for (
unsigned j=0;j<nj;++j, gi_row+=gi_jstep, gj_row+=gj_jstep,
136 o_row+=o_jstep, gm_row+=gm_jstep)
138 const float* pgi = gi_row;
139 const float* pgj = gj_row;
140 vxl_byte *po = o_row;
142 for (
unsigned i=0;i<ni;++i, pgi+=gi_istep, pgj+=gj_istep,
143 po+=o_istep, pgm+=gm_istep)
145 *pgm = std::sqrt(pgi[0]*pgi[0] + pgj[0]*pgj[0]);
146 if (*pgm<grad_threshold) *po=0;
151 int A2 = int((std::atan2(*pgj,*pgi)+3.14159)*scale);
152 *po = vxl_byte(1+((A2+1)/2)%n_orientations);
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.
void vil_orientations_at_edges(const vil_image_view< float > &grad_i, const vil_image_view< float > &grad_j, vil_image_view< vxl_byte > &orient_im, vil_image_view< float > &grad_mag, float grad_threshold, unsigned n_orientations=255)
Compute discrete orientation and gradient magnitude at edge pixels.
Functions to compute orientations and gradient magnitude.
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_orientations(const vil_image_view< float > &grad_i, const vil_image_view< float > &grad_j, vil_image_view< float > &orient_im, vil_image_view< float > &grad_mag)
Compute orientation (in radians) and gradient magnitude at each pixel.
unsigned nplanes() const
Number of planes.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.