2 #ifndef vil_normalised_correlation_2d_h_ 3 #define vil_normalised_correlation_2d_h_ 13 # include <vcl_msvc_warnings.h> 21 template <
class srcT,
class kernelT,
class accumT>
23 std::ptrdiff_t s_jstep, std::ptrdiff_t s_pstep,
27 unsigned ni = kernel.
ni();
28 unsigned nj = kernel.
nj();
31 std::ptrdiff_t k_istep = kernel.
istep(), k_jstep = kernel.
jstep();
36 for (
unsigned p = 0; p<np; ++p)
39 const srcT* src_row = src_im + p*s_pstep;
42 for (
unsigned int j=0;j<nj;++j,src_row+=s_jstep,k_row+=k_jstep)
44 const srcT* sp = src_row;
45 const kernelT* kp = k_row;
47 for (
unsigned int i=0;i<ni;++i, sp += s_istep, kp += k_istep)
49 sum += accumT(*sp)*accumT(*kp);
51 sum_sq += accumT(*sp)*accumT(*sp);
58 accumT var = sum_sq/(accumT)n - mean*mean;
59 return var<=0 ? 0 : sum/std::sqrt(var);
70 template <
class srcT,
class destT,
class kernelT,
class accumT>
76 unsigned ni = 1+src_im.
ni()-kernel.
ni(); assert(1+src_im.
ni() >= kernel.
ni());
77 unsigned nj = 1+src_im.
nj()-kernel.
nj(); assert(1+src_im.
nj() >= kernel.
nj());
78 std::ptrdiff_t s_istep = src_im.
istep(), s_jstep = src_im.
jstep();
79 std::ptrdiff_t s_pstep = src_im.
planestep();
82 std::ptrdiff_t d_istep = dest_im.
istep(),d_jstep = dest_im.
jstep();
88 for (
unsigned j=0;j<nj;++j,src_row+=s_jstep,dest_row+=d_jstep)
90 const srcT* sp = src_row;
92 for (
unsigned i=0;i<ni;++i, sp += s_istep, dp += d_istep)
98 #endif // vil_normalised_correlation_2d_h_ void vil_normalised_correlation_2d(const vil_image_view< srcT > &src_im, vil_image_view< destT > &dest_im, const vil_image_view< kernelT > &kernel, accumT ac)
Normalised cross-correlation of (pre-normalised) kernel with srcT.
accumT vil_norm_corr_2d_at_pt(const srcT *src_im, std::ptrdiff_t s_istep, std::ptrdiff_t s_jstep, std::ptrdiff_t s_pstep, const vil_image_view< kernelT > &kernel, accumT)
Evaluate dot product between kernel and src_im.
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.
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.
A base class reference-counting view of some image data.
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.