Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
* green/tests/accu/stat/histo2d : New directory.
* green/tests/accu/stat/histo2d/Makefile.am : New makefile.
* green/tests/accu/stat/histo2d/gaussian2d.sh : New calibrating tool.
---
.../green/tests/accu/stat/histo2d/Makefile.am | 148 ++++++++++++++++++++
.../green/tests/accu/stat/histo2d/gaussian2d.sh | 21 +++
2 files changed, 169 insertions(+), 0 deletions(-)
create mode 100644 trunk/milena/sandbox/green/tests/accu/stat/histo2d/Makefile.am
create mode 100755 trunk/milena/sandbox/green/tests/accu/stat/histo2d/gaussian2d.sh
diff --git a/trunk/milena/sandbox/green/tests/accu/stat/histo2d/Makefile.am b/trunk/milena/sandbox/green/tests/accu/stat/histo2d/Makefile.am
new file mode 100644
index 0000000..d970989
--- /dev/null
+++ b/trunk/milena/sandbox/green/tests/accu/stat/histo2d/Makefile.am
@@ -0,0 +1,148 @@
+#
+# Generic Makefile
+#
+
+#########
+# TOOLS #
+#########
+
+INCLUDES= -I$(HOME)/svn/oln/trunk/milena/sandbox/green
+CXXFLAGS= -ggdb -O0 -Wall -W -pedantic -ansi -pipe $(INCLUDES)
+ECHO= echo
+RM= rm
+MKDIR= mkdir -p
+CP= cp
+
+SOURCE_PATTERN= green/tests
+BUILD__PATTERN= green/build/tests
+
+
+ifeq ($(findstring $(BUILD__PATTERN),$(PWD)), $(BUILD__PATTERN))
+# Case where make is done from build directory.
+SOURCE_DIR= $(subst $(BUILD__PATTERN),$(SOURCE_PATTERN),$(PWD))
+BUILD__DIR= $(PWD)
+else
+# Case where make is done from source directory.
+SOURCE_DIR= $(PWD)
+BUILD__DIR= $(subst $(SOURCE_PATTERN),$(BUILD__PATTERN),$(PWD))
+endif
+
+SRC= $(notdir $(wildcard $(SOURCE_DIR)/*.cc))
+OLD= $(notdir $(wildcard $(SOURCE_DIR)/*~))
+OBJ= $(patsubst %.cc,%.o,$(SRC))
+SOURCE_MAKEFILE=Makefile.am
+BUILD__MAKEFILE=Makefile
+TARGET_FILE= $(notdir $(PWD))
+SOURCE_FILES= $(notdir $(wildcard $(SOURCE_DIR)/*.*))
+BUILD__FILES= $(filter-out $(SRC) $(SOURCE_MAKEFILE), $(SOURCE_FILES))
+
+BUILD__F_PATH= $(addprefix $(BUILD__DIR)/,$(BUILD__FILES))
+SOURCE_F_PATH= $(addprefix $(SOURCE_DIR)/,$(SOURCE_FILES))
+
+BUILD__M_PATH= $(addprefix $(BUILD__DIR)/,$(BUILD__MAKEFILE))
+SOURCE_M_PATH= $(addprefix $(SOURCE_DIR)/,$(SOURCE_MAKEFILE))
+
+TARGET_F_PATH= $(addprefix $(BUILD__DIR)/,$(TARGET_FILE))
+OBJ_F_PATH= $(addprefix $(BUILD__DIR)/,$(OBJ))
+SRC_F_PATH= $(addprefix $(SOURCE_DIR)/,$(SRC))
+OLD_F_PATH= $(addprefix $(SOURCE_DIR)/,$(OLD))
+
+#############
+# BOOTSTRAP #
+#############
+
+
+bootstrap: $(BUILD__DIR) $(BUILD__F_PATH) $(BUILD__M_PATH)
+
+# Create, if nessary, the destination directory
+$(BUILD__DIR):
+ $(MKDIR) $(BUILD__DIR)
+
+# Copy, if nessary, all the files, except the Makefile.am
+$(BUILD__F_PATH): $(SOURCE_F_PATH)
+ $(CP) $(addprefix $(SOURCE_DIR)/,$(@F)) $@
+
+# Copy if nessary, the Makefile.am into Makefile
+$(BUILD__M_PATH): $(SOURCE_M_PATH)
+ $(CP) $(SOURCE_M_PATH) $(BUILD__M_PATH)
+
+
+#######
+# ALL #
+#######
+
+# We assume that the call is done from the build directory.
+# With the directive vpath, hidden files are found in the source directory.
+
+all: $(TARGET_F_PATH)
+
+
+$(TARGET_F_PATH): $(OBJ_F_PATH)
+ $(LINK.cc) $< $(LOADLIBES) $(LDLIBS) -o $@
+
+$(OBJ_F_PATH):$(SRC_F_PATH)
+ $(COMPILE.cc) $(OUTPUT_OPTION) $<
+
+
+#########
+# CLEAN #
+#########
+
+# Force every time the deletion
+clean: clean_target clean_obj clean_dst clean_old #clean_make
+
+
+clean_target:
+ -@$(RM) $(TARGET_F_PATH) &> /dev/null
+
+clean_obj:
+ -@$(RM) $(OBJ_F_PATH) &> /dev/null
+
+clean_dst:
+ -@$(RM) $(BUILD_F_PATH) &> /dev/null
+
+clean_make:
+ -@$(RM) $(BUILD_M_PATH) &> /dev/null
+
+clean_old:
+ -@$(RM) $(OLD_F_PATH) &> /dev/null
+
+
+#########
+# PRINT #
+#########
+
+print: print_tools print_bootstrap
+
+print_tools:
+ @$(ECHO) "HOME = $(HOME)"
+ @$(ECHO) "INCLUDES = $(INCLUDES)"
+ @$(ECHO) "CXXFLAGS = $(CXXFLAGS)"
+ @$(ECHO) "ECHO = $(ECHO)"
+ @$(ECHO) "RM = $(RM)"
+ @$(ECHO) "MKDIR = $(MKDIR)"
+ @$(ECHO) "CP = $(CP)"
+ @$(ECHO)
+
+print_bootstrap:
+ @$(ECHO) "PWD = $(PWD)"
+ @$(ECHO) "SOURCE_PATTERN = $(SOURCE_PATTERN)"
+ @$(ECHO) "BUILD__PATTERN = $(BUILD__PATTERN)"
+ @$(ECHO) "SOURCE_DIR = $(SOURCE_DIR)"
+ @$(ECHO) "BUILD__DIR = $(BUILD__DIR)"
+ @$(ECHO) "SOURCE_MAKEFILE = $(SOURCE_MAKEFILE)"
+ @$(ECHO) "BUILD__MAKEFILE = $(BUILD__MAKEFILE)"
+ @$(ECHO) "TARGET_FILE = $(TARGET_FILE)"
+ @$(ECHO) "SOURCE_FILES = $(SOURCE_FILES)"
+ @$(ECHO) "SOURCE_F_PATH = $(SOURCE_F_PATH)"
+ @$(ECHO) "BUILD__FILES = $(BUILD__FILES)"
+ @$(ECHO) "BUILD__F_PATH = $(BUILD__F_PATH)"
+ @$(ECHO) "BUILD__M_PATH = $(BUILD__M_PATH)"
+ @$(ECHO) "SOURCE_M_PATH = $(SOURCE_M_PATH)"
+ @$(ECHO) "SRC = $(SRC)"
+ @$(ECHO) "OBJ = $(OBJ)"
+ @$(ECHO) "OLD = $(OLD)"
+ @$(ECHO) "SRC_F_PATH = $(SRC_F_PATH)"
+ @$(ECHO) "OBJ_F_PATH = $(OBJ_F_PATH)"
+ @$(ECHO) "OLD_F_PATH = $(OLD_F_PATH)"
+ @$(ECHO)
diff --git a/trunk/milena/sandbox/green/tests/accu/stat/histo2d/gaussian2d.sh b/trunk/milena/sandbox/green/tests/accu/stat/histo2d/gaussian2d.sh
new file mode 100755
index 0000000..313fbf0
--- /dev/null
+++ b/trunk/milena/sandbox/green/tests/accu/stat/histo2d/gaussian2d.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+############
+# gaussian #
+############
+
+# support 6 sigma sur chaque axe
+
+gnuplot <<EOF
+set terminal x11 persist 1
+square(x)=x*x
+gaussian(x,mean,sigma)=exp(-0.5*square((x-mean)/sigma))/(sigma*sqrt(2*pi))
+gaussian2d(x,y,mx,my,sx,sy)=gaussian(x,mx,sx)*gaussian(y,my,sy)
+
+
+set view 50
+#set grid
+#set contour
+set isosample 20
+splot [x=-20:20][y=-20:20] gaussian2d(x,y,0,0,6,6) with line palette
+EOF
--
1.5.6.5
1
0
[PATCH 5/5] configure.ac: Configure milena/apps/graph-morpho/Makefile.
by Roland Levillain 08 Sep '09
by Roland Levillain 08 Sep '09
08 Sep '09
---
ChangeLog | 4 ++++
configure.ac | 1 +
2 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8e7d38b..e2991df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-09-08 Roland Levillain <roland(a)lrde.epita.fr>
+
+ * configure.ac: Configure milena/apps/graph-morpho/Makefile.
+
2009-09-04 Roland Levillain <roland(a)lrde.epita.fr>
* configure.ac: s/statues/mesh-segm-skel/.
diff --git a/configure.ac b/configure.ac
index 30706f0..c7a2487 100644
--- a/configure.ac
+++ b/configure.ac
@@ -399,6 +399,7 @@ AM_CONDITIONAL([ENABLE_APPS], [test "x$enable_apps" = "xyes"])
AC_CONFIG_FILES([
milena/apps/Makefile
milena/apps/mesh-segm-skel/Makefile
+ milena/apps/graph-morpho/Makefile
])
# Configure tests.
--
1.6.4.2
1
0
08 Sep '09
* apps/graph-morpho/: New directory.
* apps/graph-morpho/complex1d.cc: New.
* apps/graph-morpho/Makefile.am: New.
---
milena/ChangeLog | 8 +
milena/apps/Makefile.am | 2 +-
milena/apps/{ => graph-morpho}/Makefile.am | 14 +-
milena/apps/graph-morpho/complex1d.cc | 390 ++++++++++++++++++++++++++++
4 files changed, 409 insertions(+), 5 deletions(-)
copy milena/apps/{ => graph-morpho}/Makefile.am (67%)
create mode 100644 milena/apps/graph-morpho/complex1d.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 223d040..4bbe8e2 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,11 @@
+2009-09-08 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Morphological operators on graphs (using 1-complexes).
+
+ * apps/graph-morpho/: New directory.
+ * apps/graph-morpho/complex1d.cc: New.
+ * apps/graph-morpho/Makefile.am: New.
+
2009-09-04 Roland Levillain <roland(a)lrde.epita.fr>
Adjust names w.r.t. apps/mesh-segm-skel/.
diff --git a/milena/apps/Makefile.am b/milena/apps/Makefile.am
index 3e41536..2150657 100644
--- a/milena/apps/Makefile.am
+++ b/milena/apps/Makefile.am
@@ -17,4 +17,4 @@
## Process this file through Automake to produce Makefile.in.
-SUBDIRS = mesh-segm-skel
+SUBDIRS = mesh-segm-skel graph-morpho
diff --git a/milena/apps/Makefile.am b/milena/apps/graph-morpho/Makefile.am
similarity index 67%
copy from milena/apps/Makefile.am
copy to milena/apps/graph-morpho/Makefile.am
index 3e41536..590e756 100644
--- a/milena/apps/Makefile.am
+++ b/milena/apps/graph-morpho/Makefile.am
@@ -1,4 +1,4 @@
-# Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE).
+# Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE).
#
# This file is part of Olena.
#
@@ -13,8 +13,14 @@
#
# You should have received a copy of the GNU General Public License
# along with Olena. If not, see <http://www.gnu.org/licenses/>.
-#
-## Process this file through Automake to produce Makefile.in.
+# Find Milena headers.
+AM_CPPFLAGS = -I$(top_srcdir)/milena
+# Produce fast code.
+APPS_CXXFLAGS = @APPS_CXXFLAGS@
+AM_CXXFLAGS = $(APPS_CXXFLAGS)
+
+bin_PROGRAMS = complex1d
+complex1d_SOURCES = complex1d.cc
-SUBDIRS = mesh-segm-skel
+TESTS = complex1d
diff --git a/milena/apps/graph-morpho/complex1d.cc b/milena/apps/graph-morpho/complex1d.cc
new file mode 100644
index 0000000..8587040
--- /dev/null
+++ b/milena/apps/graph-morpho/complex1d.cc
@@ -0,0 +1,390 @@
+// Copyright (C) 2008, 2009 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.
+
+/// \file
+/// \brief Morphological operators in graph space implemented on
+/// 1-complex images.
+///
+/// \todo There should be a second version of this program, where the
+/// graph structure is implemented with an actual graph.
+
+#include <mln/core/image/complex_image.hh>
+#include <mln/geom/complex_geometry.hh>
+#include <mln/core/image/complex_neighborhoods.hh>
+#include <mln/core/image/complex_neighborhood_piter.hh>
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/point2d.hh>
+#include <mln/core/alias/box2d.hh>
+
+#include <mln/core/site_set/p_set.hh>
+#include <mln/util/site_pair.hh>
+
+
+using namespace mln;
+
+// A graph is considered as a 1-complex here.
+const unsigned dim = 1;
+typedef topo::complex<dim> complex_t;
+
+// Binary graph-based image with vertices aligned on a discrete 2D grid.
+typedef point2d site_t;
+typedef geom::complex_geometry<dim, site_t> geom_t;
+typedef complex_image<dim, geom_t, bool> ima_t;
+
+// Iterator type on faces (vertices and edges).
+typedef p_n_faces_fwd_piter<dim, geom_t> face_iter;
+// Edge-to-vertices neighborhood.
+typedef complex_lower_neighborhood<dim, geom_t> e2v_t;
+const e2v_t e2v;
+// Vertex-to-edges neighborhood.
+typedef complex_higher_neighborhood<dim, geom_t> v2e_t;
+const v2e_t v2e;
+
+
+// FIXME: We should turn this routine into something much more
+// generic, and move it to the library (into make/).
+ima_t
+build_regular_complex1d_image(const box2d& support)
+{
+ unsigned nrows = support.pmax().row() - support.pmin().row() + 1;
+ unsigned ncols = support.pmax().col() - support.pmin().col() + 1;
+
+ typedef topo::n_face<0, dim> vertex_t;
+
+ complex_t c;
+ geom_t geom;
+
+ // Vertices.
+ for (unsigned row = 0; row < nrows; ++row)
+ for (unsigned col = 0; col < ncols; ++col)
+ {
+ c.add_face();
+ geom.add_location(point2d(row,col));
+ }
+
+ // Edges.
+ for (unsigned row = 0; row < nrows; ++row)
+ {
+ // Horizontal edges.
+ for (unsigned col = 1; col < ncols; ++col)
+ {
+ // First vertex.
+ vertex_t v1(c, row * ncols + col - 1);
+ // Second vertex.
+ vertex_t v2(c, row * ncols + col);
+ // Edge bewteen V1 and V2.
+ c.add_face(v1 + v2);
+ }
+
+ // Vertical edges.
+ if (row != 0)
+ for (unsigned col = 0; col < ncols; ++col)
+ {
+ // First vertex.
+ vertex_t v1(c, (row - 1) * ncols + col);
+ // Second vertex.
+ vertex_t v2(c, row * ncols + col);
+ // Edge bewteen V1 and V2.
+ c.add_face(v1 + v2);
+ }
+ }
+
+ // Site set (domain) of the image.
+ p_complex<dim, geom_t> pc(c, geom);
+
+ // Image based on this site set.
+ ima_t ima(pc);
+ return ima;
+}
+
+
+template <typename T>
+void
+println(const complex_image<dim, geom_t, T>& ima, const box2d& support)
+{
+ // These are admittedly loose preconditions, but we cannot check
+ // much.
+ mln_precondition(ima.nsites() == support.nsites());
+
+ image2d<bool> vertices(support);
+ image2d<bool> h_edges(box2d(support.pmin(), support.pmax() - dpoint2d(0, 1)));
+ image2d<bool> v_edges(box2d(support.pmin(), support.pmax() - dpoint2d(1, 0)));
+
+ // Iterator on vertices.
+ p_n_faces_fwd_piter<dim, geom_t> v(ima.domain(), 0);
+ for_all(v)
+ {
+ mln_site_(geom_t) s(v);
+ // Site S is point2d multi-site and should be a singleton (since V
+ // iterates on vertices).
+ mln_invariant(s.size() == 1);
+ point2d p = s.front();
+ vertices(p) = ima(v);
+ }
+
+ // Iterator on edges.
+ p_n_faces_fwd_piter<dim, geom_t> e(ima.domain(), 1);
+ for_all(e)
+ {
+ mln_site_(geom_t) s(e);
+ // Site S is point2d multi-site and should be a pair (since E
+ // iterates on vertices).
+ mln_invariant(s.size() == 2);
+ point2d p1 = s[0];
+ point2d p2 = s[1];
+ if (p1.row() == p2.row())
+ {
+ // Horizontal edge.
+ h_edges(p1) = ima(e);
+ }
+ else
+ {
+ // Vertical edge.
+ mln_assertion(p1.col() == p2.col());
+ v_edges(p1) = ima(e);
+ }
+ }
+
+ for (int row = vertices.domain().pmin().row();
+ row <= vertices.domain().pmax().row(); ++row)
+ {
+ for (int col = vertices.domain().pmin().col();
+ col <= vertices.domain().pmax().col(); ++col)
+ {
+ point2d p(row, col);
+ // Vertex.
+ std::cout << (vertices(p) ? "O" : ".");
+ // Potential horizontal edge on the right of the vertex.
+ if (col != vertices.domain().pmax().col())
+ std::cout << (h_edges(p) ? " - " : " ");
+ }
+ std::cout << std::endl;
+
+ // Potential vertical edge below the vertices of the current ROW.
+ if (row != vertices.domain().pmax().row())
+ for (int col = vertices.domain().pmin().col();
+ col <= vertices.domain().pmax().col(); ++col)
+ {
+ point2d p(row, col);
+ std::cout << (v_edges(p) ? "| " : " ");
+ }
+ std::cout << std::endl;
+ }
+}
+
+/*------------------------------------.
+| Morphological operators on graphs. |
+`------------------------------------*/
+
+/* FIXME: By constraining the domain of the input and passing the
+ neighborhood, one should be able to use a truly generic dilation
+ (resp. erosion), or even use Milena's standard morpho::dilation
+ (resp. morpho::erosion). */
+
+/// Dilation from edges to vertices (delta^dot).
+template <typename I>
+mln_concrete(I)
+dilation_e2v(const Image<I>& input_)
+{
+ const I& input = exact(input_);
+ mln_concrete(I) output;
+ initialize(output, input);
+ p_n_faces_fwd_piter<dim, geom_t> v(input.domain(), 0);
+ mln_niter_(v2e_t) e(v2e, v);
+ for_all(v)
+ {
+ output(v) = false;
+ for_all(e)
+ if (input(e))
+ {
+ output(v) = true;
+ break;
+ }
+ }
+ return output;
+}
+
+/// Erosion from vertices to edges (erosion^cross).
+template <typename I>
+mln_concrete(I)
+erosion_v2e(const Image<I>& input_)
+{
+ const I& input = exact(input_);
+ mln_concrete(I) output;
+ initialize(output, input);
+ p_n_faces_fwd_piter<dim, geom_t> e(input.domain(), 1);
+ mln_niter_(e2v_t) v(e2v, e);
+ for_all(e)
+ {
+ output(e) = true;
+ for_all(v)
+ if (!input(v))
+ {
+ output(e) = false;
+ break;
+ }
+ }
+ return output;
+}
+
+/// Erosion from edges to vertices (erosion^dot).
+template <typename I>
+mln_concrete(I)
+erosion_e2v(const Image<I>& input_)
+{
+ const I& input = exact(input_);
+ mln_concrete(I) output;
+ initialize(output, input);
+ p_n_faces_fwd_piter<dim, geom_t> v(input.domain(), 0);
+ mln_niter_(v2e_t) e(v2e, v);
+ for_all(v)
+ {
+ output(v) = true;
+ for_all(e)
+ if (!input(e))
+ {
+ output(v) = false;
+ break;
+ }
+ }
+ return output;
+}
+
+/// Dilation from vertices to edges (dilation^cross).
+template <typename I>
+mln_concrete(I)
+dilation_v2e(const Image<I>& input_)
+{
+ const I& input = exact(input_);
+ mln_concrete(I) output;
+ initialize(output, input);
+ p_n_faces_fwd_piter<dim, geom_t> e(input.domain(), 1);
+ mln_niter_(e2v_t) v(e2v, e);
+ for_all(e)
+ {
+ output(e) = false;
+ for_all(v)
+ if (input(v))
+ {
+ output(e) = true;
+ break;
+ }
+ }
+ return output;
+}
+
+
+int main()
+{
+ /*--------------.
+ | Input image. |
+ `--------------*/
+
+ /* Build a ``regular'' graph image. Of course, it would have been
+ better, simpler and faster to use a cubical 1-complex here, but
+ they are not yet available. */
+ box2d b(9, 6);
+ ima_t ima = build_regular_complex1d_image(b);
+
+ /* Set the values so that IMA corresponds to the graph G of the ISMM
+ 2009 paper from Jean Cousty et al. */
+
+ // The set of vertices of the graph.
+ p_set<point2d> vertices;
+ vertices.insert(point2d(1, 2));
+ vertices.insert(point2d(2, 1));
+ vertices.insert(point2d(2, 2));
+ vertices.insert(point2d(3, 4));
+ vertices.insert(point2d(5, 2));
+ vertices.insert(point2d(5, 3));
+ vertices.insert(point2d(5, 4));
+ vertices.insert(point2d(6, 1));
+ vertices.insert(point2d(6, 2));
+ vertices.insert(point2d(6, 3));
+ vertices.insert(point2d(6, 4));
+ vertices.insert(point2d(7, 2));
+ vertices.insert(point2d(7, 3));
+ // Add vertices.
+ p_n_faces_fwd_piter<dim, geom_t> v(ima.domain(), 0);
+ for_all(v)
+ {
+ mln_site_(geom_t) s(v);
+ // Site S is point2d multi-site and should be a singleton (since V
+ // iterates on vertices).
+ mln_invariant(s.size() == 1);
+ point2d p = s.front();
+ ima(v) = vertices.has(p);
+ }
+
+ // The set of edges of the graph.
+ typedef util::site_pair<point2d> point2d_pair;
+ p_set< util::site_pair<point2d> > edges;
+ edges.insert(point2d_pair(point2d(2, 1), point2d(2, 2)));
+ edges.insert(point2d_pair(point2d(5, 3), point2d(5, 4)));
+ edges.insert(point2d_pair(point2d(5, 2), point2d(6, 2)));
+ edges.insert(point2d_pair(point2d(5, 3), point2d(6, 3)));
+ edges.insert(point2d_pair(point2d(6, 1), point2d(6, 2)));
+ edges.insert(point2d_pair(point2d(6, 2), point2d(6, 3)));
+ edges.insert(point2d_pair(point2d(6, 3), point2d(6, 4)));
+ edges.insert(point2d_pair(point2d(6, 2), point2d(7, 2)));
+ edges.insert(point2d_pair(point2d(6, 3), point2d(7, 3)));
+ edges.insert(point2d_pair(point2d(7, 2), point2d(7, 3)));
+ // Add edges.
+ p_n_faces_fwd_piter<dim, geom_t> e(ima.domain(), 1);
+ for_all(e)
+ {
+ mln_site_(geom_t) s(e);
+ // Site S is point2d multi-site and should be a pair (since E
+ // iterates on vertices).
+ mln_invariant(s.size() == 2);
+ point2d p1 = s[0];
+ point2d p2 = s[1];
+ ima(e) =
+ edges.has(point2d_pair(p1, p2)) || edges.has(point2d_pair(p2, p1));
+ }
+ std::cout << "ima:" << std::endl;
+ println(ima, b);
+
+ /*-----------------------------------.
+ | Applying morphological operators. |
+ `-----------------------------------*/
+
+ ima_t dil_e2v_ima = dilation_e2v(ima);
+ std::cout << "dil_e2v_ima:" << std::endl;
+ println(dil_e2v_ima, b);
+
+ ima_t ero_v2e_ima = erosion_v2e(ima);
+ std::cout << "ero_v2e_ima:" << std::endl;
+ println(ero_v2e_ima, b);
+
+ ima_t ero_e2v_ima = erosion_e2v(ima);
+ std::cout << "ero_e2v_ima:" << std::endl;
+ println(ero_e2v_ima, b);
+
+ ima_t dil_v2e_ima = dilation_v2e(ima);
+ std::cout << "dil_v2e_ima:" << std::endl;
+ println(dil_v2e_ima, b);
+}
--
1.6.4.2
1
0
---
ChangeLog | 4 ++++
configure.ac | 28 ++++++++++++++--------------
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0df5daa..8e7d38b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-09-04 Roland Levillain <roland(a)lrde.epita.fr>
+
+ * configure.ac: s/statues/mesh-segm-skel/.
+
2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
* configure.ac: Configure scribo/src/text/*.
diff --git a/configure.ac b/configure.ac
index 75e34da..30706f0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -398,25 +398,25 @@ AM_CONDITIONAL([ENABLE_APPS], [test "x$enable_apps" = "xyes"])
# Ask for the creation of applications' Makefiles.
AC_CONFIG_FILES([
milena/apps/Makefile
- milena/apps/statues/Makefile
+ milena/apps/mesh-segm-skel/Makefile
])
# Configure tests.
# FIXME: Consider using `sed' instead of `configure' to create these
# tests for the sake of speed.
-AC_CONFIG_FILES([milena/apps/statues/test-mesh-max-curv],
- [chmod +x milena/apps/statues/test-mesh-max-curv])
-AC_CONFIG_FILES([milena/apps/statues/test-mesh-complex-max-curv],
- [chmod +x milena/apps/statues/test-mesh-complex-max-curv])
-AC_CONFIG_FILES([milena/apps/statues/test-mesh-segm],
- [chmod +x milena/apps/statues/test-mesh-segm])
-AC_CONFIG_FILES([milena/apps/statues/test-mesh-complex-segm],
- [chmod +x milena/apps/statues/test-mesh-complex-segm])
-AC_CONFIG_FILES([milena/apps/statues/test-mesh-complex-max-curv-segm],
- [chmod +x milena/apps/statues/test-mesh-complex-max-curv-segm])
-
-AC_CONFIG_FILES([milena/apps/statues/test-mesh-complex-skel],
- [chmod +x milena/apps/statues/test-mesh-complex-skel])
+AC_CONFIG_FILES([milena/apps/mesh-segm-skel/test-mesh-max-curv],
+ [chmod +x milena/apps/mesh-segm-skel/test-mesh-max-curv])
+AC_CONFIG_FILES([milena/apps/mesh-segm-skel/test-mesh-complex-max-curv],
+ [chmod +x milena/apps/mesh-segm-skel/test-mesh-complex-max-curv])
+AC_CONFIG_FILES([milena/apps/mesh-segm-skel/test-mesh-segm],
+ [chmod +x milena/apps/mesh-segm-skel/test-mesh-segm])
+AC_CONFIG_FILES([milena/apps/mesh-segm-skel/test-mesh-complex-segm],
+ [chmod +x milena/apps/mesh-segm-skel/test-mesh-complex-segm])
+AC_CONFIG_FILES([milena/apps/mesh-segm-skel/test-mesh-complex-max-curv-segm],
+ [chmod +x milena/apps/mesh-segm-skel/test-mesh-complex-max-curv-segm])
+
+AC_CONFIG_FILES([milena/apps/mesh-segm-skel/test-mesh-complex-skel],
+ [chmod +x milena/apps/mesh-segm-skel/test-mesh-complex-skel])
# Flags for apps.
AC_ARG_VAR([APPS_CXXFLAGS])
--
1.6.4.2
1
0
* apps/Makefile.am,
* apps/mesh-segm-skel/mesh-complex-max-curv-segm.cc,
* apps/mesh-segm-skel/mesh-complex-max-curv.cc,
* apps/mesh-segm-skel/mesh-complex-segm.cc,
* apps/mesh-segm-skel/mesh-complex-skel.cc,
* apps/mesh-segm-skel/mesh-max-curv.cc,
* apps/mesh-segm-skel/mesh-pinv-curv.cc,
* apps/mesh-segm-skel/mesh-segm.cc,
* apps/mesh-segm-skel/mesh-skel.cc,
* mesh/Makefile.am:
s/statues/mesh-segm-skel/.
* apps/mesh-segm-skel/io.hh,
* apps/mesh-segm-skel/save_bin_alt.hh,
* apps/mesh-segm-skel/trimesh/misc.hh:
Likewise.
Adjust header guards.
---
milena/ChangeLog | 21 ++++++++++++++++++++
milena/apps/Makefile.am | 2 +-
milena/apps/mesh-segm-skel/io.hh | 8 +++---
.../mesh-segm-skel/mesh-complex-max-curv-segm.cc | 2 +-
.../apps/mesh-segm-skel/mesh-complex-max-curv.cc | 2 +-
milena/apps/mesh-segm-skel/mesh-complex-segm.cc | 2 +-
milena/apps/mesh-segm-skel/mesh-complex-skel.cc | 2 +-
milena/apps/mesh-segm-skel/mesh-max-curv.cc | 2 +-
milena/apps/mesh-segm-skel/mesh-pinv-curv.cc | 2 +-
milena/apps/mesh-segm-skel/mesh-segm.cc | 2 +-
milena/apps/mesh-segm-skel/mesh-skel.cc | 2 +-
milena/apps/mesh-segm-skel/save_bin_alt.hh | 6 ++--
milena/apps/mesh-segm-skel/trimesh/misc.hh | 6 ++--
milena/mesh/Makefile.am | 12 +++++-----
14 files changed, 46 insertions(+), 25 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index dc2e0a1..223d040 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,26 @@
2009-09-04 Roland Levillain <roland(a)lrde.epita.fr>
+ Adjust names w.r.t. apps/mesh-segm-skel/.
+
+ * apps/Makefile.am,
+ * apps/mesh-segm-skel/mesh-complex-max-curv-segm.cc,
+ * apps/mesh-segm-skel/mesh-complex-max-curv.cc,
+ * apps/mesh-segm-skel/mesh-complex-segm.cc,
+ * apps/mesh-segm-skel/mesh-complex-skel.cc,
+ * apps/mesh-segm-skel/mesh-max-curv.cc,
+ * apps/mesh-segm-skel/mesh-pinv-curv.cc,
+ * apps/mesh-segm-skel/mesh-segm.cc,
+ * apps/mesh-segm-skel/mesh-skel.cc,
+ * mesh/Makefile.am:
+ s/statues/mesh-segm-skel/.
+ * apps/mesh-segm-skel/io.hh,
+ * apps/mesh-segm-skel/save_bin_alt.hh,
+ * apps/mesh-segm-skel/trimesh/misc.hh:
+ Likewise.
+ Adjust header guards.
+
+2009-09-04 Roland Levillain <roland(a)lrde.epita.fr>
+
Rename apps/statues/ as apps/mesh-segm-skel/.
* apps/statues/: Rename directory as...
diff --git a/milena/apps/Makefile.am b/milena/apps/Makefile.am
index e1555f6..3e41536 100644
--- a/milena/apps/Makefile.am
+++ b/milena/apps/Makefile.am
@@ -17,4 +17,4 @@
## Process this file through Automake to produce Makefile.in.
-SUBDIRS = statues
+SUBDIRS = mesh-segm-skel
diff --git a/milena/apps/mesh-segm-skel/io.hh b/milena/apps/mesh-segm-skel/io.hh
index 978ad40..4f8f084 100644
--- a/milena/apps/mesh-segm-skel/io.hh
+++ b/milena/apps/mesh-segm-skel/io.hh
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef APPS_STATUES_IO_HH
-# define APPS_STATUES_IO_HH
+#ifndef APPS_MESH_SEGM_SKEL_IO_HH
+# define APPS_MESH_SEGM_SKEL_IO_HH
-/// \file apps/statues/io.hh
+/// \file apps/mesh-segm-skel/io.hh
/// \brief I/O routines adapted from TriMesh's ones.
#include <algorithm>
@@ -202,4 +202,4 @@ inline void write_off_binary(TriMesh *mesh,
}
/// \}
-#endif // ! APPS_STATUES_IO_HH
+#endif // ! APPS_MESH_SEGM_SKEL_IO_HH
diff --git a/milena/apps/mesh-segm-skel/mesh-complex-max-curv-segm.cc b/milena/apps/mesh-segm-skel/mesh-complex-max-curv-segm.cc
index 4c08227..477ccdf 100644
--- a/milena/apps/mesh-segm-skel/mesh-complex-max-curv-segm.cc
+++ b/milena/apps/mesh-segm-skel/mesh-complex-max-curv-segm.cc
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file apps/statues/mesh-complex-max-curv-segm.cc
+/// \file apps/mesh-segm-skel/mesh-complex-max-curv-segm.cc
/// \brief A program computing the maximal curvature values from the
/// surface of the (triangle) mesh of a statue, then performing a
/// WST-based segmentation, using a complex-based image.
diff --git a/milena/apps/mesh-segm-skel/mesh-complex-max-curv.cc b/milena/apps/mesh-segm-skel/mesh-complex-max-curv.cc
index 9924a91..8d79839 100644
--- a/milena/apps/mesh-segm-skel/mesh-complex-max-curv.cc
+++ b/milena/apps/mesh-segm-skel/mesh-complex-max-curv.cc
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file apps/statues/mesh-complex-max-curv.cc
+/// \file apps/mesh-segm-skel/mesh-complex-max-curv.cc
/// \brief A program computing the max curvature at each (2-)face of
/// the surface of the (triangle) mesh of a statue, using a
/// complex-based image.
diff --git a/milena/apps/mesh-segm-skel/mesh-complex-segm.cc b/milena/apps/mesh-segm-skel/mesh-complex-segm.cc
index 041ec7c..8d349fe 100644
--- a/milena/apps/mesh-segm-skel/mesh-complex-segm.cc
+++ b/milena/apps/mesh-segm-skel/mesh-complex-segm.cc
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file apps/statues/mesh-complex-segm.cc
+/// \file apps/mesh-segm-skel/mesh-complex-segm.cc
/// \brief A program performing a WST-based segmentation of the
/// surface of the (triangle) mesh of a statue, using a complex-based
/// image.
diff --git a/milena/apps/mesh-segm-skel/mesh-complex-skel.cc b/milena/apps/mesh-segm-skel/mesh-complex-skel.cc
index 1834e2d..a4df815 100644
--- a/milena/apps/mesh-segm-skel/mesh-complex-skel.cc
+++ b/milena/apps/mesh-segm-skel/mesh-complex-skel.cc
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file apps/statues/mesh-complex-skel.cc
+/// \file apps/mesh-segm-skel/mesh-complex-skel.cc
/// \brief A program computing a skeleton of the surface of the
/// (triangle) mesh of a statue (by thinning), using a complex-based
/// image.
diff --git a/milena/apps/mesh-segm-skel/mesh-max-curv.cc b/milena/apps/mesh-segm-skel/mesh-max-curv.cc
index ee7f9e3..b612478 100644
--- a/milena/apps/mesh-segm-skel/mesh-max-curv.cc
+++ b/milena/apps/mesh-segm-skel/mesh-max-curv.cc
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file apps/statues/mesh-max-curv.cc
+/// \file apps/mesh-segm-skel/mesh-max-curv.cc
/// \brief A program computing the max curvature at each (2-)face of
/// a mesh.
diff --git a/milena/apps/mesh-segm-skel/mesh-pinv-curv.cc b/milena/apps/mesh-segm-skel/mesh-pinv-curv.cc
index 91802b3..69a9492 100644
--- a/milena/apps/mesh-segm-skel/mesh-pinv-curv.cc
+++ b/milena/apps/mesh-segm-skel/mesh-pinv-curv.cc
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file apps/statues/mesh-pinv-curv.cc
+/// \file apps/mesh-segm-skel/mesh-pinv-curv.cc
/// \brief A program computing the pseudo-inverse curvature at each
/// (2-)face of a mesh.
diff --git a/milena/apps/mesh-segm-skel/mesh-segm.cc b/milena/apps/mesh-segm-skel/mesh-segm.cc
index da4b24d..bf87249 100644
--- a/milena/apps/mesh-segm-skel/mesh-segm.cc
+++ b/milena/apps/mesh-segm-skel/mesh-segm.cc
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file apps/statues/mesh-segm.cc
+/// \file apps/mesh-segm-skel/mesh-segm.cc
/// \brief A program performing a WST-based segmentation of the
/// surface of the (triangle) mesh of a statue.
diff --git a/milena/apps/mesh-segm-skel/mesh-skel.cc b/milena/apps/mesh-segm-skel/mesh-skel.cc
index 68dfb85..0b96199 100644
--- a/milena/apps/mesh-segm-skel/mesh-skel.cc
+++ b/milena/apps/mesh-segm-skel/mesh-skel.cc
@@ -25,7 +25,7 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file apps/statues/mesh-skel.cc
+/// \file apps/mesh-segm-skel/mesh-skel.cc
/// \brief A program computing a skeleton of the surface of the
/// (triangle) mesh of a statue.
diff --git a/milena/apps/mesh-segm-skel/save_bin_alt.hh b/milena/apps/mesh-segm-skel/save_bin_alt.hh
index e422578..034b840 100644
--- a/milena/apps/mesh-segm-skel/save_bin_alt.hh
+++ b/milena/apps/mesh-segm-skel/save_bin_alt.hh
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef APPS_STATUES_SAVE_BIN_ALT_HH
-# define APPS_STATUES_SAVE_BIN_ALT_HH
+#ifndef APPS_MESH_SEGM_SKEL_SAVE_BIN_ALT_HH
+# define APPS_MESH_SEGM_SKEL_SAVE_BIN_ALT_HH
/*--------------------------------------------------------------------.
| FIXME: Copied and adjusted (in a hurry) from mln/io/off/save.hh, |
@@ -186,4 +186,4 @@ namespace mln
} // end of namespace mln
-#endif // ! APPS_STATUES_SAVE_BIN_ALT_HH
+#endif // ! APPS_MESH_SEGM_SKEL_SAVE_BIN_ALT_HH
diff --git a/milena/apps/mesh-segm-skel/trimesh/misc.hh b/milena/apps/mesh-segm-skel/trimesh/misc.hh
index 1ef56cb..5084632 100644
--- a/milena/apps/mesh-segm-skel/trimesh/misc.hh
+++ b/milena/apps/mesh-segm-skel/trimesh/misc.hh
@@ -29,8 +29,8 @@
// FIXME: Split this file.
// FIXME: Address license-related issues?
-#ifndef MILENA_APPS_STATUES_MISC_HH
-# define MILENA_APPS_STATUES_MISC_HH
+#ifndef MILENA_APPS_MESH_SEGM_SKEL_MISC_HH
+# define MILENA_APPS_MESH_SEGM_SKEL_MISC_HH
# include <algorithm> // For std::swap.
# include <utility> // For std::pair.
@@ -659,4 +659,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MILENA_APPS_STATUES_MISC_HH
+#endif // ! MILENA_APPS_MESH_SEGM_SKEL_MISC_HH
diff --git a/milena/mesh/Makefile.am b/milena/mesh/Makefile.am
index e023f4d..558d28f 100644
--- a/milena/mesh/Makefile.am
+++ b/milena/mesh/Makefile.am
@@ -52,9 +52,9 @@ dist_mesh_DATA += $(more_meshes)
## Pseudo-inverse curvature of meshes. ##
## ------------------------------------ ##
-mesh_pinv_curv = $(top_builddir)/milena/apps/statues/mesh-pinv-curv
-mesh_pinv_curv: $(top_srcdir)/milena/apps/statues/mesh-pinv-curv.cc
- cd $(top_builddir)/milena/apps/statues/mesh-pinv-curv && \
+mesh_pinv_curv = $(top_builddir)/milena/apps/mesh-segm-skel/mesh-pinv-curv
+mesh_pinv_curv: $(top_srcdir)/milena/apps/mesh-segm-skel/mesh-pinv-curv.cc
+ cd $(top_builddir)/milena/apps/mesh-segm-skel/mesh-pinv-curv && \
$(MAKE) $(AM_MAKEFLAGS) mesh_pinv_curv
# FIXME: *-pinv-curv.off files should not be regenerated
@@ -70,9 +70,9 @@ dist_mesh_DATA += $(pinv_curv)
## Maximum curvature of meshes. ##
## ----------------------------- ##
-mesh_max_curv = $(top_builddir)/milena/apps/statues/mesh-max-curv
-mesh_max_curv: $(top_srcdir)/milena/apps/statues/mesh-max-curv.cc
- cd $(top_builddir)/milena/apps/statues/mesh-max-curv && \
+mesh_max_curv = $(top_builddir)/milena/apps/mesh-segm-skel/mesh-max-curv
+mesh_max_curv: $(top_srcdir)/milena/apps/mesh-segm-skel/mesh-max-curv.cc
+ cd $(top_builddir)/milena/apps/mesh-segm-skel/mesh-max-curv && \
$(MAKE) $(AM_MAKEFLAGS) mesh_max_curv
# FIXME: *-max-curv.off files should not be regenerated
--
1.6.4.2
1
0
* apps/statues/: Rename directory as...
* apps/mesh-segm-skel/: ...this.
---
milena/ChangeLog | 7 +++++++
.../apps/{statues => mesh-segm-skel}/Makefile.am | 0
milena/apps/{statues => mesh-segm-skel}/io.hh | 0
.../mesh-complex-max-curv-segm.cc | 0
.../mesh-complex-max-curv.cc | 0
.../mesh-complex-segm.cc | 0
.../mesh-complex-skel.cc | 0
.../{statues => mesh-segm-skel}/mesh-max-curv.cc | 0
.../{statues => mesh-segm-skel}/mesh-pinv-curv.cc | 0
.../apps/{statues => mesh-segm-skel}/mesh-segm.cc | 0
.../apps/{statues => mesh-segm-skel}/mesh-skel.cc | 0
.../{statues => mesh-segm-skel}/save_bin_alt.hh | 0
.../test-mesh-complex-max-curv-segm.in | 0
.../test-mesh-complex-max-curv.in | 0
.../test-mesh-complex-segm.in | 0
.../test-mesh-complex-skel.in | 0
.../test-mesh-max-curv.in | 0
.../{statues => mesh-segm-skel}/test-mesh-segm.in | 0
.../{statues => mesh-segm-skel}/trimesh/README | 0
.../{statues => mesh-segm-skel}/trimesh/misc.hh | 0
20 files changed, 7 insertions(+), 0 deletions(-)
rename milena/apps/{statues => mesh-segm-skel}/Makefile.am (100%)
rename milena/apps/{statues => mesh-segm-skel}/io.hh (100%)
rename milena/apps/{statues => mesh-segm-skel}/mesh-complex-max-curv-segm.cc (100%)
rename milena/apps/{statues => mesh-segm-skel}/mesh-complex-max-curv.cc (100%)
rename milena/apps/{statues => mesh-segm-skel}/mesh-complex-segm.cc (100%)
rename milena/apps/{statues => mesh-segm-skel}/mesh-complex-skel.cc (100%)
rename milena/apps/{statues => mesh-segm-skel}/mesh-max-curv.cc (100%)
rename milena/apps/{statues => mesh-segm-skel}/mesh-pinv-curv.cc (100%)
rename milena/apps/{statues => mesh-segm-skel}/mesh-segm.cc (100%)
rename milena/apps/{statues => mesh-segm-skel}/mesh-skel.cc (100%)
rename milena/apps/{statues => mesh-segm-skel}/save_bin_alt.hh (100%)
rename milena/apps/{statues => mesh-segm-skel}/test-mesh-complex-max-curv-segm.in (100%)
rename milena/apps/{statues => mesh-segm-skel}/test-mesh-complex-max-curv.in (100%)
rename milena/apps/{statues => mesh-segm-skel}/test-mesh-complex-segm.in (100%)
rename milena/apps/{statues => mesh-segm-skel}/test-mesh-complex-skel.in (100%)
rename milena/apps/{statues => mesh-segm-skel}/test-mesh-max-curv.in (100%)
rename milena/apps/{statues => mesh-segm-skel}/test-mesh-segm.in (100%)
rename milena/apps/{statues => mesh-segm-skel}/trimesh/README (100%)
rename milena/apps/{statues => mesh-segm-skel}/trimesh/misc.hh (100%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 654dd5c..dc2e0a1 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,10 @@
+2009-09-04 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Rename apps/statues/ as apps/mesh-segm-skel/.
+
+ * apps/statues/: Rename directory as...
+ * apps/mesh-segm-skel/: ...this.
+
2009-09-03 Roland Levillain <roland(a)lrde.epita.fr>
* mln/debug/println.spe.hh: Reindent.
diff --git a/milena/apps/statues/Makefile.am b/milena/apps/mesh-segm-skel/Makefile.am
similarity index 100%
rename from milena/apps/statues/Makefile.am
rename to milena/apps/mesh-segm-skel/Makefile.am
diff --git a/milena/apps/statues/io.hh b/milena/apps/mesh-segm-skel/io.hh
similarity index 100%
rename from milena/apps/statues/io.hh
rename to milena/apps/mesh-segm-skel/io.hh
diff --git a/milena/apps/statues/mesh-complex-max-curv-segm.cc b/milena/apps/mesh-segm-skel/mesh-complex-max-curv-segm.cc
similarity index 100%
rename from milena/apps/statues/mesh-complex-max-curv-segm.cc
rename to milena/apps/mesh-segm-skel/mesh-complex-max-curv-segm.cc
diff --git a/milena/apps/statues/mesh-complex-max-curv.cc b/milena/apps/mesh-segm-skel/mesh-complex-max-curv.cc
similarity index 100%
rename from milena/apps/statues/mesh-complex-max-curv.cc
rename to milena/apps/mesh-segm-skel/mesh-complex-max-curv.cc
diff --git a/milena/apps/statues/mesh-complex-segm.cc b/milena/apps/mesh-segm-skel/mesh-complex-segm.cc
similarity index 100%
rename from milena/apps/statues/mesh-complex-segm.cc
rename to milena/apps/mesh-segm-skel/mesh-complex-segm.cc
diff --git a/milena/apps/statues/mesh-complex-skel.cc b/milena/apps/mesh-segm-skel/mesh-complex-skel.cc
similarity index 100%
rename from milena/apps/statues/mesh-complex-skel.cc
rename to milena/apps/mesh-segm-skel/mesh-complex-skel.cc
diff --git a/milena/apps/statues/mesh-max-curv.cc b/milena/apps/mesh-segm-skel/mesh-max-curv.cc
similarity index 100%
rename from milena/apps/statues/mesh-max-curv.cc
rename to milena/apps/mesh-segm-skel/mesh-max-curv.cc
diff --git a/milena/apps/statues/mesh-pinv-curv.cc b/milena/apps/mesh-segm-skel/mesh-pinv-curv.cc
similarity index 100%
rename from milena/apps/statues/mesh-pinv-curv.cc
rename to milena/apps/mesh-segm-skel/mesh-pinv-curv.cc
diff --git a/milena/apps/statues/mesh-segm.cc b/milena/apps/mesh-segm-skel/mesh-segm.cc
similarity index 100%
rename from milena/apps/statues/mesh-segm.cc
rename to milena/apps/mesh-segm-skel/mesh-segm.cc
diff --git a/milena/apps/statues/mesh-skel.cc b/milena/apps/mesh-segm-skel/mesh-skel.cc
similarity index 100%
rename from milena/apps/statues/mesh-skel.cc
rename to milena/apps/mesh-segm-skel/mesh-skel.cc
diff --git a/milena/apps/statues/save_bin_alt.hh b/milena/apps/mesh-segm-skel/save_bin_alt.hh
similarity index 100%
rename from milena/apps/statues/save_bin_alt.hh
rename to milena/apps/mesh-segm-skel/save_bin_alt.hh
diff --git a/milena/apps/statues/test-mesh-complex-max-curv-segm.in b/milena/apps/mesh-segm-skel/test-mesh-complex-max-curv-segm.in
similarity index 100%
rename from milena/apps/statues/test-mesh-complex-max-curv-segm.in
rename to milena/apps/mesh-segm-skel/test-mesh-complex-max-curv-segm.in
diff --git a/milena/apps/statues/test-mesh-complex-max-curv.in b/milena/apps/mesh-segm-skel/test-mesh-complex-max-curv.in
similarity index 100%
rename from milena/apps/statues/test-mesh-complex-max-curv.in
rename to milena/apps/mesh-segm-skel/test-mesh-complex-max-curv.in
diff --git a/milena/apps/statues/test-mesh-complex-segm.in b/milena/apps/mesh-segm-skel/test-mesh-complex-segm.in
similarity index 100%
rename from milena/apps/statues/test-mesh-complex-segm.in
rename to milena/apps/mesh-segm-skel/test-mesh-complex-segm.in
diff --git a/milena/apps/statues/test-mesh-complex-skel.in b/milena/apps/mesh-segm-skel/test-mesh-complex-skel.in
similarity index 100%
rename from milena/apps/statues/test-mesh-complex-skel.in
rename to milena/apps/mesh-segm-skel/test-mesh-complex-skel.in
diff --git a/milena/apps/statues/test-mesh-max-curv.in b/milena/apps/mesh-segm-skel/test-mesh-max-curv.in
similarity index 100%
rename from milena/apps/statues/test-mesh-max-curv.in
rename to milena/apps/mesh-segm-skel/test-mesh-max-curv.in
diff --git a/milena/apps/statues/test-mesh-segm.in b/milena/apps/mesh-segm-skel/test-mesh-segm.in
similarity index 100%
rename from milena/apps/statues/test-mesh-segm.in
rename to milena/apps/mesh-segm-skel/test-mesh-segm.in
diff --git a/milena/apps/statues/trimesh/README b/milena/apps/mesh-segm-skel/trimesh/README
similarity index 100%
rename from milena/apps/statues/trimesh/README
rename to milena/apps/mesh-segm-skel/trimesh/README
diff --git a/milena/apps/statues/trimesh/misc.hh b/milena/apps/mesh-segm-skel/trimesh/misc.hh
similarity index 100%
rename from milena/apps/statues/trimesh/misc.hh
rename to milena/apps/mesh-segm-skel/trimesh/misc.hh
--
1.6.4.2
1
0
* green/mln/accu/stat/histo1d/histo1d.hh : Improve documentation.
* green/tests/accu/stat/histo1d/histo1d.cc
(test_14bits_classifying) : Test gausian filtering.
* green/mln/io/plot/save_histo_sh.hh : Test new gnuplot style.
---
trunk/milena/sandbox/ChangeLog | 10 ++++++++++
.../milena/sandbox/green/mln/accu/stat/histo1d.hh | 15 ++++++++-------
.../sandbox/green/mln/io/plot/save_histo_sh.hh | 3 ++-
.../green/tests/accu/stat/histo1d/histo1d.cc | 13 +++++++------
4 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog
index b29bcef..584044a 100644
--- a/trunk/milena/sandbox/ChangeLog
+++ b/trunk/milena/sandbox/ChangeLog
@@ -1,5 +1,15 @@
2009-09-07 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+ Make some test on 14 bits grayscale image.
+
+ * green/mln/accu/stat/histo1d/histo1d.hh : Improve documentation.
+ * green/tests/accu/stat/histo1d/histo1d.cc
+ (test_14bits_classifying) : Test gausian filtering.
+ * green/mln/io/plot/save_histo_sh.hh : Test new gnuplot style.
+
+
+2009-09-07 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
Improve histo1d testing with 14 bits grayscale image.
* green/mln/fun : New directory.
diff --git a/trunk/milena/sandbox/green/mln/accu/stat/histo1d.hh b/trunk/milena/sandbox/green/mln/accu/stat/histo1d.hh
index 4cd07fa..541b749 100644
--- a/trunk/milena/sandbox/green/mln/accu/stat/histo1d.hh
+++ b/trunk/milena/sandbox/green/mln/accu/stat/histo1d.hh
@@ -34,7 +34,7 @@
///
/// This source implements the discrete histogram version. The number of beans
/// is infer from the number of greylevels. A typical int_u8 image has got
-/// 256 bins. An int_u16 image has got 65535 bins.
+/// 256 bins. An int_u<14> image has got 16384 bins.
/// The following sample is a typical use of the histogram.
///
/// #include <mln/value/int_u8.hh>
@@ -124,10 +124,10 @@ namespace mln
///
/// Param V defines the space in which we count the values.
/// For instance, this histogram works image2d<int_u8> or
- /// image1d<int_u16>. The histogram count the occurrence of each value.
+ /// image1d<int_u<14> >. The histogram count the occurrence of each value.
/// The number of bins depends of the greyscale values, for 8 bits there
- /// is 256 bins, for 16 bits there is 65536 bins. Note that over
- /// quantification works too.
+ /// is 256 bins, for 14 bits there is 16384 bins. Note that over
+ /// quantification works too (up to 14 bits).
///
/// \ingroup modaccuvalues
@@ -159,7 +159,7 @@ namespace mln
void init();
- /// \brief Update the histogram with the RGB pixel t.
+ /// \brief Update the histogram with the greylevel of the pixel t.
/// \param[in] t a greylevel pixel of type V.
///
/// The end user shouldn't call this method. In place of it, he can
@@ -216,6 +216,9 @@ namespace mln
// mln_min(comp) --> 0
// mln_max(comp) --> 2^(n-1) [127 for n=7][255 for n=8] ...
+ count_.init_(box1d(point1d(mln_min(comp)),
+ point1d(mln_max(comp))));
+
// std::cout << "min : " << mln_min(comp) << std::endl;
// std::cout << "max : " << mln_max(comp) << std::endl;
@@ -226,8 +229,6 @@ namespace mln
// v_point1d(mln_max(comp))));
// this does not work as image1d is friendly close to box1d
- count_.init_(box1d(point1d(mln_min(comp)),
- point1d(mln_max(comp))));
trace::exiting("mln::accu::stat::histo1d<V>::histo1d");
}
diff --git a/trunk/milena/sandbox/green/mln/io/plot/save_histo_sh.hh b/trunk/milena/sandbox/green/mln/io/plot/save_histo_sh.hh
index 6bf1fbf..e2d26e1 100644
--- a/trunk/milena/sandbox/green/mln/io/plot/save_histo_sh.hh
+++ b/trunk/milena/sandbox/green/mln/io/plot/save_histo_sh.hh
@@ -100,7 +100,8 @@ namespace mln
out << std::endl;
out << "gnuplot <<EOF" << std::endl;
out << "set terminal x11 persist 1" << std::endl;
- out << "plot '-' with points pointtype 20" << std::endl;
+ out << "plot '-' with impulses" << std::endl;
+ //out << "plot '-' with points pointtype 20" << std::endl;
//out << "plot '-' with points pointtype 0" << std::endl;
//out << "plot '-' with histograms" << std::endl;
//out << "plot '-' smooth unique" << std::endl;
diff --git a/trunk/milena/sandbox/green/tests/accu/stat/histo1d/histo1d.cc b/trunk/milena/sandbox/green/tests/accu/stat/histo1d/histo1d.cc
index b09fab8..e959cbd 100644
--- a/trunk/milena/sandbox/green/tests/accu/stat/histo1d/histo1d.cc
+++ b/trunk/milena/sandbox/green/tests/accu/stat/histo1d/histo1d.cc
@@ -631,8 +631,8 @@ void test_14bits_classifying()
std::cout << "(14 bits) SMOOTHING HISTOGRAM" << std::endl;
- double ws[41];
- gaussian_filter(ws, 41, 6.0);
+ double ws[401];
+ gaussian_filter(ws, 401, 50.0);
img_smooth = mln::linear::convolve(img_res, mln::make::w_window1d(ws));
mln::io::plot::save_histo_sh(img_smooth, "histo1_14bits.sh");
@@ -678,25 +678,26 @@ void test_14bits_classifying()
int main()
{
+ /*
test_8bits_instantiation_without_argument();
test_8bits_initialization();
test_8bits_take_argument();
test_8bits_take_other();
test_8bits_operator_equal();
test_8bits_integration();
-
- //test_8bits_classifying();
+ */
+ test_8bits_classifying();
// PROBLEME AVEC LES COORDONNEES PAR DEFAUT QUI SONT EN SIGNED SHORT
// SEE mln/core/def/coord.hh
-
+ /*
test_14bits_instantiation_without_argument();
test_14bits_initialization();
test_14bits_take_argument();
test_14bits_take_other();
test_14bits_operator_equal();
test_14bits_integration();
-
+ */
test_14bits_classifying();
return 0;
--
1.5.6.5
1
0
* green/mln/fun : New directory.
* green/mln/fun/v2v : New directory.
* green/mln/fun/v2v/int_u16_to_int_u14.hh : New subsampling function.
* green/tests/accu/stat/histo1d/histo1d.cc : Improve unitary tests.
---
trunk/milena/sandbox/ChangeLog | 9 +
.../green/mln/fun/v2v/int_u16_to_int_u14.hh | 71 ++++++++
.../green/tests/accu/stat/histo1d/histo1d.cc | 186 +++++++++++---------
3 files changed, 186 insertions(+), 80 deletions(-)
create mode 100644 trunk/milena/sandbox/green/mln/fun/v2v/int_u16_to_int_u14.hh
diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog
index 40d2bfd..b29bcef 100644
--- a/trunk/milena/sandbox/ChangeLog
+++ b/trunk/milena/sandbox/ChangeLog
@@ -1,5 +1,14 @@
2009-09-07 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+ Improve histo1d testing with 14 bits grayscale image.
+
+ * green/mln/fun : New directory.
+ * green/mln/fun/v2v : New directory.
+ * green/mln/fun/v2v/int_u16_to_int_u14.hh : New subsampling function.
+ * green/tests/accu/stat/histo1d/histo1d.cc : Improve unitary tests.
+
+2009-09-07 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
Delete old k_mean source location.
* green/k_mean/Makefile.am : Remove old makefile.
diff --git a/trunk/milena/sandbox/green/mln/fun/v2v/int_u16_to_int_u14.hh b/trunk/milena/sandbox/green/mln/fun/v2v/int_u16_to_int_u14.hh
new file mode 100644
index 0000000..e7f4755
--- /dev/null
+++ b/trunk/milena/sandbox/green/mln/fun/v2v/int_u16_to_int_u14.hh
@@ -0,0 +1,71 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 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_FUN_V2V_INT_U16_TO_INT_U14_HH
+#define MLN_FUN_V2V_INT_U16_TO_INT_U14_HH
+
+#include <mln/value/int_u16.hh>
+#include <mln/value/int_u.hh>
+
+/// \file
+///
+/// \brief Convert int_u16 value to int_u14.
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace v2v
+ {
+
+ /// \brief Convert int_u16 value to int_u14.
+ ///
+ /// \ingroup modfunv2v
+
+ struct int_u16_to_int_u14 : Function_v2v< int_u16_to_int_u14 >
+ {
+ typedef value::int_u16 argument;
+ typedef value::int_u<14> result;
+
+ result operator()(const argument& c) const
+ {
+ result res(c / 4);
+
+ return res;
+ }
+ };
+
+ }
+
+ }
+
+}
+
+
+#endif // ! MLN_FUN_V2V_INT_U16_TO_INT_U14_HH
diff --git a/trunk/milena/sandbox/green/tests/accu/stat/histo1d/histo1d.cc b/trunk/milena/sandbox/green/tests/accu/stat/histo1d/histo1d.cc
index 020c125..b09fab8 100644
--- a/trunk/milena/sandbox/green/tests/accu/stat/histo1d/histo1d.cc
+++ b/trunk/milena/sandbox/green/tests/accu/stat/histo1d/histo1d.cc
@@ -4,6 +4,7 @@
#include <mln/io/plot/save_histo_sh.hh>
#include <mln/accu/stat/histo1d.hh>
+#include <mln/fun/v2v/int_u16_to_int_u14.hh>
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
@@ -11,10 +12,12 @@
#include <mln/io/plot/save.hh>
#include <mln/data/compute.hh>
+#include <mln/data/transform.hh>
#include <mln/data/fill.hh>
#include <mln/value/int_u8.hh>
#include <mln/value/int_u16.hh>
+#include <mln/value/int_u.hh>
#include <mln/value/label_8.hh>
#include <mln/value/rgb8.hh>
@@ -220,6 +223,25 @@ double var_histo(mln::image1d<unsigned> img)
return result;
}
+double var_histo2(mln::image1d<unsigned> img)
+{
+ mln_precondition(img.is_valid());
+
+ double count = count_histo(img);
+ double mean = mean_histo(img);
+ double result = 0.0;
+ mln_piter_(mln::image1d<unsigned>) p(img.domain());
+
+ for_all(p)
+ {
+ result += img(p) * (p[0] - mean) * (p[0] - mean);
+ }
+
+ result /= count;
+
+ return result;
+}
+
void test_8bits_integration()
{
typedef mln::value::int_u8 int_u8;
@@ -393,17 +415,17 @@ void test_8bits_classifying()
}
//------------------------------------------------------------------------------
-// TEST IN 16 BITS
+// TEST IN 15 BITS
//------------------------------------------------------------------------------
-void test_16bits_operator_equal()
+void test_14bits_operator_equal()
{
using namespace mln::accu::stat;
- typedef mln::value::int_u16 int_u16;
- mln::accu::stat::histo1d<int_u16> histo1;
- mln::accu::stat::histo1d<int_u16> histo2;
- int_u16 val = 3;
+ typedef mln::value::int_u<14> int_u14;
+ mln::accu::stat::histo1d<int_u14> histo1;
+ mln::accu::stat::histo1d<int_u14> histo2;
+ int_u14 val = 3;
histo1.init();
histo2.init();
@@ -419,33 +441,29 @@ void test_16bits_operator_equal()
mln_assertion(histo1 == histo2);
- std::cout << "(16 bits) histo == histo : ok" << std::endl;
+ std::cout << "(14 bits) histo == histo : ok" << std::endl;
}
-void test_16bits_instantiation_without_argument()
+void test_14bits_instantiation_without_argument()
{
- mln::trace::quiet = false;
-
- typedef mln::value::int_u16 int_u16;
- typedef mln::point<mln::grid::tick, int_u16> point1d;
- typedef mln::box<point1d> box1d;
- const mln::accu::stat::histo1d<int_u16> histo;
- const mln::image1d<unsigned>& res = histo.to_result();
- const point1d& min = point1d(mln_min(int_u16));
- const point1d& max = point1d(mln_max(int_u16));
- const box1d& ref = box1d(min, max);
+ typedef mln::value::int_u<14> int_u14;
+ const mln::accu::stat::histo1d<int_u14> histo;
+ const mln::image1d<unsigned>& res = histo.to_result();
+ const mln::point1d& min =mln::point1d(mln_min(int_u14));
+ const mln::point1d& max =mln::point1d(mln_max(int_u14));
+ const mln::box1d& ref = mln::box1d(min, max);
mln_assertion(ref == res.domain());
mln_assertion(res.is_valid());
- std::cout << "(16 bits) histo<T> histo : ok" << std::endl;
+ std::cout << "(14 bits) histo<T> histo : ok" << std::endl;
}
-void test_16bits_initialization()
+void test_14bits_initialization()
{
- typedef mln::value::int_u16 int_u16;
- mln::accu::stat::histo1d<int_u16> histo;
+ typedef mln::value::int_u<14> int_u14;
+ mln::accu::stat::histo1d<int_u14> histo;
mln::image1d<unsigned> img_res = histo.to_result();
mln::image1d<unsigned> img_ref;
@@ -453,21 +471,21 @@ void test_16bits_initialization()
mln::data::fill(img_ref, 0);
histo.init();
- unsigned res = mln::data::compute(mln::accu::math::sum<int_u16>(), img_res);
- unsigned ref = mln::data::compute(mln::accu::math::sum<int_u16>(), img_ref);
+ unsigned res = mln::data::compute(mln::accu::math::sum<int_u14>(), img_res);
+ unsigned ref = mln::data::compute(mln::accu::math::sum<int_u14>(), img_ref);
mln_assertion(ref == res);
- std::cout << "(16 bits) histo.init() : ok" << std::endl;
+ std::cout << "(14 bits) histo.init() : ok" << std::endl;
}
-void test_16bits_take_argument()
+void test_14bits_take_argument()
{
- typedef mln::value::int_u16 int_u16;
- mln::accu::stat::histo1d<int_u16> histo1;
- mln::accu::stat::histo1d<int_u16> histo2;
- int_u16 val = 3;
+ typedef mln::value::int_u<14> int_u14;
+ mln::accu::stat::histo1d<int_u14> histo1;
+ mln::accu::stat::histo1d<int_u14> histo2;
+ int_u14 val = 3;
histo1.init();
histo2.init();
@@ -476,23 +494,23 @@ void test_16bits_take_argument()
const mln::image1d<unsigned> img1 = histo1.to_result();
const mln::image1d<unsigned> img2 = histo2.to_result();
- const unsigned res = mln::data::compute(mln::accu::math::sum<int_u16>(),img1);
- const unsigned ref = mln::data::compute(mln::accu::math::sum<int_u16>(),img2);
+ const unsigned res = mln::data::compute(mln::accu::math::sum<int_u14>(),img1);
+ const unsigned ref = mln::data::compute(mln::accu::math::sum<int_u14>(),img2);
mln_assertion(ref == res-1);
mln_assertion(1 == img1(mln::point1d(val)));
- std::cout << "(16 bits) histo.take(argument) : ok" << std::endl;
+ std::cout << "(14 bits) histo.take(argument) : ok" << std::endl;
}
-void test_16bits_take_other()
+void test_14bits_take_other()
{
- typedef mln::value::int_u16 int_u16;
- mln::accu::stat::histo1d<int_u16> histo1;
- mln::accu::stat::histo1d<int_u16> histo2;
- mln::accu::stat::histo1d<int_u16> histo3;
- int_u16 val = 3;
+ typedef mln::value::int_u<14> int_u14;
+ mln::accu::stat::histo1d<int_u14> histo1;
+ mln::accu::stat::histo1d<int_u14> histo2;
+ mln::accu::stat::histo1d<int_u14> histo3;
+ int_u14 val = 3;
histo1.init();
histo2.init();
@@ -506,37 +524,43 @@ void test_16bits_take_other()
mln_assertion(histo1 == histo2);
- std::cout << "(16 bits) histo.take(other) : ok" << std::endl;
+ std::cout << "(14 bits) histo.take(other) : ok" << std::endl;
}
-void test_16bits_integration()
+void test_14bits_integration()
{
typedef mln::value::int_u16 int_u16;
+ typedef mln::value::int_u<14> int_u14;
typedef mln::accu::math::count<double> count;
typedef mln::accu::math::sum<double> sum;
typedef mln::accu::stat::mean<double> mean;
typedef mln::accu::stat::variance<double> variance;
- mln::image2d<int_u16> img_ref;
+ mln::image2d<int_u16> img_fst;
+ mln::image2d<int_u14> img_ref;
mln::image1d<unsigned> img_res;
- mln::io::pgm::load(img_ref, OLENA_IMG_PATH"/lena_16.pgm");
+ mln::io::pgm::load(img_fst, OLENA_IMG_PATH"/lena_16.pgm");
+ img_ref = mln::data::transform(img_fst, mln::fun::v2v::int_u16_to_int_u14());
const double count_ref = mln::data::compute(count(), img_ref);
const double mean_ref = mln::data::compute(mean(), img_ref);
const double var_ref = mln::data::compute(variance(), img_ref);
- img_res = mln::data::compute(mln::accu::stat::histo1d<int_u16>(), img_ref);
+ img_res = mln::data::compute(mln::accu::stat::histo1d<int_u14>(), img_ref);
const double count_res = count_histo(img_res);
const double mean_res = mean_histo(img_res);
- const double var_res = var_histo(img_res);
+ const double var_res = var_histo2(img_res);
+
+ //std::cout << "var_res : " << var_res << std::endl;
+ //std::cout << "var_ref : " << var_ref << std::endl;
mln_assertion(count_ref == count_res);
mln_assertion( mean_ref == mean_res );
mln_assertion(0.0001 > abs(var_ref - var_res));
- std::cout << "(16 bits) test integration : ok" << std::endl;
+ std::cout << "(14 bits) test integration : ok" << std::endl;
}
/// The aim of this function is to rebuild an label image2d from the segmenting
@@ -544,10 +568,10 @@ void test_16bits_integration()
/// label_image2d / for each grey tone, associate its label.
mln::image2d<mln::value::label_8>
-build_16bits(const mln::image2d<mln::value::int_u16>& input,
- const mln::image1d<mln::value::label_8>& label)
+build_14bits(const mln::image2d<mln::value::int_u<14> >& input,
+ const mln::image1d<mln::value::label_8>& label)
{
- mln::trace::entering("build_16bits");
+ mln::trace::entering("build_14bits");
mln_precondition(label.is_valid());
mln_precondition(input.is_valid());
@@ -555,31 +579,33 @@ build_16bits(const mln::image2d<mln::value::int_u16>& input,
mln::initialize(output, input);
- mln_piter_(mln::image2d<mln::value::int_u16>) pi(input.domain());
+ mln_piter_(mln::image2d<mln::value::int_u<14> >) pi(input.domain());
mln_piter_(mln::image2d<mln::value::label_8>) po(output.domain());
for_all_2(pi, po)
{
- mln::value::int_u16 val = input(pi);
- unsigned grp = label(mln::point1d(val));
+ mln::value::int_u<14> val = input(pi);
+ unsigned grp = label(mln::point1d(val));
output(po) = grp;
}
- mln::trace::exiting("build_16bits");
+ mln::trace::exiting("build_14bits");
return output;
}
-void test_16bits_classifying()
+void test_14bits_classifying()
{
typedef mln::value::int_u16 int_u16;
+ typedef mln::value::int_u<14> int_u14;
typedef mln::value::label_8 label_8;
typedef mln::value::rgb8 rgb8;
typedef mln::accu::stat::mean<double> mean;
- mln::image2d<int_u16> img_ref;
- mln::image2d<int_u16> img_out;
+ mln::image2d<int_u16> img_fst;
+ mln::image2d<int_u14> img_ref;
+ mln::image2d<int_u14> img_out;
mln::image2d<rgb8> img_rgb;
mln::image1d<unsigned> img_res;
mln::image1d<double> img_smooth;
@@ -590,31 +616,32 @@ void test_16bits_classifying()
// Loading the scribo image and computing its histogram
//-----------------------------------------------------
- std::cout << "(16 bits) LOADING HISTOGRAM" << std::endl;
+ std::cout << "(14 bits) LOADING HISTOGRAM" << std::endl;
- // mln::io::pgm::load(img_ref, OLENA_IMG_PATH"/lena.pgm");
- mln::io::pgm::load(img_ref, SCRIBO_IMG_PATH"/mp00082c_50p_16bits.pgm");
- img_res = mln::data::compute(mln::accu::stat::histo1d<int_u16>(), img_ref);
- mln::io::plot::save_histo_sh(img_res, "histo0_16bits.sh");
+ //mln::io::pgm::load(img_fst, OLENA_IMG_PATH"/lena_16.pgm");
+ mln::io::pgm::load(img_fst, SCRIBO_IMG_PATH"/mp00082c_50p_16bits.pgm");
+ img_ref = mln::data::transform(img_fst, mln::fun::v2v::int_u16_to_int_u14());
+ img_res = mln::data::compute(mln::accu::stat::histo1d<int_u14>(), img_ref);
+ mln::io::plot::save_histo_sh(img_res, "histo0_14bits.sh");
//-----------------------------------------------------
// Smoothing the histogram with a gaussian filter
//-----------------------------------------------------
- std::cout << "(16 bits) SMOOTHING HISTOGRAM" << std::endl;
+ std::cout << "(14 bits) SMOOTHING HISTOGRAM" << std::endl;
double ws[41];
gaussian_filter(ws, 41, 6.0);
img_smooth = mln::linear::convolve(img_res, mln::make::w_window1d(ws));
- mln::io::plot::save_histo_sh(img_smooth, "histo1_16bits.sh");
+ mln::io::plot::save_histo_sh(img_smooth, "histo1_14bits.sh");
//-----------------------------------------------------
// Segmenting the histogram with the watershed method
//-----------------------------------------------------
- std::cout << "(16 bits) SEGMENTING HISTOGRAM" << std::endl;
+ std::cout << "(14 bits) SEGMENTING HISTOGRAM" << std::endl;
/*
labels = mln::labeling::regional_maxima(img_smooth, mln::c2(), nlabels);
@@ -625,24 +652,24 @@ void test_16bits_classifying()
labels = mln::morpho::watershed::flooding(img_smooth, mln::c2(), nlabels);
std::cout << "N labels : " << nlabels << std::endl;
- mln::io::plot::save_histo_sh(labels, "histo2_16bits.sh");
+ mln::io::plot::save_histo_sh(labels, "histo2_14bits.sh");
//-----------------------------------------------------
// Rebuilding the image with the mean of each region
//-----------------------------------------------------
- std::cout << "(16 bits) BUILDING OUTPUT" << std::endl;
+ std::cout << "(14 bits) BUILDING OUTPUT" << std::endl;
- mln::image2d<label_8>img_label = build_16bits(img_ref, labels);
+ mln::image2d<label_8>img_label = build_14bits(img_ref, labels);
- std::cout << "(16 bits) COLORING OUTPUT" << std::endl;
+ std::cout << "(14 bits) COLORING OUTPUT" << std::endl;
img_out = mln::labeling::mean_values(img_ref, img_label, nlabels);
img_rgb = mln::labeling::colorize(rgb8(), img_label);
- mln::io::pgm::save(img_out, "out_16bits.pgm");
- mln::io::ppm::save(img_rgb, "color_16bits.pgm");
+ mln::io::pgm::save(img_out, "out_14bits.pgm");
+ mln::io::ppm::save(img_rgb, "color_14bits.pgm");
//labels = mln::morpho::elementary::dilation(labels, mln::c2());
//mln::io::plot::save_histo_sh(labels, "histo3.sh");
@@ -663,15 +690,14 @@ int main()
// PROBLEME AVEC LES COORDONNEES PAR DEFAUT QUI SONT EN SIGNED SHORT
// SEE mln/core/def/coord.hh
- /*
- test_16bits_instantiation_without_argument();
- test_16bits_initialization();
- test_16bits_take_argument();
- test_16bits_take_other();
- test_16bits_operator_equal();
- test_16bits_integration();
-
- //test_16bits_classifying();
- */
+ test_14bits_instantiation_without_argument();
+ test_14bits_initialization();
+ test_14bits_take_argument();
+ test_14bits_take_other();
+ test_14bits_operator_equal();
+ test_14bits_integration();
+
+ test_14bits_classifying();
+
return 0;
}
--
1.5.6.5
1
0
---
trunk/milena/sandbox/ChangeLog | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog
index 2a8148f..40d2bfd 100644
--- a/trunk/milena/sandbox/ChangeLog
+++ b/trunk/milena/sandbox/ChangeLog
@@ -3,7 +3,7 @@
Delete old k_mean source location.
* green/k_mean/Makefile.am : Remove old makefile.
- * green/k_mean/k_mean.hh : Remove old library code.
+ * green/k_mean/k_mean.hh : Remove old library code.
* green/k_mean/k_mean.cc : Remove old unitary tests.
* green/k_mean : Remove old directory.
@@ -13,7 +13,7 @@
* green/histo1d/Makefile.am : Remove old makefile.
* green/histo1d/gaussian.sh : Remove old tools.
- * green/histo1d/histo1d.hh : Remove old library code.
+ * green/histo1d/histo1d.hh : Remove old library code.
* green/histo1d/histo1d.cc : Remove old unitary tests.
* green/histo1d/mp00082c_50p.pgm : Remove old image.
* green/histo1d/save_sh.hh : Remove old library code.
@@ -25,7 +25,7 @@
* green/mln : New dev directory.
* green/mln/accu : New directory.
- * green/mln/accu/stat : New directory.
+ * green/mln/accu/stat : New directory.
* green/mln/accu/stat/histo1d.hh : New histo1d location.
* green/mln/img_path.hh : New image path defines.
* green/mln/io : New directory.
@@ -35,7 +35,7 @@
* green/tests/accu : New directory.
* green/tests/accu/stat : New directory.
* green/tests/accu/stat/histo1d : New histo1d test directory.
- * green/tests/accu/stat/histo1d/Makefile.am: New makefle.
+ * green/tests/accu/stat/histo1d/Makefile.am: New makefle.
* green/tests/accu/stat/histo1d/histo1d.cc : New unit tests location.
* green/tests/accu/stat/histo1d/gaussian.sh: New tools to test filter.
@@ -50,7 +50,7 @@
* green/tests : New unitary test directory.
* green/tests/clustering : New directory.
* green/tests/clustering/k_mean : New k_mean test directory.
- * green/tests/clustering/k_mean/Makefile.am: New makefle.
+ * green/tests/clustering/k_mean/Makefile.am: New makefle.
* green/tests/clustering/k_mean/k_mean.cc : New unit tests location.
2009-09-07 Fabien Freling <fabien.freling(a)lrde.epita.fr>
--
1.5.6.5
1
0
* green/k_mean/Makefile.am : Remove old makefile.
* green/k_mean/k_mean.hh : Remove old library code.
* green/k_mean/k_mean.cc : Remove old unitary tests.
* green/k_mean : Remove old directory.
---
trunk/milena/sandbox/ChangeLog | 9 +
trunk/milena/sandbox/green/k_mean/Makefile.am | 50 --
trunk/milena/sandbox/green/k_mean/k_mean.cc | 450 -----------------
trunk/milena/sandbox/green/k_mean/k_mean.hh | 672 -------------------------
4 files changed, 9 insertions(+), 1172 deletions(-)
delete mode 100644 trunk/milena/sandbox/green/k_mean/Makefile.am
delete mode 100644 trunk/milena/sandbox/green/k_mean/k_mean.cc
delete mode 100644 trunk/milena/sandbox/green/k_mean/k_mean.hh
diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog
index 4555e7f..2a8148f 100644
--- a/trunk/milena/sandbox/ChangeLog
+++ b/trunk/milena/sandbox/ChangeLog
@@ -1,5 +1,14 @@
2009-09-07 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+ Delete old k_mean source location.
+
+ * green/k_mean/Makefile.am : Remove old makefile.
+ * green/k_mean/k_mean.hh : Remove old library code.
+ * green/k_mean/k_mean.cc : Remove old unitary tests.
+ * green/k_mean : Remove old directory.
+
+2009-09-07 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
Delete old histo1d source location.
* green/histo1d/Makefile.am : Remove old makefile.
diff --git a/trunk/milena/sandbox/green/k_mean/Makefile.am b/trunk/milena/sandbox/green/k_mean/Makefile.am
deleted file mode 100644
index 1834984..0000000
--- a/trunk/milena/sandbox/green/k_mean/Makefile.am
+++ /dev/null
@@ -1,50 +0,0 @@
-#
-# Generic Makefile
-#
-
-BIN_PATTERN= trunk/build/milena
-SRC_PATTERN= trunk/milena
-
-INCLUDES= -I/home/green/svn/oln/trunk/milena
-CXXFLAGS= -ggdb -O0 -Wall -W -pedantic -ansi -pipe $(INCLUDES)
-ECHO= echo
-RM= rm
-MKDIR= mkdir
-CP= cp
-
-ifeq ($(findstring $(BIN_PATTERN),$(PWD)), $(BIN_PATTERN))
-BIN_DIR=
-SRC_DIR= $(subst $(BIN_PATTERN),$(SRC_PATTERN), $(PWD))/
-else
-BIN_DIR= $(subst $(SRC_PATTERN),$(BIN_PATTERN), $(PWD))/
-SRC_DIR=
-endif
-
-TARGET= $(BIN_DIR)$(notdir $(PWD))
-BIN_MAKE= $(BIN_DIR)Makefile
-SRC_MAKE= $(SRC_DIR)Makefile.am
-
-
-SRC_FILES= $(wildcard $(SRC_DIR)*.cc)
-OLD_FILES= $(addsuffix ~, $(SRC_FILES))
-OBJ_FILES= $(addprefix $(BIN_DIR), $(notdir $(SRC_FILES:%.cc=%.o)))
-
-
-all: $(BIN_DIR) $(TARGET)
- @$(ECHO) "Compilation terminée"
-
-$(BIN_DIR):
- $(MKDIR) $(BIN_DIR)
- $(CP) $(SRC_MAKE) $(BIN_MAKE)
-
-$(TARGET):$(OBJ_FILES)
- $(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@
-
-$(BIN_DIR)%.o:$(SRC_DIR)%.cc
- $(COMPILE.cc) $(OUTPUT_OPTION) $<
-
-clean:
- -@$(RM) $(TARGET)
- -@$(RM) $(OBJ_FILES)
- -@$(RM) $(OLD_FILES)
-
diff --git a/trunk/milena/sandbox/green/k_mean/k_mean.cc b/trunk/milena/sandbox/green/k_mean/k_mean.cc
deleted file mode 100644
index 985e0e0..0000000
--- a/trunk/milena/sandbox/green/k_mean/k_mean.cc
+++ /dev/null
@@ -1,450 +0,0 @@
-// UNARY TESTS ON K_MEAN
-
-#include "k_mean.hh"
-
-#include <iostream>
-
-#include <mln/pw/value.hh>
-
-#include <mln/value/int_u8.hh>
-#include <mln/value/rgb8.hh>
-
-#include <mln/literal/colors.hh>
-
-#include <mln/algebra/vec.hh>
-#include <mln/algebra/mat.hh>
-
-#include <mln/core/macros.hh>
-#include <mln/core/contract.hh>
-#include <mln/core/image/image2d.hh>
-#include <mln/core/image/dmorph/image_if.hh>
-
-#include <mln/io/ppm/load.hh>
-#include <mln/io/pgm/load.hh>
-#include <mln/io/pgm/save.hh>
-#include <mln/io/ppm/save.hh>
-
-#include <mln/data/transform.hh>
-
-#include <mln/trait/value/print.hh>
-#include <mln/trait/image/print.hh>
-
-#define SIZE_IMAGE 512
-#define SIZE_SAMPLE1 (512*512)
-#define SIZE_SAMPLE2 4
-#define NB_CENTER 2
-#define DIM_POINT 3
-#define TYPE_POINT double
-#define MAT_POINT1 mln::algebra::mat<SIZE_SAMPLE1, DIM_POINT, TYPE_POINT>
-#define MAT_POINT2 mln::algebra::mat<SIZE_SAMPLE2, DIM_POINT, TYPE_POINT>
-#define MAT_CENTER mln::algebra::mat<NB_CENTER, DIM_POINT, TYPE_POINT>
-#define MAT_DISTANCE1 mln::algebra::mat<SIZE_SAMPLE1, NB_CENTER, TYPE_POINT>
-#define MAT_DISTANCE2 mln::algebra::mat<SIZE_SAMPLE2, NB_CENTER, TYPE_POINT>
-#define MAT_GROUP1 mln::algebra::mat<SIZE_SAMPLE1, NB_CENTER, TYPE_POINT>
-#define MAT_GROUP2 mln::algebra::mat<SIZE_SAMPLE2, NB_CENTER, TYPE_POINT>
-#define VEC_VAR mln::algebra::vec<NB_CENTER, TYPE_POINT>
-
-
-void test_instantiation()
-{
- mln::clustering::k_mean<SIZE_SAMPLE2,NB_CENTER, DIM_POINT, TYPE_POINT> kmean;
-
- // test the compilation
-
- std::cout << "test instantiation : ok" << std::endl;
-}
-
-struct rgb8_to_4colors : mln::Function_v2v<rgb8_to_4colors>
-{
- typedef mln::value::rgb8 result;
-
- mln::value::rgb8 operator()(const mln::value::rgb8& color) const
- {
- mln::value::rgb8 result;
- unsigned hash = (color.red() + color.green() + color.blue()) % 4;
-
- switch (hash)
- {
- case 0: result = mln::literal::lime; break;
- case 1: result = mln::literal::brown; break;
- case 2: result = mln::literal::teal; break;
- case 3: result = mln::literal::purple; break;
- }
-
- return result;
- }
-};
-
-
-void print_color(const mln::value::rgb8& color)
-{
- std::cout << "{r=" << color.red() << ", ";
- std::cout << "g=" << color.green() << ", ";
- std::cout << "b=" << color.blue() << "}" << std::endl;
-}
-
-void fill_image_with_4colors(mln::image2d<mln::value::rgb8>& img)
-{
- const mln::value::rgb8 lime = mln::literal::lime;
- const mln::value::rgb8 brown = mln::literal::brown;
- const mln::value::rgb8 teal = mln::literal::teal;
- const mln::value::rgb8 purple = mln::literal::purple;
-
- img = mln::data::transform(img, rgb8_to_4colors());
-
- //print_color(lime);
- //print_color(brown);
- //print_color(teal);
- //print_color(purple);
-}
-
-bool is_equivalent(const mln::image2d<mln::value::rgb8>& img,
- const MAT_POINT1& point)
-{
- mln_piter_(mln::image2d<mln::value::rgb8>) pi(img.domain());
- bool result = true;
- unsigned index = -1;
-
- for_all(pi)
- {
- bool test = true;
-
- ++index;
-
- test = test && (point(index,0) == img(pi).red());
- test = test && (point(index,1) == img(pi).green());
- test = test && (point(index,2) == img(pi).blue());
-
- if (!test)
- {
- std::cout << pi;
- std::cout << "{r=" << img(pi).red() << ", ";
- std::cout << "g=" << img(pi).green() << ", ";
- std::cout << "b=" << img(pi).blue() << "}";
- std::cout << index;
- std::cout << "[r=" << point(index,0) << ", ";
- std::cout << "g=" << point(index,1) << ", ";
- std::cout << "b=" << point(index,2) << "]" << std::endl;
-
- mln_assertion(test);
- }
-
- result &= test;
- }
-
- return result;
-}
-
-void test_init_point()
-{
- typedef mln::value::rgb8 rgb8;
- mln::image2d<rgb8> img_ref;
-
- mln::clustering::k_mean<SIZE_SAMPLE1,NB_CENTER, DIM_POINT, TYPE_POINT> kmean;
-
- mln::io::ppm::load(img_ref, "/usr/local/share/olena/images/lena.ppm");
- //mln::io::ppm::save(img_ref, "verif.ppm");
-
- fill_image_with_4colors(img_ref);
- kmean.init_point(img_ref);
-
- mln_assertion(true == is_equivalent(img_ref, kmean.get_point()));
-
- std::cout << "Test init point : ok" << std::endl;
-}
-
-void set_point(MAT_POINT2& point,
- const unsigned index,
- const mln::value::rgb8& color)
-{
- point(index,0) = color.red();
- point(index,1) = color.green();
- point(index,2) = color.blue();
-}
-
-void fake_init_point(MAT_POINT2& point,
- const mln::value::rgb8& point1,
- const mln::value::rgb8& point2,
- const mln::value::rgb8& point3,
- const mln::value::rgb8& point4)
-{
- set_point(point, 0, point1);
- set_point(point, 1, point2);
- set_point(point, 2, point3);
- set_point(point, 3, point4);
-}
-
-bool is_equal(const mln::value::rgb8& ref,
- const MAT_CENTER& center,
- const unsigned i)
-{
- bool result = true;
-
- result = result && (center(i, 0) - ref.red() < 1.0);
- result = result && (center(i, 1) - ref.green() < 1.0);
- result = result && (center(i, 2) - ref.blue() < 1.0);
-
- return result;
-}
-
-void test_init_center()
-{
- mln::clustering::k_mean<SIZE_SAMPLE2, NB_CENTER, DIM_POINT, TYPE_POINT> kmean;
-
- const mln::value::rgb8 lime = mln::literal::lime;
- const mln::value::rgb8 brown = mln::literal::brown;
- const mln::value::rgb8 teal = mln::literal::teal;
- const mln::value::rgb8 purple = mln::literal::purple;
-
- fake_init_point(kmean.get_point(), lime, brown, teal, purple);
- kmean.init_center();
-
- mln_assertion(is_equal(lime, kmean.get_center(), 0) ||
- is_equal(brown, kmean.get_center(), 0) ||
- is_equal(teal, kmean.get_center(), 0) ||
- is_equal(purple, kmean.get_center(), 0));
-
- mln_assertion(is_equal(lime, kmean.get_center(), 1) ||
- is_equal(brown, kmean.get_center(), 1) ||
- is_equal(teal, kmean.get_center(), 1) ||
- is_equal(purple, kmean.get_center(), 1));
-
- std::cout << "Test init center : ok" << std::endl;
-}
-
-void set_center(MAT_CENTER& center,
- const unsigned index,
- const mln::value::rgb8& color)
-{
- center(index,0) = color.red();
- center(index,1) = color.green();
- center(index,2) = color.blue();
-}
-
-void fake_init_center(MAT_CENTER& center,
- const mln::value::rgb8 center1,
- const mln::value::rgb8 center2)
-{
-
- set_center(center, 0, center1);
- set_center(center, 1, center2);
-}
-
-
-double dist(mln::value::rgb8 color1, mln::value::rgb8 color2)
-{
- double red = color1.red() - color2.red();
- double green = color1.green() - color2.green();
- double blue = color1.blue() - color2.blue();
- double result= red * red + green * green + blue * blue;
-
- return result;
-}
-
-void test_update_distance()
-{
- mln::clustering::k_mean<SIZE_SAMPLE2, NB_CENTER, DIM_POINT, TYPE_POINT> kmean;
-
- const mln::value::rgb8 lime = mln::literal::lime;
- const mln::value::rgb8 brown = mln::literal::brown;
- const mln::value::rgb8 teal = mln::literal::teal;
- const mln::value::rgb8 purple = mln::literal::purple;
- const mln::value::rgb8 c1 = lime;
- const mln::value::rgb8 c2 = purple;
- const MAT_DISTANCE2& dist_v = kmean.get_distance();
-
- fake_init_point(kmean.get_point(), lime, brown, teal, purple);
- fake_init_center(kmean.get_center(), c1, c2);
- kmean.update_distance();
-
- mln_assertion(dist(lime, c1) == dist_v(0,0));
- mln_assertion(dist(lime, c2) == dist_v(0,1));
- mln_assertion(dist(brown, c1) == dist_v(1,0));
- mln_assertion(dist(brown, c2) == dist_v(1,1));
- mln_assertion(dist(teal, c1) == dist_v(2,0));
- mln_assertion(dist(teal, c2) == dist_v(2,1));
- mln_assertion(dist(purple, c1) == dist_v(3,0));
- mln_assertion(dist(purple, c2) == dist_v(3,1));
-
- std::cout << "Test update distance : ok" << std::endl;
-}
-
-void set_distance(MAT_DISTANCE2& distance,
- const unsigned index,
- const double d1,
- const double d2)
-{
- distance(index,0) = d1;
- distance(index,1) = d2;
-}
-
-void fake_update_distance(MAT_DISTANCE2& distance,
- const mln::value::rgb8& point1,
- const mln::value::rgb8& point2,
- const mln::value::rgb8& point3,
- const mln::value::rgb8& point4,
- const mln::value::rgb8& center1,
- const mln::value::rgb8& center2)
-{
- set_distance(distance, 0, dist(point1, center1), dist(point1, center2));
- set_distance(distance, 1, dist(point2, center1), dist(point2, center2));
- set_distance(distance, 2, dist(point3, center1), dist(point3, center2));
- set_distance(distance, 3, dist(point4, center1), dist(point4, center2));
-
- /*
- for (int i = 0; i < SIZE_SAMPLE2; ++i)
- for (int j = 0; j < NB_CENTER; ++j)
- std::cout << "d(" << i << "," << j << ") = " << distance(i,j) <<std::endl;
- */
-}
-
-void test_update_group()
-{
- mln::clustering::k_mean<SIZE_SAMPLE2, NB_CENTER, DIM_POINT, TYPE_POINT> kmean;
-
- const mln::value::rgb8 lime = mln::literal::lime;
- const mln::value::rgb8 brown = mln::literal::brown;
- const mln::value::rgb8 teal = mln::literal::teal;
- const mln::value::rgb8 purple = mln::literal::purple;
- const mln::value::rgb8 c1 = lime;
- const mln::value::rgb8 c2 = purple;
- const unsigned point1_min= 0; // lime near lime (c1)
- const unsigned point2_min= 1; // brown near purple (c2)
- const unsigned point3_min= 1; // teal near purple (c2)
- const unsigned point4_min= 1; // purple near purple (c2)
- const MAT_GROUP2& group = kmean.get_group();
-
- fake_init_point(kmean.get_point(), lime, brown, teal, purple);
- fake_init_center(kmean.get_center(), c1, c2);
- fake_update_distance(kmean.get_distance(), lime, brown, teal, purple, c1, c2);
- kmean.update_group();
-
- mln_assertion(0.0 == group(0, 1 - point1_min));
- mln_assertion(1.0 == group(0, point1_min));
- mln_assertion(0.0 == group(1, 1 - point2_min));
- mln_assertion(1.0 == group(1, point2_min));
- mln_assertion(0.0 == group(2, 1 - point3_min));
- mln_assertion(1.0 == group(2, point3_min));
- mln_assertion(0.0 == group(3, 1 - point4_min));
- mln_assertion(1.0 == group(3, point4_min));
-
- std::cout << "Test update group : ok" << std::endl;
-}
-
-void set_group(MAT_GROUP2& group,
- const unsigned index,
- const unsigned min)
-{
- group(index, min) = 1.0;
- group(index, 1-min) = 0.0;
-}
-
-
-void fake_update_group(MAT_GROUP2& group,
- const unsigned& point1_min,
- const unsigned& point2_min,
- const unsigned& point3_min,
- const unsigned& point4_min)
-{
- set_group(group, 0, point1_min);
- set_group(group, 1, point2_min);
- set_group(group, 2, point3_min);
- set_group(group, 3, point4_min);
-}
-
-void test_update_center()
-{
- mln::clustering::k_mean<SIZE_SAMPLE2, NB_CENTER, DIM_POINT, TYPE_POINT> kmean;
-
- const mln::value::rgb8 lime = mln::literal::lime;
- const mln::value::rgb8 brown = mln::literal::brown;
- const mln::value::rgb8 teal = mln::literal::teal;
- const mln::value::rgb8 purple = mln::literal::purple;
- const mln::value::rgb8 c1 = lime;
- const mln::value::rgb8 c2 = purple;
- const unsigned pt1_min = 0; // lime near lime (c1)
- const unsigned pt2_min = 1; // brown near purple (c2)
- const unsigned pt3_min = 1; // teal near purple (c2)
- const unsigned pt4_min = 1; // purple near purple (c2)
- const mln::value::rgb8 mean_c1 = lime;
- const mln::value::rgb8 mean_c2 = (brown+teal+purple)/3;
-
- fake_init_point(kmean.get_point(), lime, brown, teal, purple);
- fake_init_center(kmean.get_center(), c1, c2);
- fake_update_distance(kmean.get_distance(), lime, brown, teal, purple, c1, c2);
- fake_update_group(kmean.get_group(), pt1_min, pt2_min, pt3_min, pt4_min);
- kmean.update_center();
-
- mln_assertion(is_equal(mean_c1, kmean.get_center(), 0));
- mln_assertion(is_equal(mean_c2, kmean.get_center(), 1));
-
- std::cout << "Test update center : ok" << std::endl;
-}
-
-void test_update_variance()
-{
- mln::clustering::k_mean<SIZE_SAMPLE2, NB_CENTER, DIM_POINT, TYPE_POINT> kmean;
-
- const mln::value::rgb8 lime = mln::literal::lime;
- const mln::value::rgb8 brown = mln::literal::brown;
- const mln::value::rgb8 teal = mln::literal::teal;
- const mln::value::rgb8 purple = mln::literal::purple;
- const mln::value::rgb8 c1 = lime;
- const mln::value::rgb8 c2 = purple;
- const unsigned pt1_min = 0; // lime near lime (c1)
- const unsigned pt2_min = 1; // brown near purple (c2)
- const unsigned pt3_min = 1; // teal near purple (c2)
- const unsigned pt4_min = 1; // purple near purple (c2)
- const double v1 = 0;
- const double v2 = dist(purple, brown) + dist(purple, teal);
- const mln::value::rgb8 mean_c2 = (brown+teal+purple)/3;
- const VEC_VAR& var = kmean.get_variance();
-
- fake_init_point(kmean.get_point(), lime, brown, teal, purple);
- fake_init_center(kmean.get_center(), c1, c2);
- fake_update_distance(kmean.get_distance(), lime, brown, teal, purple, c1, c2);
- fake_update_group(kmean.get_group(), pt1_min, pt2_min, pt3_min, pt4_min);
- kmean.update_variance();
-
- mln_assertion(v1 == var[0]);
- mln_assertion(v2 == var[1]);
-
- std::cout << "Test update variance : ok" << std::endl;
-}
-
-void test_loop()
-{
- typedef mln::value::rgb8 rgb8;
- mln::image2d<rgb8> img_ref;
-
- mln::clustering::k_mean<SIZE_SAMPLE1, NB_CENTER, DIM_POINT, TYPE_POINT> kmean;
-
- mln::io::ppm::load(img_ref, "/usr/local/share/olena/images/lena.ppm");
- //mln::io::ppm::save(img_ref, "verif.ppm");
-
- fill_image_with_4colors(img_ref);
- kmean.init_point(img_ref);
-
- kmean.loop(img_ref);
-
-
- // std::cout << "Test update variance: ok" << std::endl;
-}
-
-
-int main()
-{
- //test_instantiation();
- //test_init_point();
- //test_init_center();
- //test_update_distance();
- //test_update_group();
- //test_update_center();
- //test_update_variance();
-
- // mln::trace::quiet = false;
-
- test_loop();
-
- return 0;
-}
diff --git a/trunk/milena/sandbox/green/k_mean/k_mean.hh b/trunk/milena/sandbox/green/k_mean/k_mean.hh
deleted file mode 100644
index db3f34c..0000000
--- a/trunk/milena/sandbox/green/k_mean/k_mean.hh
+++ /dev/null
@@ -1,672 +0,0 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory (LRDE)
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
-// Copyright (C) 2009 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_CLUSTERING_K_MEAN_HH
-#define MLN_CLUSTERING_K_MEAN_HH
-
-/// \file
-///
-/// \brief Implements the K MEAN algorithm.
-/// DO
-/// - ASSIGNEMENT STEP
-/// - UPDATE STEP
-/// LOOP UNTIL CONVERGENCE
-///
-/// ASSIGNEMENT STEP
-/// BEGIN
-/// - COMPUTE THE DISTANCE MATRIX FROM POINTS TO CENTERS
-/// - COMPUTE GROUP MATRIX WHERE EACH POINT IS ASSIGNED TO NEAREST CENTER
-/// END
-///
-/// UPDATE STEP
-/// BEGIN
-/// - COMPUTE THE MEAN OF THE GROUPS WHICH ARE THE NEW CENTERS
-/// END
-
-#include <limits.h>
-#include <iostream>
-#include <mln/trace/entering.hh>
-#include <mln/trace/exiting.hh>
-
-#include <mln/core/contract.hh>
-#include <mln/trait/value_.hh>
-
-#include <mln/algebra/mat.hh>
-#include <mln/algebra/vec.hh>
-
-#include <mln/math/min.hh>
-#include <mln/norm/l2.hh>
-
-#include <mln/core/concept/image.hh>
-#include <mln/core/macros.hh>
-
-namespace mln
-{
-
- namespace clustering
- {
-
- // Forward declaration.
- template <unsigned n, unsigned k, unsigned p, typename T>
- struct k_mean;
-
- } // end of namespace mln::clustering
-
- namespace clustering
- {
-
- //
- // PARAM : DIM VECTOR, NUMBER OF CLASSES
- // INPUT : MATRIX 1..N (SAMPLE)
- // WORK
- //
-
- // n is the size of the sample.
- // k is the number of centers.
- // p is the number of attributes for a point.
- // T is the type for computations.
- template <unsigned n, unsigned k, unsigned p, typename T>
- struct k_mean
- {
-
- //------------------------------------------------------------------------
- // Constructor and destructor
- //------------------------------------------------------------------------
-
- k_mean();
- ~k_mean();
-
-
- //------------------------------------------------------------------------
- // Accessors
- //------------------------------------------------------------------------
-
- algebra::mat<n, p, T>& get_point();
- algebra::mat<k, p, T>& get_center();
- algebra::mat<n, k, T>& get_distance();
- algebra::mat<n, k, T>& get_group();
- algebra::vec<k, T>& get_variance();
-
-
- //------------------------------------------------------------------------
- // Tools
- //------------------------------------------------------------------------
-
-
- /// \brief Return the euclidian distance beetween vector x and vector y.
- ///
- /// Compute the f$\sqrt(\sum_{i=0}^P ((x_i - y_i)^2)$f
- ///
- /// \param[in] x a vector of dimension 1xP.
- /// \param[in] y a second vector of dimension 1xP.
- /// \return the distance between x and y.
-
- mln_sum_product(T,T) euclidian_distance(const algebra::vec<p,T>& x,
- const algebra::vec<p,T>& y) const;
-
- /// \brief Return the ith column.
- ///
- /// \param[in] m a matrix of dimension {N or K}xP.
- /// \return the ith column as a vector of dimension 1xP.
-
-
- /// \brief Return the ith column.
- ///
- /// \param[in] m a matrix of dimension {N or K}xP.
- /// \return the ith column as a vector of dimension 1xP.
- template <unsigned q, unsigned r>
- algebra::vec<q,T> col(const algebra::mat<r, q, T>& m,
- const unsigned _col) const;
-
- template <unsigned q, unsigned r>
- algebra::vec<q,T>* ptr_col(const algebra::mat<r, q, T>& m,
- const unsigned _col) const;
-
- template <unsigned q, unsigned r>
- algebra::vec<r,T> row(const algebra::mat<r, q, T>& m,
- const unsigned _row) const;
-
- template <unsigned q, unsigned r>
- void div_col(algebra::mat<r, q, T>& m,
- const unsigned _col,
- const T value);
-
- template <unsigned q, unsigned r>
- mln_sum(T) sum_row(const algebra::mat<r, q, T>& m,
- const unsigned _row) const;
-
- template <unsigned q, typename M>
- M min_col(const algebra::vec<q, M>& x) const;
-
-
- //------------------------------------------------------------------------
- // Initializations of points and centers
- //------------------------------------------------------------------------
-
- /// \brief Initialize the matrix _point with the pixels of an image.
- ///
- /// \param[in] input an image which contains the data points.
- template <typename I>
- void init_point(const Image<I>& _input);
- void init_center();
-
-
- //------------------------------------------------------------------------
- // Computations of distance, group, center, within variance
- //------------------------------------------------------------------------
-
- void update_distance();
- void update_group();
- void update_center();
- T update_variance();
-
-
- //------------------------------------------------------------------------
- // Main loop
- //------------------------------------------------------------------------
-
- template <typename I>
- void loop(const Image<I>& _input);
- //void loop();
-
- private:
- static const unsigned watch_dog = 100;
-
- /// \brief _points contains the concatenation of every data points.
- ///
- /// One data point is a vector 1xP where P is the number of attributes.
- /// _points is a matrix NxP where N is the number of data points.
- algebra::mat<n, p, T>* _point;
-
- /// \brief _distance contains all the euclidian distances between points
- /// and the centers.
- ///
- /// _distance is a matrix NxK where N is the number of data points and
- /// K the number of centers.
- algebra::mat<n, k, mln_sum_product(T,T)>* _distance;
-
- /// \brief _group contains the point assignement to one center.
- ///
- /// _group is a boolean matrix NxK where N is the number of data points
- /// and K the number of centers.
- algebra::mat<n, k, T>* _group;
-
- /// \brief _center contains the coordonnate of the K centers.
- ///
- /// _center is a matrix KxP where K is the number of centers and P is the
- /// number of attributes.
- algebra::mat<k, p, T>* _center;
-
- algebra::vec<k, T>* _variance;
- };
-
-#ifndef MLN_INCLUDE_ONLY
-
- //--------------------------------------------------------------------------
- // Constructor and destructor
- //--------------------------------------------------------------------------
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- inline
- k_mean<n,k,p,T>::k_mean()
- {
- trace::entering("mln::clustering::k_mean::k_mean");
-
- _point = new algebra::mat<n, p, T>();
- _distance = new algebra::mat<n, k, mln_sum_product(T,T)>();
- _group = new algebra::mat<n, k, T>();
- _center = new algebra::mat<k, p, T>();
- _variance = new algebra::vec<k,T>();
-
- mln_postcondition(_point != 0);
- mln_postcondition(_distance != 0);
- mln_postcondition(_group != 0);
- mln_postcondition(_center != 0);
- mln_postcondition(_variance != 0);
-
- trace::exiting("mln::clustering::k_mean::k_mean");
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- inline
- k_mean<n,k,p,T>::~k_mean()
- {
- trace::entering("mln::clustering::k_mean::~k_mean");
-
- delete _point;
- delete _distance;
- delete _group;
- delete _center;
- delete _variance;
-
- trace::exiting("mln::clustering::k_mean::~k_mean");
- }
-
- //--------------------------------------------------------------------------
- // Accessors
- //--------------------------------------------------------------------------
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- inline
- algebra::mat<n, p, T>&
- k_mean<n,k,p,T>::get_point()
- {
- trace::entering("mln::clustering::k_mean::get_point");
- trace::exiting("mln::clustering::k_mean::get_point");
-
- return *_point;
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- inline
- algebra::mat<k, p, T>&
- k_mean<n,k,p,T>::get_center()
- {
- trace::entering("mln::clustering::k_mean::get_center");
- trace::exiting("mln::clustering::k_mean::get_center");
-
- return *_center;
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- inline
- algebra::mat<n, k, T>&
- k_mean<n,k,p,T>::get_distance()
- {
- trace::entering("mln::clustering::k_mean::get_distance");
- trace::exiting("mln::clustering::k_mean::get_distance");
-
- return *_distance;
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- inline
- algebra::mat<n, k, T>&
- k_mean<n,k,p,T>::get_group()
- {
- trace::entering("mln::clustering::k_mean::get_group");
- trace::exiting("mln::clustering::k_mean::get_group");
-
- return *_group;
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- inline
- algebra::vec<k, T>&
- k_mean<n,k,p,T>::get_variance()
- {
- trace::entering("mln::clustering::k_mean::get_variance");
- trace::exiting("mln::clustering::k_mean::get_variance");
-
- return *_variance;
- }
-
- //--------------------------------------------------------------------------
- // Tools
- //--------------------------------------------------------------------------
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- template <unsigned q, unsigned r>
- inline
- algebra::vec<r, T> k_mean<n,k,p,T>::row(const algebra::mat<r, q, T>& m,
- const unsigned _row) const
- {
- trace::entering("mln::clustering::k_mean::row");
- mln_precondition(q > _row);
-
- algebra::vec<r, T> result;
-
- for (unsigned i = 0; i < r; ++i)
- result[i] = m(i, _row);
-
- trace::exiting("mln::clustering::k_mean::row");
- return result;
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- template <unsigned q, unsigned r>
- inline
- algebra::vec<q,T> k_mean<n,k,p,T>::col(const algebra::mat<r, q, T>& m,
- const unsigned _col) const
- {
- trace::entering("mln::clustering::k_mean::col");
- mln_precondition(r > _col);
-
- algebra::vec<q, T> result;
-
- for (unsigned j = 0; j < q; ++j)
- result[j] = m(_col, j);
-
- trace::exiting("mln::clustering::k_mean::col");
- return result;
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- template <unsigned q, unsigned r>
- inline
- algebra::vec<q,T>* k_mean<n,k,p,T>::ptr_col(const algebra::mat<r, q, T>& m,
- const unsigned _col) const
- {
- trace::entering("mln::clustering::k_mean::ptr_col");
- mln_precondition(r > _col);
-
- algebra::vec<q, T> *result = new algebra::vec<q, T>();
-
- for (unsigned j = 0; j < q; ++j)
- (*result)[j] = m(_col, j);
-
- trace::exiting("mln::clustering::k_mean::ptr_col");
- return result;
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- template <unsigned q, unsigned r>
- inline
- mln_sum(T) k_mean<n,k,p,T>::sum_row(const algebra::mat<r, q, T>& m,
- const unsigned _row) const
- {
- trace::entering("mln::clustering::k_mean::sum_row");
- mln_precondition(q > _row);
-
- mln_sum(T) result;
-
- for (unsigned j = 0; j < r; ++j)
- result += m(j, _row);
-
- trace::exiting("mln::clustering::k_mean::sum_row");
- return result;
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- template <unsigned q, unsigned r>
- inline
- void k_mean<n,k,p,T>::div_col(algebra::mat<r, q, T>& m,
- const unsigned _col,
- const T value)
- {
- trace::entering("mln::clustering::k_mean::div_col");
- mln_precondition(r > _col);
-
- for (unsigned j = 0; j < q; ++j)
- m(_col, j) /= value;
-
- trace::exiting("mln::clustering::k_mean::div_col");
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- template <unsigned q, typename M>
- inline
- M k_mean<n,k,p,T>::min_col(const algebra::vec<q, M>& x) const
- {
- trace::entering("mln::clustering::k_mean<n,k,p,T>::min_col");
-
- M result = x[0];
-
- for (unsigned i = 1; i < q; ++i)
- result = math::min(result, x[i]);
-
- trace::exiting("mln::clustering::k_mean<n,k,p,T>::min_col");
- return result;
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- inline
- mln_sum_product(T,T)
- k_mean<n,k,p,T>::euclidian_distance(const algebra::vec<p, T>& x,
- const algebra::vec<p, T>& y) const
- {
- trace::entering("mln::clustering::k_mean::euclidian_distance");
- //vec<p, double> tmp = norm::l2(x - y);
- const algebra::vec<p, double> tmp = (x - y);
- mln_sum_product(T,T) result = tmp*tmp;
-
- trace::exiting("mln::clustering::k_mean::euclidian_distance");
- return result;
- }
-
-
- //--------------------------------------------------------------------------
- // Initializations of points and centers
- //--------------------------------------------------------------------------
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- template <typename I>
- inline
- void k_mean<n,k,p,T>::init_point(const Image<I>& _input)
- {
- trace::entering("mln::clustering::k_mean<n,k,p,T>::init");
-
- const I& input = exact(_input);
- algebra::mat<n, p, T>& point = *_point;
-
- mln_precondition(input.is_valid());
- mln_precondition(n == input.nrows() * input.ncols());
- //mln_precondition(n == input.nrows());
- //mln_precondition(n == input.nrows() * input.ncols() * input.nslices());
-
- mln_piter(I) pi(input.domain());
- unsigned i = -1;
-
- for_all(pi)
- {
- //std::cout << pi << std::endl;
-
- ++i;
- for (unsigned j = 0; j < p; ++j)
- {
-
- point(i,j) = input(pi).comp(j);
- //point(i,j) = input(pi);
- }
- }
-
- trace::exiting("mln::clustering::k_mean<n,k,p,T>::init");
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- inline
- void k_mean<n,k,p,T>::init_center()
- {
- trace::entering("mln::clustering::k_mean<n,k,p,T>::init_center");
-
- algebra::mat<n, p, T>& point = *_point;
- algebra::mat<k, p, T>& center = *_center;
-
- // A random point is choosen to be the initial value for a center.
- for (unsigned i = 0; i < k; ++i)
- {
- unsigned random = rand() % n;
-
- for (unsigned j = 0; j < p; ++j)
- {
- center(i,j) = point(random, j);
- }
-
- //std::cout << "center(" << i << ")" << col(center, i) << std::endl;
- }
-
- trace::exiting("mln::clustering::k_mean<n,k,p,T>::init_center");
- }
-
-
- //--------------------------------------------------------------------------
- // Computations of distance, group, center, within variance
- //--------------------------------------------------------------------------
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- inline
- void k_mean<n,k,p,T>::update_distance()
- {
- trace::entering("mln::clustering::k_mean::update_distance");
- //mln::trace::quiet = true;
-
- // the result is stored in _distance matrix.
- algebra::mat<n, p, T>& point = *_point;
- algebra::mat<n, k, T>& distance = *_distance;
- algebra::mat<k, p, T>& center = *_center;
-
- // for all points in the data cloud.
- for (unsigned i = 0; i < n; ++i)
- {
- // for every center
- for (unsigned j = 0; j < k; ++j)
- {
- distance(i,j) = euclidian_distance(col(point,i),col(center,j));
- }
- }
- //mln::trace::quiet = false;
- trace::exiting("mln::clustering::k_mean::update_distance");
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- inline
- void k_mean<n,k,p,T>::update_group()
- {
- trace::entering("mln::clustering::k_mean<n,k,p,T>::update_group");
-
- algebra::mat<n, k, mln_sum_product(T,T)>& distance = *_distance;
- algebra::mat<n, k, T>& group = *_group;
-
- // for each point
- for (unsigned i = 0; i < n; ++i)
- {
- // tell us the minimum distance from a specific point to a group
- mln_sum_product(T,T) min_dist = min_col(col(distance, i));
-
- // for each center
- for (unsigned j = 0; j < k; ++j)
- group(i,j) = (min_dist == distance(i,j))? 1.0 : 0.0;
- }
-
- // mln_postcondition(sum(col(distance(i,j)) == 1) Vi
- trace::exiting("mln::clustering::k_mean<n,k,p,T>::update_group");
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- inline
- void k_mean<n,k,p,T>::update_center()
- {
- trace::entering("mln::clustering::k_mean<n,k,p,T>::update_center");
-
- algebra::mat<n, p, T>& point = *_point;
- algebra::mat<k, p, T>& center = *_center;
- algebra::mat<n, k, T>& group = *_group;
-
- // center = (group.t() * point);
-
- for (unsigned i = 0; i < k; ++i)
- {
- for (unsigned j = 0; j < p; ++j)
- {
- center(i,j) = literal::zero;
-
- for (unsigned l = 0; l < n; ++l)
- center(i,j) += group(l,i) * point(l,j);
- }
- }
-
- for (unsigned i = 0; i < k; ++i)
- div_col(center, i, sum_row(group, i));
-
- trace::exiting("mln::clustering::k_mean<n,k,p,T>::update_center");
- }
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- inline
- T k_mean<n,k,p,T>::update_variance()
- {
- trace::entering("mln::clustering::k_mean<n,k,p,T>::update_variance");
-
- algebra::vec<k, T>& variance = *_variance;
- algebra::mat<n, k, T>& distance = *_distance;
- algebra::mat<n, k, T>& group = *_group;
- T result = literal::zero;
-
- // for every group
- for (unsigned i = 0; i < k; ++i)
- {
- variance[i] = row(group, i) * row(distance, i);
- result += variance[i];
- }
-
- trace::exiting("mln::clustering::k_mean<n,k,p,T>::update_variance");
- return result;
- }
-
-
- //--------------------------------------------------------------------------
- // Main loop
- //--------------------------------------------------------------------------
-
- template <unsigned n, unsigned k, unsigned p, typename T>
- template <typename I>
- inline
- void k_mean<n,k,p,T>::loop(const Image<I>& _input)
- //void k_mean<n,k,p,T>::loop()
- {
- trace::entering("mln::clustering::k_mean<n,k,p,T>::loop");
-
- T within_variance = INT_MAX-1;
- T old_variance = INT_MAX;
-
- init_point(_input);
- init_center();
-
- std::cout << "LOOP" << std::endl;
-
- for (unsigned i = 0; i < watch_dog && within_variance < old_variance; ++i)
- {
- update_distance();
-
- std::cout << "DISTANCE DONE" << std::endl;
-
- update_group();
-
- std::cout << "GROUP DONE" << std::endl;
-
- update_center();
-
- std::cout << "UPDATE CENTER DONE" << std::endl;
-
- old_variance = within_variance;
- within_variance = update_variance();
-
- std::cout << i << " : " << within_variance << std::endl;
- }
-
- trace::exiting("mln::clustering::k_mean<n,k,p,T>::loop");
- }
-
-
-
-#endif // ! MLN_INCLUDE_ONLY
-
- } // end of namespace mln::clustering
-
-} // end of namespace mln::clustering
-
-#endif // ! MLN_CLUSTERING_K_MEAN_HH
--
1.5.6.5
1
0