* mln/detection/corner/harris.hh: New.
* mln/detection/corner/harris_criterion.hh: New.
---
milena/ChangeLog | 7 +
.../mln/detection/corner/{moravec.hh => harris.hh} | 91 +++++++++------
milena/mln/detection/corner/harris_criterion.hh | 123 ++++++++++++++++++++
3 files changed, 187 insertions(+), 34 deletions(-)
copy milena/mln/detection/corner/{moravec.hh => harris.hh} (52%)
create mode 100644 milena/mln/detection/corner/harris_criterion.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index fab764c..808624f 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,10 @@
+2012-10-04 Jonathan Fabrizio <jonathan(a)lrde.epita.fr>
+
+ Add Harris corner detection.
+
+ * mln/detection/corner/harris.hh: New.
+ * mln/detection/corner/harris_criterion.hh: New.
+
2012-10-03 Jonathan Fabrizio <jonathan(a)lrde.epita.fr>
Add test for Moravec corner detection.
diff --git a/milena/mln/detection/corner/moravec.hh
b/milena/mln/detection/corner/harris.hh
similarity index 52%
copy from milena/mln/detection/corner/moravec.hh
copy to milena/mln/detection/corner/harris.hh
index b9af479..0acce69 100644
--- a/milena/mln/detection/corner/moravec.hh
+++ b/milena/mln/detection/corner/harris.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,20 +23,24 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_DETECTION_CORNER_MORAVEC_HH
-# define MLN_DETECTION_CORNER_MORAVEC_HH
+#ifndef MLN_DETECTION_CORNER_HARRIS_HH
+# define MLN_DETECTION_CORNER_HARRIS_HH
#include <mln/core/site_set/p_array.hh>
-#include <mln/extension/adjust_duplicate.hh>
-#include <mln/metal/is.hh>
-#include <mln/win/rectangle2d.hh>
+//#include <mln/win/rectangle2d.hh>
#include <mln/core/alias/neighb2d.hh>
-#include <mln/core/alias/window2d.hh>
-#include <mln/detection/corner/moravec_criterion.hh>
+#include <mln/linear/ch_convolve.hh>
+#include <mln/linear/convolve.hh>
+#include <mln/linear/gaussian.hh>
+#include <mln/arith/times.hh>
+#include <mln/core/alias/w_window2d_int.hh>
+
+//#include <mln/core/alias/window2d.hh>
+#include <mln/detection/corner/harris_criterion.hh>
/// \file
///
-/// \brief Implementation of Moravec corner detection.
+/// \brief Implementation of Harris corner detection.
namespace mln
@@ -46,32 +50,47 @@ namespace mln
namespace corner
{
/**
- Computes Moravec corner detection on \p in_image
+ Computes Harris corner detection on \p in_image
\param image_in_ The input image
- \param win The window of moravec algorithm
- \param nbh All possible positions of the window
+ \param k the k parameter in Harris algorithm
+ \param sigma the standard deviation of the gaussian used in
+ Harris algorithm
\return The list of points detected as corner
\author J. Fabrizio
*/
- template<typename I, typename W, typename N>
+ template<typename I>
p_array<mln_site(I)>
- moravec(const Image<I>& in_image_, const Window<W>& win, const
Neighborhood<N>& nbh);
+ harris(const Image<I>& in_image_, float k, float sigma);
/**
- Computes Moravec corner detection on \p in_image
- with a default 3x3 window and a defaut 3x3 neighborhood.
+ Computes Harris corner detection on \p in_image with the
+ standard deviation of the guassian sets to 0.34
\param image_in_ The input image
+ \param k the k parameter in Harris algorithm
\return The list of points detected as corner
\author J. Fabrizio
*/
template<typename I>
p_array<mln_site(I)>
- moravec(const Image<I>& in_image_);
+ harris(const Image<I>& in_image_, float k);
+
+ /**
+ Computes Harris corner detection on \p in_image with the k
+ parameter sets to 0.04 and the standard deviation of the
+ guassian sets to 0.34.
+ \param image_in_ The input image
+ \return The list of points detected as corner
+
+ \author J. Fabrizio
+ */
+ template<typename I>
+ p_array<mln_site(I)>
+ harris(const Image<I>& in_image_);
# ifndef MLN_INCLUDE_ONLY
@@ -80,19 +99,18 @@ namespace mln
namespace internal
{
/**
- \iternal Computes local min to find corner in an image
+ \iternal Computes local max to find corner in an image
- \param image_in_ The result of moravec_criterion
+ \param image_in_ The result of harris_criterion
\return The list of local min
\author J. Fabrizio
*/
template<typename I>
p_array<mln_site(I)>
- moravec_local_min(const Image<I>& in_image_)
+ harris_local_max(const Image<I>& in_image_)
{
- trace::entering("detection::corner::moravec_local_min");
-
+ trace::exiting("detection::corner::harris_local_max");
const I& in_image = exact(in_image_);
p_array<mln_site(I)> result;
mln_piter(I) p(in_image.domain());
@@ -101,7 +119,7 @@ namespace mln
bool max = true;
mln_niter(neighb2d) n(c8(), p);
for_all(n) {
- if (in_image(p)<=in_image(n))
+ if (in_image(p)<=in_image(n))
{
max = false;
break;
@@ -111,28 +129,33 @@ namespace mln
result.append(p);
}
}
- trace::exiting("detection::corner::moravec_local_min");
+ trace::exiting("detection::corner::harris_local_max");
return result;
}
} // end of namespace mln::detection::corner::internal
- template<typename I, typename W, typename N>
+ template<typename I>
p_array<mln_site(I)>
- moravec(const Image<I>& in_image_, const Window<W>& win, const
Neighborhood<N>& nbh) {
- trace::entering("detection::corner::moravec");
- mln_ch_value(I, unsigned short) criterion_image;
- criterion_image = moravec_criterion(in_image_, win, nbh);
- trace::exiting("detection::corner::moravec");
- return internal::moravec_local_min(criterion_image);
+ harris(const Image<I>& in_image_, float k, float sigma) {
+ trace::entering("detection::corner::harris");
+ mln_ch_convolve(I, w_window2d_int) criterion_image;
+ criterion_image = harris_criterion(in_image_, k, sigma);
+ trace::exiting("detection::corner::harris");
+ return internal::harris_local_max(criterion_image);
}
template<typename I>
p_array<mln_site(I)>
- moravec(const Image<I>& in_image_) {
- return moravec(in_image_, win_c8p(), c8());
+ harris(const Image<I>& in_image_, float k) {
+ return harris(in_image_, k, 0.34);
}
+ template<typename I>
+ p_array<mln_site(I)>
+ harris(const Image<I>& in_image_) {
+ return harris(in_image_, 0.04, 0.34);
+ }
@@ -144,4 +167,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_DETECTION_CORNER_MORAVEC_HH
+#endif // ! MLN_DETECTION_CORNER_HARRIS_HH
diff --git a/milena/mln/detection/corner/harris_criterion.hh
b/milena/mln/detection/corner/harris_criterion.hh
new file mode 100644
index 0000000..0b125c6
--- /dev/null
+++ b/milena/mln/detection/corner/harris_criterion.hh
@@ -0,0 +1,123 @@
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef MLN_DETECTION_CORNER_HARRIS_CRITERION_HH
+# define MLN_DETECTION_CORNER_HARRIS_CRITERION_HH
+
+
+//#include <mln/io/essential.hh>
+//#include <mln/data/stretch.hh>
+//#include <mln/data/convert.hh>
+//#include <mln/value/graylevel.hh>
+# include <mln/core/alias/w_window2d_int.hh>
+
+/// \file
+///
+/// \brief Implementation of Harris corner detection.
+
+
+namespace mln
+{
+ namespace detection
+ {
+ namespace corner
+ {
+ /**
+ Computes Harris corner detection criterion on \p in_image.
+
+ \param image_in_ The input image.
+ \param k The k parameter in harris algorithm (use 0.04 if you
+ do not know what to do).
+ \param sigma The standard deviation of the gaussian used harris algorithm.
+
+ \return Harris criterion computed for evey pixel.
+
+ \author J. Fabrizio
+ */
+ template<typename I>
+ mln_ch_convolve(I, w_window2d_int)
+ harris_criterion(const Image<I>& in_image_, float k, float sigma);
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template<typename I>
+ mln_ch_convolve(I, w_window2d_int)
+ harris_criterion(const Image<I>& in_image_, float k, float sigma)
+ {
+ trace::entering("detection::corner::haris_criterion");
+
+ const I& in_image = exact(in_image_);
+ p_array<mln_site(I)> result;
+ typedef mln_ch_convolve(I, w_window2d_int) O;
+ O dx_image;
+ O dy_image;
+ O dxx_image;
+ O dxy_image;
+ O dyy_image;
+ O harris_criterion(in_image.domain());
+
+ typedef dpoint2d D;
+ w_window2d_int dx_grad;
+ dx_grad
+ .insert(-1, D(0, -1))
+ .insert(+1, D(0, +1));
+ w_window2d_int dy_grad;
+ dy_grad
+ .insert(-1, D(-1, 0))
+ .insert(+1, D(+1, 0));
+
+ dx_image=linear::convolve(in_image, dx_grad);
+ dy_image=linear::convolve(in_image, dy_grad);
+
+ dxx_image=linear::gaussian(dx_image*dx_image, sigma);
+ dxy_image=linear::gaussian(dx_image*dy_image, sigma);
+ dyy_image=linear::gaussian(dy_image*dy_image, sigma);
+
+ typedef mln_value(O) V;
+ mln_piter(I) p(in_image.domain());
+ for_all(p) {
+ V a = dxx_image(p);
+ V b = dyy_image(p);
+ V c = dxy_image(p);
+ harris_criterion(p)=(a*b-c*c)-k*(a+b)*(a+b);
+ }
+
+ // I output = data::stretch(mln_value(I)(), harris_criterion);
+ // io::pgm::save(output, "harris-criterion-result.pgm");
+
+ trace::exiting("detection::corner::harris_criterion");
+ return harris_criterion;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::detection::corner
+
+ } // end of namespace mln::detection
+
+} // end of namespace mln
+
+#endif // ! MLN_DETECTION_CORNER_HARRIS_CRITERION_HH
--
1.7.2.5