Commit ab946d7f authored by Davis King's avatar Davis King

Added find_bright_keypoints() and find_dark_keypoints(). Also added a convenience overload

for remove_incoherent_edge_pixels().
parent f2845f15
......@@ -394,6 +394,23 @@ namespace dlib
return newpixels;
}
template <
typename image_type
>
std::vector<std::vector<point>> remove_incoherent_edge_pixels (
const std::vector<std::vector<point>>& line_pixels,
const image_type& horz_gradient_,
const image_type& vert_gradient_,
const double angle_threshold
)
{
std::vector<std::vector<point>> temp;
temp.reserve(line_pixels.size());
for (auto& line : line_pixels)
temp.emplace_back(remove_incoherent_edge_pixels(line, horz_gradient_, vert_gradient_, angle_threshold));
return temp;
}
// ----------------------------------------------------------------------------------------
class image_gradients
......@@ -621,6 +638,96 @@ namespace dlib
impl::find_lines(xx,xy,yy,horz,vert,+1);
}
// ----------------------------------------------------------------------------------------
template <
typename in_image_type,
typename out_image_type
>
void find_bright_keypoints(
const in_image_type& xx_,
const in_image_type& xy_,
const in_image_type& yy_,
out_image_type& saliency_
)
{
typedef typename image_traits<out_image_type>::pixel_type out_pixel_type;
static_assert(std::is_same<float,out_pixel_type>::value || std::is_same<double,out_pixel_type>::value,
"Output images must contain either float or double valued pixels");
const_image_view<in_image_type> xx(xx_);
const_image_view<in_image_type> xy(xy_);
const_image_view<in_image_type> yy(yy_);
DLIB_CASSERT(xx.nr() == xy.nr());
DLIB_CASSERT(xx.nr() == yy.nr());
DLIB_CASSERT(xx.nc() == xy.nc());
DLIB_CASSERT(xx.nc() == yy.nc());
image_view<out_image_type> saliency(saliency_);
saliency.set_size(xx.nr(), xx.nc());
for (long r = 0; r < xx.nr(); ++r)
{
for (long c = 0; c < xx.nc(); ++c)
{
matrix<double,2,2> tmp;
tmp = xx[r][c], xy[r][c],
xy[r][c], yy[r][c];
matrix<double,2,1> e = real_eigenvalues(tmp);
saliency[r][c] = prod(upperbound(e,0));
}
}
}
// ----------------------------------------------------------------------------------------
template <
typename in_image_type,
typename out_image_type
>
void find_dark_keypoints(
const in_image_type& xx_,
const in_image_type& xy_,
const in_image_type& yy_,
out_image_type& saliency_
)
{
typedef typename image_traits<out_image_type>::pixel_type out_pixel_type;
static_assert(std::is_same<float,out_pixel_type>::value || std::is_same<double,out_pixel_type>::value,
"Output images must contain either float or double valued pixels");
const_image_view<in_image_type> xx(xx_);
const_image_view<in_image_type> xy(xy_);
const_image_view<in_image_type> yy(yy_);
DLIB_CASSERT(xx.nr() == xy.nr());
DLIB_CASSERT(xx.nr() == yy.nr());
DLIB_CASSERT(xx.nc() == xy.nc());
DLIB_CASSERT(xx.nc() == yy.nc());
image_view<out_image_type> saliency(saliency_);
saliency.set_size(xx.nr(), xx.nc());
for (long r = 0; r < xx.nr(); ++r)
{
for (long c = 0; c < xx.nc(); ++c)
{
matrix<double,2,2> tmp;
tmp = xx[r][c], xy[r][c],
xy[r][c], yy[r][c];
matrix<double,2,1> e = real_eigenvalues(tmp);
saliency[r][c] = prod(lowerbound(e,0));
}
}
}
// ----------------------------------------------------------------------------------------
}
......
......@@ -165,6 +165,33 @@ namespace dlib
- PTS is just line with some elements removed.
!*/
template <
typename image_type
>
std::vector<std::vector<point>> remove_incoherent_edge_pixels (
const std::vector<std::vector<point>>& lines,
const image_type& horz_gradient,
const image_type& vert_gradient,
const double angle_threshold
);
/*!
requires
- image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h
- image_type contains float, double, or long double pixels.
- horz_gradient.nr() == vert_gradient.nr()
- horz_gradient.nc() == vert_gradient.nc()
- horz_gradient and vert_gradient represent unit normalized vectors. That is,
you should have called normalize_image_gradients(horz_gradient,vert_gradient)
or otherwise caused all the gradients to have unit norm.
- for all valid i,j:
get_rect(horz_gradient).contains(lines[i][j])
ensures
- Returns a vector LINES where:
- LINES.size() == lines.size()
- LINES[i] == remove_incoherent_edge_pixels(lines[i], horz_gradient, vert_gradient, angle_threshold)
!*/
// ----------------------------------------------------------------------------------------
class image_gradients
......@@ -394,9 +421,8 @@ namespace dlib
direction. Moreover, if the second derivative is positive then the output
vector is zero. This zeroing if positive gradients causes the output to be
sensitive only to bright lines surrounded by darker pixels.
- We assume that xx, xy, and yy are the 3 different second order gradients of
the image in question. You can obtain these gradients using the
image_gradients class.
- We assume that xx, xy, and yy are the 3 second order gradients of the image
in question. You can obtain these gradients using the image_gradients class.
- The output images will have the same sizes as the input images, that is:
- #num_rows(horz) == #num_rows(vert) == num_rows(xx)
- #num_columns(horz) == #num_columns(vert) == num_columns(xx)
......@@ -436,14 +462,89 @@ namespace dlib
direction. Moreover, if the second derivative is negative then the output
vector is zero. This zeroing if negative gradients causes the output to be
sensitive only to dark lines surrounded by light pixels.
- We assume that xx, xy, and yy are the 3 different second order gradients of
the image in question. You can obtain these gradients using the
image_gradients class.
- We assume that xx, xy, and yy are the 3 second order gradients of the image
in question. You can obtain these gradients using the image_gradients class.
- The output images will have the same sizes as the input images, that is:
- #num_rows(horz) == #num_rows(vert) == num_rows(xx)
- #num_columns(horz) == #num_columns(vert) == num_columns(xx)
!*/
// ----------------------------------------------------------------------------------------
template <
typename in_image_type,
typename out_image_type
>
void find_bright_keypoints(
const in_image_type& xx,
const in_image_type& xy,
const in_image_type& yy,
out_image_type& saliency
);
/*!
requires
- in_image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h
- out_image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h
- All images are grayscale and the saliency image must contain float or double
pixel types.
- num_rows(xx) == num_rows(xy) == num_rows(yy)
- num_columns(xx) == num_columns(xy) == num_columns(yy)
ensures
- This routine finds bright "keypoints" in an image. In general, these are
bright/white localized blobs. It does this by computing the determinant of
the image Hessian at each location and storing this value into the output
saliency image if both eigenvalues of the Hessian are negative. If either
eigenvalue is positive then the saliency for that pixel is 0. I.e.
- for all valid r,c:
- #saliency[r][c] == a number >= 0 and larger values indicate the
presence of a keypoint at this pixel location.
- We assume that xx, xy, and yy are the 3 second order gradients of the image
in question. You can obtain these gradients using the image_gradients class.
- The output image will have the same size as the input images, that is:
- #num_rows(saliency) == num_rows(xx)
- #num_columns(saliency) == num_columns(xx)
!*/
// ----------------------------------------------------------------------------------------
template <
typename in_image_type,
typename out_image_type
>
void find_dark_keypoints(
const in_image_type& xx,
const in_image_type& xy,
const in_image_type& yy,
out_image_type& saliency
);
/*!
requires
- in_image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h
- out_image_type == an image object that implements the interface defined in
dlib/image_processing/generic_image.h
- All images are grayscale and the saliency image must contain float or double
pixel types.
- num_rows(xx) == num_rows(xy) == num_rows(yy)
- num_columns(xx) == num_columns(xy) == num_columns(yy)
ensures
- This routine finds dark "keypoints" in an image. In general, these are dark
localized blobs. It does this by computing the determinant of the image
Hessian at each location and storing this value into the output saliency
image if both eigenvalues of the Hessian are positive. If either eigenvalue
is negative then the saliency for that pixel is 0. I.e.
- for all valid r,c:
- #saliency[r][c] == a number >= 0 and larger values indicate the
presence of a keypoint at this pixel location.
- We assume that xx, xy, and yy are the 3 second order gradients of the image
in question. You can obtain these gradients using the image_gradients class.
- The output image will have the same size as the input images, that is:
- #num_rows(saliency) == num_rows(xx)
- #num_columns(saliency) == num_columns(xx)
!*/
// ----------------------------------------------------------------------------------------
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment