2 #ifndef vil_find_peaks_h_ 3 #define vil_find_peaks_h_ 12 # include <vcl_msvc_warnings.h> 18 inline bool vil_is_peak_3x3(
const T* im, std::ptrdiff_t i_step, std::ptrdiff_t j_step)
25 &&
v > im[i_step+j_step]
26 &&
v > im[i_step-j_step]
27 &&
v > im[j_step-i_step]
28 &&
v > im[-i_step-j_step];
38 std::vector<unsigned>& pj,
47 const unsigned ni1=image.
ni()-1,nj1=image.
nj()-1;
48 const std::ptrdiff_t istep = image.
istep(),jstep=image.
jstep();
50 for (
unsigned j=1;j<nj1;++j,row+=jstep)
53 for (
unsigned i=1;i<ni1;++i,pixel+=istep)
55 { pi.push_back(i); pj.push_back(j); }
66 std::ptrdiff_t istep, std::ptrdiff_t jstep,
67 double& dx,
double& dy,
double& val)
78 const T& p11 = *pixel;
79 const T& p01 = *(pixel-istep);
80 const T& p21 = *(pixel+istep);
81 const T& p10 = *(pixel-jstep);
82 const T& p12 = *(pixel+jstep);
83 const T& p00 = *(&p10-istep);
84 const T& p20 = *(&p10+istep);
85 const T& p02 = *(&p12-istep);
86 const T& p22 = *(&p12+istep);
92 double Ix =(-p00-p01-p02 +p20+p21+p22)/6.0;
96 double Iy =(-p00-p10-p20 +p02+p12+p22)/6.0;
100 double Ixx = ((p00+p01+p02 +p20+p21+p22)-2.0*(p10+p11+p12))/3.0;
104 double Ixy = (p00+p22 -p02-p20)/4.0;
108 double Iyy = ((p00+p10+p20 +p02+p12+p22)-2.0*(p01+p11+p21))/3.0;
120 double det = Ixx*Iyy - Ixy*Ixy;
125 dx = (Iy*Ixy - Ix*Iyy) / det;
126 dy = (Ix*Ixy - Iy*Ixx) / det;
128 if (dx > 1.0 || dx < -1.0 || dy > 1.0 || dy < -1.0)
131 double Io =(p00+p01+p02 +p10+p11+p12 +p20+p21+p22)/9.0;
133 val = Io + (Ix + 0.5*Ixx*dx + Ixy*dy)*dx + (Iy + 0.5*Iyy*dy)*dy;
147 std::vector<double>& py,
148 std::vector<double>& val,
151 bool clear_list=
true)
158 const unsigned ni1=image.
ni()-1,nj1=image.
nj()-1;
159 const std::ptrdiff_t istep = image.
istep(),jstep=image.
jstep();
162 for (
unsigned j=1;j<nj1;++j,row+=jstep)
164 const T* pixel = row;
165 for (
unsigned i=1;i<ni1;++i,pixel+=istep)
176 #endif // vil_find_peaks_h_ Concrete view of image data of type T held in memory.
bool vil_interpolate_peak(const T *pixel, std::ptrdiff_t istep, std::ptrdiff_t jstep, double &dx, double &dy, double &val)
Fit a paraboloid to a pixel and its 8 neighbors to interpolate the peak.
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_find_peaks_3x3_subpixel(std::vector< double > &px, std::vector< double > &py, std::vector< double > &val, const vil_image_view< T > &image, const T &min_thresh, bool clear_list=true)
Return sub-pixel (px,py,val) for all points in image strictly above their 8 neighbours.
void vil_find_peaks_3x3(std::vector< unsigned > &pi, std::vector< unsigned > &pj, const vil_image_view< T > &image, const T &min_thresh, bool clear_list=true)
Return (pi,pj) for all points in image strictly above their 8 neighbours.
A base class reference-counting view of some image data.
bool vil_is_peak_3x3(const T *im, std::ptrdiff_t i_step, std::ptrdiff_t j_step)
True if pixel at *im is strictly above 8 neighbours.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.