[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] libcvd cvd/tensor_voting.h cvd_src/tensor_votin...
From: |
Edward Rosten |
Subject: |
[libcvd-members] libcvd cvd/tensor_voting.h cvd_src/tensor_votin... |
Date: |
Fri, 18 Apr 2008 16:51:36 +0000 |
CVSROOT: /cvsroot/libcvd
Module name: libcvd
Changes by: Edward Rosten <edrosten> 08/04/18 16:51:36
Modified files:
cvd : tensor_voting.h
cvd_src : tensor_voting.cc
Log message:
Tensor voting now includes the edges
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/tensor_voting.h?cvsroot=libcvd&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd_src/tensor_voting.cc?cvsroot=libcvd&r1=1.1&r2=1.2
Patches:
Index: cvd/tensor_voting.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/tensor_voting.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- cvd/tensor_voting.h 25 Mar 2008 19:28:36 -0000 1.4
+++ cvd/tensor_voting.h 18 Apr 2008 16:51:35 -0000 1.5
@@ -13,8 +13,18 @@
#ifndef DOXYGEN_IGNORE_INTERNAL
namespace TensorVoting
{
- std::vector<std::pair<int, TooN::Matrix<2> > >
compute_a_tensor_kernel(int radius, double cutoff, double angle, double sigma,
double ratio, int row_stride);
- unsigned int quantize_half_angle(double r, int num_divs);
+ struct TV_coord
+ {
+ ptrdiff_t o;
+ int x;
+ int y;
+ };
+
+ std::vector<std::pair<TV_coord, TooN::Matrix<2> > >
compute_a_tensor_kernel(int radius, double cutoff, double angle, double sigma,
double ratio, int row_stride);
+ inline unsigned int quantize_half_angle(double r, int num_divs)
+ {
+ return ((int)floor((r/M_PI+100) * num_divs + 0.5)) %
num_divs;
+ }
}
#endif
@@ -72,6 +82,7 @@
using TooN::Matrix;
using std::pair;
using std::vector;
+ using TensorVoting::TV_coord;
Matrix<2> zero;
TooN::Zero(zero);
@@ -86,7 +97,7 @@
//First, build up the kernels
- vector<vector<pair<int, Matrix<2> > > > kernels;
+ vector<vector<pair<TV_coord, Matrix<2> > > > kernels;
for(unsigned int i=0; i < num_divs; i++)
{
double angle = M_PI * i / num_divs;
@@ -103,16 +114,48 @@
double scale = sqrt(gx*gx + gy*gy);
unsigned int direction =
TensorVoting::quantize_half_angle(M_PI/2 + atan(gy / gx), num_divs);
- const vector<pair<int, Matrix<2> > >& kernel =
kernels[direction];
+ const vector<pair<TV_coord, Matrix<2> > >&
kernel = kernels[direction];
Matrix<2>* p = &field[y][x];
//The matrices are all symmetric, so only use
the upper right triangle.
for(unsigned int i=0; i < kernel.size(); i++)
{
- p[kernel[i].first][0][0] +=
kernel[i].second[0][0] * scale;
- p[kernel[i].first][0][1] +=
kernel[i].second[0][1] * scale;
- p[kernel[i].first][1][1] +=
kernel[i].second[1][1] * scale;
+ p[kernel[i].first.o][0][0] +=
kernel[i].second[0][0] * scale;
+ p[kernel[i].first.o][0][1] +=
kernel[i].second[0][1] * scale;
+ p[kernel[i].first.o][1][1] +=
kernel[i].second[1][1] * scale;
+ }
+ }
+
+ //Now do the edges
+ for(int y= 1; y < field.size().y-1; y++)
+ {
+ for(int x= 1; x < field.size().x-1; x++)
+ {
+ //Skip the middle bit
+ if(y >= kernel_radius && y < field.size().y -
kernel_radius && x == kernel_radius)
+ x = field.size().x - kernel_radius;
+
+ double gx = ((double)image[y][x+1] -
image[y][x-1])/2.;
+ double gy = ((double)image[y+1][x] -
image[y-1][x])/2.;
+
+ double scale = sqrt(gx*gx + gy*gy);
+ unsigned int direction =
TensorVoting::quantize_half_angle(M_PI/2 + atan(gy / gx), num_divs);
+
+ const vector<pair<TV_coord, Matrix<2> > >&
kernel = kernels[direction];
+
+ Matrix<2>* p = &field[y][x];
+
+ //The matrices are all symmetric, so only use
the upper right triangle.
+ for(unsigned int i=0; i < kernel.size(); i++)
+ {
+ if(kernel[i].first.y+y >= 0 &&
kernel[i].first.y+y < field.size().y && kernel[i].first.x+x >= 0 &&
kernel[i].first.x+x < field.size().x)
+ {
+ p[kernel[i].first.o][0][0] +=
kernel[i].second[0][0] * scale;
+ p[kernel[i].first.o][0][1] +=
kernel[i].second[0][1] * scale;
+ p[kernel[i].first.o][1][1] +=
kernel[i].second[1][1] * scale;
+ }
+ }
}
}
Index: cvd_src/tensor_voting.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd_src/tensor_voting.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- cvd_src/tensor_voting.cc 13 Dec 2007 22:36:56 -0000 1.1
+++ cvd_src/tensor_voting.cc 18 Apr 2008 16:51:36 -0000 1.2
@@ -13,11 +13,6 @@
namespace TensorVoting
{
- unsigned int quantize_half_angle(double r, int num_divs)
- {
- return ((int)floor((r/M_PI+100) * num_divs + 0.5)) %
num_divs;
- }
-
Matrix<2> rot(double angle)
{
double v[]= {cos(angle), sin(angle), -sin(angle),
cos(angle)};
@@ -76,12 +71,21 @@
return refpair<A,B>(aa, bb);
}
+ TV_coord make(int x, int y, int s)
+ {
+ TV_coord t;
+ t.x = x;
+ t.y = y;
+ t.o = (ptrdiff_t)s * y + x;
+ return t;
+ }
+
//Compute a kernel, with small values set to zero, with pointer
offsets
//for the nonzero elements.
- vector<pair<int, Matrix<2> > > compute_a_tensor_kernel(int
radius, double cutoff, double angle, double sigma, double ratio, int row_stride)
+ vector<pair<TV_coord, Matrix<2> > > compute_a_tensor_kernel(int
radius, double cutoff, double angle, double sigma, double ratio, int row_stride)
{
- vector<pair<int, Matrix<2> > > ret;
+ vector<pair<TV_coord, Matrix<2> > > ret;
Vector<2> g;
g[0] = cos(angle);
@@ -95,7 +99,7 @@
rpair(tensor, scale) =
tensor_kernel_element(g, x, y, sigma, ratio);
if(scale >= cutoff)
- ret.push_back(make_pair(x + y *
row_stride, scale * tensor));
+
ret.push_back(make_pair(make(x,y,row_stride), scale * tensor));
}
return ret;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libcvd-members] libcvd cvd/tensor_voting.h cvd_src/tensor_votin...,
Edward Rosten <=