2 #ifndef vil_suppress_non_max_edges_hxx_ 3 #define vil_suppress_non_max_edges_hxx_ 14 # include <vcl_msvc_warnings.h> 26 template<
class srcT,
class destT>
29 double grad_mag_threshold,
34 unsigned ni = grad_i.
ni(), nj = grad_i.
nj();
36 assert(grad_j.
ni()==ni && grad_j.
nj()==nj);
49 const std::ptrdiff_t gi_istep = grad_i.
istep(), gi_jstep = grad_i.
jstep();
50 const std::ptrdiff_t gj_istep = grad_j.
istep(), gj_jstep = grad_j.
jstep();
51 const std::ptrdiff_t gm_istep = grad_mag.
istep(), gm_jstep = grad_mag.
jstep();
53 const srcT * gi_data = &grad_i(0,0);
54 const srcT * gj_data = &grad_j(0,0);
55 const srcT * gi_row = &grad_i(2,2);
56 const srcT * gj_row = &grad_j(2,2);
57 destT * gm_row = &grad_mag(2,2);
61 for (
unsigned j=2; j<=jhi; ++j, gi_row+=gi_jstep, gj_row+=gj_jstep,
64 const srcT* pgi = gi_row;
65 const srcT* pgj = gj_row;
67 for (
unsigned i=2; i<=ihi; ++i, pgi+=gi_istep, pgj+=gj_istep,
70 double gmag=std::sqrt(
double(pgi[0]*pgi[0] + pgj[0]*pgj[0]));
71 if (gmag<grad_mag_threshold) *pgm=0;
74 double dx=pgi[0]/gmag;
75 double dy=pgj[0]/gmag;
79 if (dx*gx1+dy*gy1>gmag) *pgm=0;
85 if (dx*gx2+dy*gy2>gmag) *pgm=0;
98 double interpolate_parabola(
double y_1,
double y_0,
double y_2,
102 double diff1 = y_2 - y_1;
103 double diff2 = 2 * y_0 - y_1 - y_2;
107 y_peak += diff1 * diff1 / (8 * diff2);
108 return diff1 / (2 * diff2);
141 template<
class srcT,
class destT>
144 double grad_mag_threshold,
149 unsigned ni = grad_i.
ni(), nj = grad_i.
nj();
150 assert(ni>2 && nj>2);
151 assert(grad_j.
ni()==ni && grad_j.
nj()==nj);
164 const std::ptrdiff_t gi_istep = grad_i.
istep(), gi_jstep = grad_i.
jstep();
165 const std::ptrdiff_t gj_istep = grad_j.
istep(), gj_jstep = grad_j.
jstep();
166 const std::ptrdiff_t gm_istep = grad_moo.
istep(), gm_jstep = grad_moo.
jstep();
167 const std::ptrdiff_t gm_pstep = grad_moo.
planestep();
169 const srcT * gi_data = &grad_i(0,0);
170 const srcT * gj_data = &grad_j(0,0);
171 const srcT * gi_row = &grad_i(2,2);
172 const srcT * gj_row = &grad_j(2,2);
173 destT * gm_row = &grad_moo(2,2);
177 for (
unsigned j=2; j<=jhi; ++j, gi_row+=gi_jstep, gj_row+=gj_jstep,
180 const srcT* pgi = gi_row;
181 const srcT* pgj = gj_row;
183 for (
unsigned i=2; i<=ihi; ++i, pgi+=gi_istep, pgj+=gj_istep,
186 double gmag=std::sqrt(
double(pgi[0]*pgi[0] + pgj[0]*pgj[0]));
187 if (gmag<grad_mag_threshold){
194 double dx=pgi[0]/gmag;
195 double dy=pgj[0]/gmag;
199 double g1mag = dx*gx1+dy*gy1;
210 double g2mag = dx*gx2+dy*gy2;
220 double offset = interpolate_parabola(g2mag, gmag, g1mag, peak);
222 *(pgm+gm_pstep) = destT(std::atan2(dy,dx));
223 *(pgm+2*gm_pstep) = destT(offset);
231 #undef VIL_SUPPRESS_NON_MAX_EDGES_INSTANTIATE 232 #define VIL_SUPPRESS_NON_MAX_EDGES_INSTANTIATE(srcT, destT) \ 233 template void vil_suppress_non_max_edges(const vil_image_view<srcT >& grad_i,\ 234 const vil_image_view<srcT >& grad_j,\ 235 double grad_mag_threshold,\ 236 vil_image_view<destT >& grad_mag);\ 237 template void vil_suppress_non_max_edges_subpixel(const vil_image_view<srcT >& grad_i,\ 238 const vil_image_view<srcT >& grad_j,\ 239 double grad_mag_threshold,\ 240 vil_image_view<destT >& grad_moo) 242 #endif // vil_suppress_non_max_edges_hxx_ 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.
void vil_fill_col(vil_image_view< T > &view, unsigned i, T value)
Fill column i in view with given value.
unsigned ni() const
Width.
unsigned nj() const
Height.
std::ptrdiff_t planestep() const
Add this to your pixel pointer to get pixel on next plane.
void vil_suppress_non_max_edges(const vil_image_view< srcT > &grad_i, const vil_image_view< srcT > &grad_j, double grad_mag_threshold, vil_image_view< destT > &grad_mag)
Given gradient images, computes magnitude image containing maximal edges.
unsigned nplanes() const
Number of planes.
void vil_suppress_non_max_edges_subpixel(const vil_image_view< srcT > &grad_i, const vil_image_view< srcT > &grad_j, double grad_mag_threshold, vil_image_view< destT > &grad_mag_orient_offset)
Given gradient images, computes a subpixel edgemap with magnitudes and orientations.
double vil_bilin_interp_unsafe(double x, double y, const T *data, std::ptrdiff_t xstep, std::ptrdiff_t ystep)
Compute bilinear interpolation at (x,y), no bound checks. Requires 0<x<ni-2, 0<y<nj-2.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.
void vil_fill_row(vil_image_view< T > &view, unsigned j, T value)
Fill row j in view with given value.
Given gradient image, compute magnitude and zero any non-maximal values.
Bilinear interpolation functions for 2D images.