[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] libcvd/cvd interpolate.h
From: |
Gerhard Reitmayr |
Subject: |
[libcvd-members] libcvd/cvd interpolate.h |
Date: |
Thu, 04 Dec 2008 14:46:53 +0000 |
CVSROOT: /cvsroot/libcvd
Module name: libcvd
Changes by: Gerhard Reitmayr <gerhard> 08/12/04 14:46:53
Modified files:
cvd : interpolate.h
Log message:
some fixes and 2D versions that return the interpolated value as well
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/interpolate.h?cvsroot=libcvd&r1=1.1&r2=1.2
Patches:
Index: interpolate.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/interpolate.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- interpolate.h 25 Nov 2008 09:17:51 -0000 1.1
+++ interpolate.h 4 Dec 2008 14:46:53 -0000 1.2
@@ -25,6 +25,7 @@
#include <cvd/image.h>
#include <cvd/config.h>
#include <cvd/vision.h>
+#include <cvd/vector_image_ref.h>
namespace CVD
{
@@ -71,7 +72,7 @@
///@param I_1__1 Pixel $( 1, -1)$ relative to the centre (g)
///@param I_1_0 Pixel $( 1, 0)$ relative to the centre (h)
///@param I_1_1 Pixel $( 1, 1)$ relative to the centre (i)
- ///@param Location of the local extrema.
+ ///@return Location of the local extrema.
///@ingroup gVision
TooN::Vector<2> interpolate_extremum(double I__1__1,
double I__1_0,
@@ -96,7 +97,7 @@
double Dinv = 1./(gxx * gyy - gxy * gxy);
- Vector<2> v;
+ TooN::Vector<2> v;
v[0] = -Dinv * (gyy * gx - gxy * gy);
v[1] = -Dinv * (-gxy * gx + gxx * gy);
@@ -107,31 +108,108 @@
///Interpolate a 2D local maximum, by fitting a quadratic.
///@param i Image in which to interpolate extremum
///@param p Point at which to interpolate extremum
- ///@return Pocation of local extremum
+ ///@return Location of local extremum in image coordinates
///@ingroup gVision
template<class I> TooN::Vector<2> interpolate_extremum(const
SubImage<I>& i, ImageRef p)
{
- CVD_IMAGE_ASSERT(p.x > 0 && p.y > 0 && p.x < i.size().x-1 && p.y <
i.size().y-1);
+ CVD_IMAGE_ASSERT(p.x > 0 && p.y > 0 && p.x < i.size().x-1 && p.y <
i.size().y-1, ImageError::AccessOutsideImage);
//Extract and label 9 particular points
- float I__1__1 = i[p[j] + ImageRef(-1, -1)];
- float I__1_0 = i[p[j] + ImageRef(-1, 0)];
- float I__1_1 = i[p[j] + ImageRef(-1, 1)];
- float I_0__1 = i[p[j] + ImageRef( 0, -1)];
- float I_0_0 = i[p[j] + ImageRef( 0, 0)];
- float I_0_1 = i[p[j] + ImageRef( 0, 1)];
- float I_1__1 = i[p[j] + ImageRef( 1, -1)];
- float I_1_0 = i[p[j] + ImageRef( 1, 0)];
- float I_1_1 = i[p[j] + ImageRef( 1, 1)];
- return interpolate_extremum(I__1__1, I__1_0, I__1_1, I_0__1,
I_0_0, I_0_1, I_1__1, I_1_0, I_1_1);
+ double I__1__1 = i[p + ImageRef(-1, -1)];
+ double I__1_0 = i[p + ImageRef(-1, 0)];
+ double I__1_1 = i[p + ImageRef(-1, 1)];
+ double I_0__1 = i[p + ImageRef( 0, -1)];
+ double I_0_0 = i[p + ImageRef( 0, 0)];
+ double I_0_1 = i[p + ImageRef( 0, 1)];
+ double I_1__1 = i[p + ImageRef( 1, -1)];
+ double I_1_0 = i[p + ImageRef( 1, 0)];
+ double I_1_1 = i[p + ImageRef( 1, 1)];
+ return interpolate_extremum(I__1__1, I__1_0, I__1_1, I_0__1,
I_0_0, I_0_1, I_1__1, I_1_0, I_1_1) + vec(p);
}
#endif
+ ///Interpolate a 2D local maximum, by fitting a quadratic. This is done
by using
+ ///using the 9 datapoints to compute the local Hessian using finite
differences and
+ ///finding the location where the gradient is zero. This version
returns also the
+ /// value of the extremum.
+ ///
+ /// Given the grid of pixels:
+ /// <pre>
+ /// a b c
+ /// d e f
+ /// g h i
+ /// </pre>
+ /// The centre pixel (e) must be the most extreme of all the pixels.
+ ///
+ ///@param I__1__1 Pixel $(-1, -1)$ relative to the centre (a)
+ ///@param I__1_0 Pixel $(-1, 0)$ relative to the centre (b)
+ ///@param I__1_1 Pixel $(-1, 1)$ relative to the centre (c)
+ ///@param I_0__1 Pixel $( 0, -1)$ relative to the centre (d)
+ ///@param I_0_0 Pixel $( 0, 0)$ relative to the centre (e)
+ ///@param I_0_1 Pixel $( 0, 1)$ relative to the centre (f)
+ ///@param I_1__1 Pixel $( 1, -1)$ relative to the centre (g)
+ ///@param I_1_0 Pixel $( 1, 0)$ relative to the centre (h)
+ ///@param I_1_1 Pixel $( 1, 1)$ relative to the centre (i)
+ ///@return pair containing Location of the local extrema and the value
+ ///@ingroup gVision
+ std::pair<TooN::Vector<2>, double> interpolate_extremum_value(double
I__1__1,
+ double I__1_0,
+ double I__1_1,
+ double I_0__1,
+ double I_0_0,
+ double I_0_1,
+ double I_1__1,
+ double I_1_0,
+ double I_1_1)
+ {
+ //Compute the gradient values
+ double gx = 0.5 * (I_1_0 - I__1_0);
+ double gy = 0.5 * (I_0_1 - I_0__1);
+
+ //Compute the Hessian values
+ double gxx = I_1_0 - 2 * I_0_0 + I__1_0;
+ double gyy = I_0_1 - 2 * I_0_0 + I_0__1;
+ double gxy = 0.25 * (I_1_1 + I__1__1 - I_1__1 - I__1_1);
+ //Compute -inv(H) * grad
-}
+ double Dinv = 1./(gxx * gyy - gxy * gxy);
+
+ TooN::Vector<2> v;
+ v[0] = -Dinv * (gyy * gx - gxy * gy);
+ v[1] = -Dinv * (-gxy * gx + gxx * gy);
+
+ double value = I_0_0 + (gx + gxx * v[0] + 2 * gxy * v[1])* v[0] + (gy
+ gyy * v[1]) * v[1];
+
+ return std::make_pair(v, value);
+ }
+
+ ///Interpolate a 2D local maximum, by fitting a quadratic.
+ ///@param i Image in which to interpolate extremum
+ ///@param p Point at which to interpolate extremum
+ ///@return pair containing Location of local extremum in image
coordinates and the value of the extemum
+ ///@ingroup gVision
+ template<class I> std::pair<TooN::Vector<2>, double>
interpolate_extremum_value(const SubImage<I>& i, ImageRef p)
+ {
+ CVD_IMAGE_ASSERT(p.x > 0 && p.y > 0 && p.x < i.size().x-1 && p.y <
i.size().y-1, ImageError::AccessOutsideImage);
+ //Extract and label 9 particular points
+ double I__1__1 = i[p + ImageRef(-1, -1)];
+ double I__1_0 = i[p + ImageRef(-1, 0)];
+ double I__1_1 = i[p + ImageRef(-1, 1)];
+ double I_0__1 = i[p + ImageRef( 0, -1)];
+ double I_0_0 = i[p + ImageRef( 0, 0)];
+ double I_0_1 = i[p + ImageRef( 0, 1)];
+ double I_1__1 = i[p + ImageRef( 1, -1)];
+ double I_1_0 = i[p + ImageRef( 1, 0)];
+ double I_1_1 = i[p + ImageRef( 1, 1)];
+ std::pair<TooN::Vector<2>, double> result =
interpolate_extremum_value(I__1__1, I__1_0, I__1_1, I_0__1, I_0_0, I_0_1,
I_1__1, I_1_0, I_1_1);
+ result.first += vec(p);
+ return result;
+ }
+
+}
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libcvd-members] libcvd/cvd interpolate.h,
Gerhard Reitmayr <=