https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Start /filtering to n components/ procedure.
* jardonnet/n_cmpt/Makefile (all,debug): New.
* jardonnet/n_cmpt: New.
* jardonnet/n_cmpt/n_cmpt.cc: New. Lauch procedure.
* jardonnet/n_cmpt/check: New.
* jardonnet/n_cmpt/check/tiny.pgm: New test image.
* jardonnet/n_cmpt/check/mg_ima.pgm: New test image.
* jardonnet/n_cmpt/n_cmpt.hh: Modified version of algebraic unionfind.
* jardonnet/igr/check/check: New check script.
igr/Makefile | 24 ++++---
igr/check/check | 10 +++
n_cmpt/Makefile | 5 +
n_cmpt/n_cmpt.cc | 43 +++++++++++++
n_cmpt/n_cmpt.hh | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 247 insertions(+), 9 deletions(-)
Index: jardonnet/n_cmpt/n_cmpt.cc
--- jardonnet/n_cmpt/n_cmpt.cc (revision 0)
+++ jardonnet/n_cmpt/n_cmpt.cc (revision 0)
@@ -0,0 +1,43 @@
+
+#include <iostream>
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/accu/volume.hh>
+
+#include "n_cmpt.hh"
+
+using namespace mln;
+using namespace mln::value;
+
+bool usage(int argc, char ** argv)
+{
+ if (argc != 3)
+ {
+ std::cout << argv[0] << " ima.pgm lambda" << std::endl;
+ return false;
+ }
+ return true;
+}
+
+int main(int argc, char ** argv)
+{
+ if (not usage(argc,argv))
+ return 1;
+
+ image2d<int_u8> ima;
+ io::pgm::load(ima, argv[1]);
+
+ int lambda = atoi(argv[2]);
+
+ image2d<int_u8> out(ima.domain());
+
+ n_cmpt::algebraic_union_find(ima, c4(), lambda, out);
+
+ io::pgm::save(out, "out.pgm");
+}
+
Index: jardonnet/n_cmpt/Makefile
--- jardonnet/n_cmpt/Makefile (revision 0)
+++ jardonnet/n_cmpt/Makefile (revision 0)
@@ -0,0 +1,5 @@
+n_cmpt: n_cmpt.hh n_cmpt.cc
+ g++ -I../../.. n_cmpt.cc -DNDEBUG -O1 -o n_cmpt
+
+debug: n_cmpt.hh n_cmpt.cc
+ g++ -I../../.. n_cmpt.cc -g -g3 -DNDEBUG -O1 -o n_cmpt
Index: jardonnet/n_cmpt/check/tiny.pgm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: jardonnet/n_cmpt/check/tiny.pgm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: jardonnet/n_cmpt/check/mg_ima.pgm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: jardonnet/n_cmpt/check/mg_ima.pgm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Index: jardonnet/n_cmpt/n_cmpt.hh
--- jardonnet/n_cmpt/n_cmpt.hh (revision 0)
+++ jardonnet/n_cmpt/n_cmpt.hh (revision 0)
@@ -0,0 +1,174 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN__N_CMPT_HH
+# define MLN__N_CMPT_HH
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/level/fill.hh>
+# include <mln/util/pix.hh>
+# include <mln/level/sort_psites.hh>
+
+namespace mln
+{
+
+ namespace n_cmpt
+ {
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ inline
+ mln_psite(I)
+ find_root(I& parent,
+ const mln_psite(I)& x)
+ {
+ if (parent(x) == x)
+ return x;
+ else
+ return parent(x) = find_root(parent, parent(x));
+ }
+
+ template <typename I, typename N, typename O>
+ void
+ algebraic_union_find(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ unsigned limit,
+ Image<O>& output_)
+ {
+ trace::entering("canvas::morpho::algebraic_union_find");
+
+ std::cout << "limit = " << limit << std::endl;
+
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ O& output = exact(output_);
+
+ mln_precondition(output.domain() == input.domain());
+
+ // Local type.
+ typedef mln_psite(I) P;
+
+ typedef accu::volume<I> A;
+ typedef mln_psite(I) P;
+ typedef p_array<P> S;
+
+ const S s(level::sort_psites_increasing(input));
+
+ // Auxiliary data.
+ mln_ch_value(O, bool) deja_vu;
+ mln_ch_value(O, P) parent;
+
+ int n_cmpt = input.domain().nsites();
+ int lambda = 10;
+ std::cout << "trying lambda = 10" << std::endl;
+
+ // init
+ {
+ initialize(deja_vu, input);
+ initialize(parent, input);
+ }
+
+ // first pass
+ {
+
+ do {
+ mln_ch_value(O, A) data;
+ initialize(data, input);
+
+ mln::level::fill(deja_vu, false);
+
+ {
+ mln_fwd_piter(S) p(s);
+ for_all(p)
+ parent(p) = p;
+ }
+
+ mln_fwd_piter(S) p(s); // s required.
+ mln_niter(N) n(nbh, p);
+ for_all(p)
+ {
+ // Make set.
+ {
+ data(p).take_as_init(make::pix(input, p)); // FIXME: algebraic so p!
+ }
+
+ for_all(n)
+ if (input.domain().has(n) && deja_vu(n))
+ {
+ //do_union(n, p);
+ P r = find_root(parent, n);
+ if (r != p)
+ {
+ if (input(r) == input(p) || (data(p).to_result() < lambda))
+ // Either a flat zone or the component of r is still growing.
+ {
+ data(p).take(data(r));
+ parent(r) = p;
+ if(--n_cmpt <= limit)
+ {
+ std::cout << "limit reached at " <<
n_cmpt << std::endl;
+ goto step2;
+ }
+ }
+ else
+ data(p).set_value(lambda);
+ }
+ }
+ deja_vu(p) = true;
+ }
+ n_cmpt = input.domain().nsites();
+ lambda *= 1.1;
+ std::cout << "trying lambda = " << lambda <<
std::endl;
+ }while (1);
+ }
+
+ step2:
+ // second pass
+ {
+ mln_bkd_piter(S) p(s);
+ for_all(p)
+ if (parent(p) == p) // p is root.
+ output(p) = input(p);
+ else
+ output(p) = output(parent(p));
+ }
+
+ trace::exiting("canvas::morpho::algebraic_union_find");
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::n_cmpt
+
+} // end of namespace mln
+
+#endif /* MLN__N_CMPT_HH */
+
Index: jardonnet/igr/Makefile
--- jardonnet/igr/Makefile (revision 2941)
+++ jardonnet/igr/Makefile (working copy)
@@ -2,18 +2,20 @@
## Author: ugo.jardonnet(a)lrde.epita.fr
## Version: $Id: Makefile,v 0.0 2008/11/19 11:40:34 jardonnet Exp $
-## Keywords:
-## X-URL:
+## Keywords: IGR OLENA LRDE RECONSTRUCTION
+
+
+CXXC?=g++
+LFLAGS=-I../../abraham/ -I../../../
+CFLAGS=-W -Wall -Wextra -O1 -DNDEBUG
PROJ=igr-reco
SRC=src/igr.cc
BIN=igr
-LFLAGS=-I../../abraham/ -I../../../
-CFLAGS=-W -Wall -Wextra -O1 -DNDEBUG
FILES=src configure check README
$(BIN): Makefile
- g++ $(CFLAGS) $(LFLAGS) $(SRC) -o $(BIN)
+ $(CXXC) $(CFLAGS) $(LFLAGS) $(SRC) -o $(BIN)
check:
cd check && ./check
@@ -23,7 +25,7 @@
rm -f .deps .depsr
rm -f *.ppm
-dist: clean todo AUTHORS svn_check
+dist: clean AUTHORS TODO svn_check
rm -rf $(PROJ)
mkdir $(PROJ)
cp -r Makefile AUTHORS TODO $(FILES) $(PROJ)
@@ -34,21 +36,25 @@
rm -rf $(PROJ)
chmod 644 $(PROJ).tar.bz2
+AUTHORS:
+ echo $(USER) > AUTHORS
+
svn_check:
@svn st | grep \? ; [ $$? = "1" ] \
|| (echo "----------------------------------------------"\
&& echo "SOME FILES ARE MISSING FROM THE SVN REPOSITORY"\
&& echo "----------------------------------------------");
-todo:
- grep "FIXME" -r . --exclude="Makefile" > TODO
+TODO:
+ grep "FIXME" -r . --exclude="Makefile"
--exclude-dir=".svn" \
+ --exclude="TODO" > TODO
.deps:
g++ $(LFLAGS) -MM $(SRC) > $@
@sed -ir s/igr.cc// .deps
@sed -ir s/igr.o/igr/ .deps
-.PHONY: doc check .deps
+.PHONY: doc check .deps AUTHORS TODO
include .deps
Index: jardonnet/igr/check/check
--- jardonnet/igr/check/check (revision 0)
+++ jardonnet/igr/check/check (revision 0)
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+
+for i in `seq 10000 1000 50000`
+do
+ ../igr ./tiny.ppm $i
+ mv out.ppm out/$i.ppm
+done
+
+rm g_ima.ppm mg_ima.ppm o_ima.ppm
\ No newline at end of file
Property changes on: jardonnet/igr/check/check
___________________________________________________________________
Name: svn:executable
+ *