https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox
Index: ChangeLog
from Alexandre Abraham <abraham(a)lrde.epita.fr>
Add co-occurence matrix computing.
* nature/co_occurence.hh: New
(mln::co_occurence) : compute co-occurence matrix.
* nature/mco.cc: New
Dummy test.
co_occurence.hh | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
mco.cc | 45 +++++++++++++++++++++++++++++++++
2 files changed, 120 insertions(+)
Index: nature/co_occurence.hh
--- nature/co_occurence.hh (revision 0)
+++ nature/co_occurence.hh (revision 0)
@@ -0,0 +1,75 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library 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 this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library 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_CO_OCCURENCE_HH
+# define MLN_CO_OCCURENCE_HH
+
+/*! \file ??
+ *
+ * \brief FIXME
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/dpoint.hh>
+# include <mln/core/image/image2d.hh>
+# include <mln/level/fill.hh>
+
+
+namespace mln
+{
+
+
+ template <typename I, typename D>
+ // image2d<unsigned> co_occurence (const Image<I>&, const
Dpoint<D>&);
+ image2d<unsigned> co_occurence (const Image<I>&, const
Gdpoint<D>&);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename D>
+ image2d<unsigned> co_occurence (const Image<I> &ima_, const
Gdpoint<D> &dp_)
+ {
+ mln::metal::equal<mln_psite(I), mln_psite(D)>::check();
+
+ const I &ima = exact(ima_);
+ const D &dp = exact(dp_);
+ image2d<unsigned> mco(mln_card(mln_value(I)), mln_card(mln_value(I)), 0);
+ level::fill(mco, 0);
+
+
+ mln_piter(I) p(ima.domain());
+ for_all(p)
+ if (ima.domain().has(p + dp))
+ mco(point2d(ima(p), ima(p + dp)))++;
+
+ return mco;
+ }
+
+#endif // MLN_INCLUDE_ONLY
+
+}
+
+#endif // MLN_CO_OCCURENCE_HH
Index: nature/mco.cc
--- nature/mco.cc (revision 0)
+++ nature/mco.cc (revision 0)
@@ -0,0 +1,45 @@
+#include <iostream>
+
+#include <mln/value/int_u.hh>
+#include <mln/core/image/image2d.hh>
+#include "co_occurence.hh"
+#include <mln/core/alias/dpoint2d.hh>
+
+int main ()
+{
+ using namespace mln;
+ using namespace value;
+
+ typedef image2d< int_u<3> > I;
+
+ int_u<3> vs[6][5] = {
+
+ { 3, 3, 4, 4, 4 },
+ { 2, 1, 1, 1, 1 },
+ { 1, 4, 4, 4, 6 },
+ { 1, 4, 3, 4, 1 },
+ { 7, 4, 5, 3, 1 },
+ { 7, 7, 1, 1, 0 }
+
+ };
+
+ I ima(make::image2d(vs));
+
+ dpoint2d d(0, 1);
+
+ // std::cout << co_occurence(ima, d) << std::endl;
+
+ image2d<unsigned> co(co_occurence(ima, d));
+
+ unsigned cpt = 0;
+
+ mln_piter_(image2d<unsigned>) p(co.domain());
+ for_all(p)
+ {
+ std::cout << p << " = " << co(p) << std::endl;
+ cpt += co(p);
+ }
+
+ std::cout << cpt << std::endl;
+
+}