* dalila/Makefile,
* dalila/photo.cc,
* dalila/plop.cc,
* dalila/start.sh,
* dalila/table.cc: Delete.
---
milena/sandbox/ChangeLog | 10 ++++++
milena/sandbox/dalila/Makefile | 18 -----------
milena/sandbox/dalila/photo.cc | 64 --------------------------------------
milena/sandbox/dalila/plop.cc | 19 -----------
milena/sandbox/dalila/start.sh | 44 --------------------------
milena/sandbox/dalila/table.cc | 66 ----------------------------------------
6 files changed, 10 insertions(+), 211 deletions(-)
delete mode 100644 milena/sandbox/dalila/Makefile
delete mode 100644 milena/sandbox/dalila/photo.cc
delete mode 100644 milena/sandbox/dalila/plop.cc
delete mode 100755 milena/sandbox/dalila/start.sh
delete mode 100644 milena/sandbox/dalila/table.cc
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index 216b67c..089a6f4 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,3 +1,13 @@
+2009-07-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Delete Dalila's sandbox.
+
+ * dalila/Makefile,
+ * dalila/photo.cc,
+ * dalila/plop.cc,
+ * dalila/start.sh,
+ * dalila/table.cc: Delete.
+
2009-07-01 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
Add new programs to extract data from microfilms.
diff --git a/milena/sandbox/dalila/Makefile b/milena/sandbox/dalila/Makefile
deleted file mode 100644
index 7ab2b0a..0000000
--- a/milena/sandbox/dalila/Makefile
+++ /dev/null
@@ -1,18 +0,0 @@
-OLENA_INCLUDE_PATH=../../../
-CXXFLAGS=-I$(OLENA_INCLUDE_PATH) -ggdb3 -Wall -O1 -DNDEBUG
-
-all: photo table
-
-photo: demat.hh photo.cc
- g++ $(CXXFLAGS) photo.cc -o photo
-
-table: demat.hh table.cc
- g++ $(CXXFLAGS) table.cc -o table
-
-dclean: clean
- rm -f photo
- rm -f table
-
-clean:
- rm -f *.pbm *.pgm *.ppm
-
diff --git a/milena/sandbox/dalila/photo.cc b/milena/sandbox/dalila/photo.cc
deleted file mode 100644
index 118411b..0000000
--- a/milena/sandbox/dalila/photo.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
-//
-// This file is part of the Milena 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.
-
-
-#include "demat.hh"
-
-int main(int argc, char*argv[])
-{
- using namespace mln;
- using value::int_u8;
-
- if (argc < 2)
- {
- std::cout << argv[0] << " <in.pbm> <out.pgm> <l> <bbox_larger> <bbox_distance> <min_comp_nsites>" << std::endl
- << std::endl << std::endl
- << std::endl
- << "=========="
- << std::endl << std::endl
- << "<in.pbm> B/W inverted input image."
- << std::endl << std::endl
-/* << "<out.ppm> RGB8 output image."
- << std::endl << std::endl
- << "<bbox_distance> Maximum distance between character bounding boxes. Used for bbox grouping."
- << std::endl << std::endl
- << "<min_comp_nsites> Minimum site count of a character/text component."
- << std::endl
- << " If a component have a site count lesser than this value, it is erased."
- << std::endl << std::endl
- << std::endl*/
- << "=========="
- << std::endl << std::endl
- << "HINT: compile with -DNOUT to avoid debug images."
- << std::endl << std::endl;
- return 1;
- }
-
- scribo::demat(argv, false);
-
- return 0;
-}
diff --git a/milena/sandbox/dalila/plop.cc b/milena/sandbox/dalila/plop.cc
deleted file mode 100644
index a4c284d..0000000
--- a/milena/sandbox/dalila/plop.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-#include <mln/essential/2d.hh>
-
-int main()
-{
- using namespace mln;
-
- image2d<bool> ima1(2, 3);
- image2d<bool> ima2(2, 3);
-
- data::fill(ima1, 2);
- data::fill(ima2, 3);
-
-// debug::println(ima1);
-// debug::println(ima2);
-
-// debug::println(ima2 - ima1);
-// debug::println(arith::minus(ima2, ima1));
- ima1 * ima2;
-}
diff --git a/milena/sandbox/dalila/start.sh b/milena/sandbox/dalila/start.sh
deleted file mode 100755
index de4840c..0000000
--- a/milena/sandbox/dalila/start.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/sh
-
-out_location="./images-out"
-
-treat_file()
-{
- file=$1
- shift
- echo "-------------------------"
- echo " * Processing $file..."
- echo " => Running: $1 $file"
- echo "-------------------------"
- d1=`date +%s`
- time $1 $file
- d2=`date +%s`
- echo ""
- dstdir="$out_location/`basename $file .pbm`"
- echo "Moving output files to $dstdir..."
- mkdir -p $dstdir
- mv -f *.pbm $dstdir 2>/dev/null
- mv -f *.ppm $dstdir 2>/dev/null
- mv -f *.pgm $dstdir 2>/dev/null
- echo ""
-}
-
-treat_dir()
-{
- for file in $2/*; do
- treat_file $file $1
- done
-}
-
-rm -f *.pbm *.ppm *.pgm
-make
-
-# Traite une seule image
-# Usage: ./starh.sh <file.pbm> <table | photo>
-if [ $# -eq 2 ]; then
- treat_file $1 ./$2
-else
-# Traite toutes les images
- treat_dir ./table ./images/factures
- treat_dir ./photo ./images/photos
-fi
diff --git a/milena/sandbox/dalila/table.cc b/milena/sandbox/dalila/table.cc
deleted file mode 100644
index 76faf57..0000000
--- a/milena/sandbox/dalila/table.cc
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
-//
-// This file is part of the Milena 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.
-
-
-#include "demat.hh"
-
-int main(int argc, char*argv[])
-{
- using namespace mln;
- using value::int_u8;
-
- if (argc < 2)
- {
- std::cout << argv[0] << " <in.pbm> <out.pgm> <l> <bbox_larger> <bbox_distance> <min_comp_nsites>" << std::endl
- << std::endl << std::endl
- << std::endl
- << "=========="
- << std::endl << std::endl
- << "<in.pbm> B/W inverted input image."
- << std::endl << std::endl
-/* << "<out.ppm> RGB8 output image."
- << std::endl << std::endl
- << "<l> Line length"
- << std::endl << std::endl
- << "<bbox_distance> Maximum distance between character bounding boxes. Used for bbox grouping."
- << std::endl << std::endl
- << "<min_comp_nsites> Minimum site count of a character/text component."
- << std::endl
- << " If a component have a site count lesser than this value, it is erased."
- << std::endl << std::endl
- << std::endl*/
- << "=========="
- << std::endl << std::endl
- << "HINT: compile with -DNOUT to avoid debug images."
- << std::endl << std::endl;
- return 1;
- }
-
- scribo::demat(argv, true);
-
- return 0;
-}
--
1.5.6.5
* lazzara/afp/micro_films/Makefile: New.
* lazzara/afp/micro_films/demat_mf_afp.sh: New script running various
programs.
* lazzara/afp/micro_films/keep_background.cc,
* lazzara/afp/micro_films/extract_mf.cc,
* lazzara/afp/micro_films/split_image.cc: new dedicated programs for
microfilms data extraction.
---
milena/sandbox/ChangeLog | 14 ++
milena/sandbox/lazzara/afp/micro_films/Makefile | 8 ++
.../lazzara/afp/micro_films/demat_mf_afp.sh | 52 ++++++++
.../sandbox/lazzara/afp/micro_films/extract_mf.cc | 126 ++++++++++++++++++++
.../lazzara/afp/micro_films/keep_background.cc | 85 +++++++++++++
.../sandbox/lazzara/afp/micro_films/split_image.cc | 80 +++++++++++++
6 files changed, 365 insertions(+), 0 deletions(-)
create mode 100644 milena/sandbox/lazzara/afp/micro_films/Makefile
create mode 100755 milena/sandbox/lazzara/afp/micro_films/demat_mf_afp.sh
create mode 100644 milena/sandbox/lazzara/afp/micro_films/extract_mf.cc
create mode 100644 milena/sandbox/lazzara/afp/micro_films/keep_background.cc
create mode 100644 milena/sandbox/lazzara/afp/micro_films/split_image.cc
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index 5ec4781..216b67c 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,3 +1,17 @@
+2009-07-01 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Add new programs to extract data from microfilms.
+
+ * lazzara/afp/micro_films/Makefile: New.
+
+ * lazzara/afp/micro_films/demat_mf_afp.sh: New script running various
+ programs.
+
+ * lazzara/afp/micro_films/keep_background.cc,
+ * lazzara/afp/micro_films/extract_mf.cc,
+ * lazzara/afp/micro_films/split_image.cc: new dedicated programs for
+ microfilms data extraction.
+
2009-07-03 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Add some utils to handle objects detection with mean color attribute.
diff --git a/milena/sandbox/lazzara/afp/micro_films/Makefile b/milena/sandbox/lazzara/afp/micro_films/Makefile
new file mode 100644
index 0000000..4c81cc0
--- /dev/null
+++ b/milena/sandbox/lazzara/afp/micro_films/Makefile
@@ -0,0 +1,8 @@
+CXXFLAGS = -I../../../../ -I. -I../../../../../ -I../../../bin -O3 -DNDEBUG
+
+PROGRAMS = \
+ extract_mf \
+ split_image \
+ keep_background
+
+all: $(PROGRAMS)
diff --git a/milena/sandbox/lazzara/afp/micro_films/demat_mf_afp.sh b/milena/sandbox/lazzara/afp/micro_films/demat_mf_afp.sh
new file mode 100755
index 0000000..99f71d4
--- /dev/null
+++ b/milena/sandbox/lazzara/afp/micro_films/demat_mf_afp.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+PATH_TO_BIN=/lrde/stockholm/lazzara/svn/olena/git/oln/milena/sandbox/bin
+PATH_TO_SCRIBO=/lrde/stockholm/lazzara/svn/olena/git/build/scribo/src
+
+if [ $# -ne 2 ]; then
+ echo "Usage: $0 <input.pgm> <initial rotation>"
+ exit 1
+fi
+
+input=$PWD/$1
+bname=`basename $1 .pgm`
+mkdir -p $bname
+cd $bname
+
+
+echo "* Running pre-processing algorithms on $1."
+${PATH_TO_SCRIBO}/binarization/simple $input ${bname}.pbm
+${PATH_TO_BIN}/morpho/closing/structural_rectangle2d ${bname}.pbm 21 21 ${bname}_clo.pbm
+./../keep_background ${bname}_clo.pbm ${bname}_bg.pbm
+${PATH_TO_BIN}/morpho/dilation_rectangle2d ${bname}_bg.pbm 70 70 ${bname}_clo_dil.pbm
+${PATH_TO_SCRIBO}/negate ${bname}_clo_dil.pbm ${bname}_clo_dil_i.pbm
+
+echo "* Splitting $1 into several documents."
+./../extract_mf $input ${bname}.pbm ${bname}_clo_dil_i.pbm "$2"
+
+echo "* Processing extracted documents"
+for f in mf_*_.pgm; do
+ echo " - Processing $f..."
+
+ fbname=`basename $f .pgm`
+
+# Compute two different binary versions.
+ echo " # Binarization."
+ ${PATH_TO_BIN}/level_objects $f 100 ${fbname}_level.pgm
+ ${PATH_TO_SCRIBO}/binarization/simple ${fbname}_level.pgm ${fbname}_level.pbm
+
+ ${PATH_TO_SCRIBO}/binarization/simple $f ${fbname}.pbm
+
+# '_level' or '' according to which binary version you want to use.
+use_level=''
+
+ ${PATH_TO_BIN}/logical/not ${fbname}${use_level}.pbm ${fbname}${use_level}_i.pbm
+
+ echo " # Filtering."
+ ${PATH_TO_SCRIBO}/filter/small_objects ${fbname}${use_level}_i.pbm 3 ${fbname}${use_level}_small.pbm
+ ${PATH_TO_SCRIBO}/filter/thin_objects ${fbname}${use_level}_small.pbm 3 ${fbname}${use_level}_small_thin.pbm
+
+ echo " # Text extraction."
+ ${PATH_TO_SCRIBO}/extract_text_double_link ${fbname}${use_level}_small_thin.pbm 100 100 "${fbname}_text"
+done
+
diff --git a/milena/sandbox/lazzara/afp/micro_films/extract_mf.cc b/milena/sandbox/lazzara/afp/micro_films/extract_mf.cc
new file mode 100644
index 0000000..6587d1d
--- /dev/null
+++ b/milena/sandbox/lazzara/afp/micro_films/extract_mf.cc
@@ -0,0 +1,126 @@
+// 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.
+
+
+/// \file
+///
+///
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/imorph/labeled_image.hh>
+#include <mln/core/image/dmorph/image_if.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/var.hh>
+
+#include <mln/data/fill.hh>
+#include <mln/debug/filename.hh>
+#include <mln/io/pbm/all.hh>
+#include <mln/io/pgm/all.hh>
+#include <mln/labeling/blobs.hh>
+#include <mln/labeling/background.hh>
+#include <mln/labeling/n_max.hh>
+
+#include <mln/value/label_16.hh>
+
+#include <mln/geom/rotate.hh>
+#include <mln/data/fill.hh>
+#include <mln/logical/not.hh>
+
+#include <tools/usage.hh>
+#include <scribo/preprocessing/unskew.hh>
+#include <scribo/filter/small_objects.hh>
+
+#include <mln/data/compare.hh>
+
+
+const char *args_desc[][2] =
+{
+ { "input.pgm", "A gray level image." },
+ { "input.pbm", "A binary image." },
+ { "mask.pbm", "A binary image. Objects are set to 'true'. Will be used to split input.pbm into several images." },
+ { "rot", "Initial rotation in degrees." },
+ { 0, 0 }
+};
+
+
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+
+ if (argc != 5)
+ return tools::usage(argv,
+ "Extract an image for each object in the input image.",
+ "input.pgm input.pbm mask.pbm rot",
+ args_desc, "Gray level images extracted from the input.");
+
+ image2d<value::int_u8> input;
+ io::pgm::load(input, argv[1]);
+
+ image2d<bool> input_bw;
+ io::pbm::load(input_bw, argv[2]);
+
+ image2d<bool> mask;
+ io::pbm::load(mask, argv[3]);
+
+ value::label_16 nlabels;
+ typedef image2d<value::label_16> lbl_t;
+ lbl_t lbl_ = labeling::blobs(mask, c8(), nlabels);
+ labeled_image<lbl_t> lbl(lbl_, nlabels);
+
+ debug::internal::filename_prefix = "mf";
+
+
+ value::label_16 nbglabels;
+ lbl_t lbl_bg = labeling::background(input_bw, c8(), nbglabels);
+
+ // Should be always true...
+ value::label_16 bg = lbl_bg(point2d(0,0));
+ // ... but not as robust as the line below.
+// value::label_16 bg = labeling::n_max(lbl_bg, nbglabels, 2)[1];
+
+ logical::not_inplace(input_bw);
+
+ for (unsigned i = 1; i <= lbl.nlabels(); ++i)
+ {
+ io::pbm::save(input_bw | lbl.bbox(i), debug::filename(".pbm", i));
+ mln_VAR(tmp_bw, input_bw | lbl.bbox(i));
+ data::fill((tmp_bw | (pw::value(lbl_bg) == pw::cst(bg))).rw(), false);
+
+ mln_VAR(cleaned,
+ scribo::preprocessing::unskew(geom::rotate(tmp_bw, atoi(argv[4]))));
+
+ double angle = cleaned.second();
+
+// io::pbm::save(cleaned.first(), debug::filename("object.pbm"));
+ mln_VAR(cell, input | lbl.bbox(i));
+ data::fill((cell | (pw::value(lbl_bg) == pw::cst(bg))).rw(),
+ mln_max(value::int_u8));
+ io::pgm::save(geom::rotate(cell, angle + atoi(argv[4]),
+ mln_max(value::int_u8)),
+ debug::filename(".pgm", i));
+ }
+
+}
diff --git a/milena/sandbox/lazzara/afp/micro_films/keep_background.cc b/milena/sandbox/lazzara/afp/micro_films/keep_background.cc
new file mode 100644
index 0000000..78373ad
--- /dev/null
+++ b/milena/sandbox/lazzara/afp/micro_films/keep_background.cc
@@ -0,0 +1,85 @@
+// 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.
+
+
+/// \file
+///
+/// Keep the background from a binary image.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/pw/all.hh>
+#include <mln/core/image/dmorph/image_if.hh>
+
+#include <mln/data/fill.hh>
+#include <mln/io/pbm/all.hh>
+#include <mln/labeling/blobs.hh>
+
+#include <mln/logical/not.hh>
+
+#include <mln/value/label_16.hh>
+
+#include <tools/usage.hh>
+
+
+const char *args_desc[][2] =
+{
+ { "input.pbm", "A binary image. Objects are set to 'true'." },
+ { 0, 0 }
+};
+
+
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+
+ if (argc != 3)
+ return tools::usage(argv,
+ "Extract the background from a binary image.",
+ "input.pbm output.pbm",
+ args_desc, "A binary image. Background is set to 'false'.");
+
+ image2d<bool> input;
+ io::pbm::load(input, argv[1]);
+
+ logical::not_inplace(input);
+
+ typedef value::label_16 V;
+ V nlabels;
+ image2d<V> lbl = labeling::blobs(input, c8(), nlabels);
+
+ image2d<bool> output;
+ initialize(output, input);
+
+ V bg_lbl = lbl(literal::origin);
+
+ data::fill(output, false);
+ data::fill((output | (pw::value(lbl) == pw::cst(bg_lbl))).rw(), true);
+
+ io::pbm::save(output, argv[2]);
+}
+
diff --git a/milena/sandbox/lazzara/afp/micro_films/split_image.cc b/milena/sandbox/lazzara/afp/micro_films/split_image.cc
new file mode 100644
index 0000000..b0c71c7
--- /dev/null
+++ b/milena/sandbox/lazzara/afp/micro_films/split_image.cc
@@ -0,0 +1,80 @@
+// 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.
+
+
+/// \file
+///
+/// Split an image into several smaller image based on the objects.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/imorph/labeled_image.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/data/fill.hh>
+#include <mln/debug/filename.hh>
+#include <mln/io/pbm/all.hh>
+#include <mln/io/pgm/all.hh>
+#include <mln/labeling/blobs.hh>
+#include <mln/value/int_u8.hh>
+
+#include <tools/usage.hh>
+
+
+const char *args_desc[][2] =
+{
+ { "input.pgm", "A gray level image." },
+ { "mask.pbm", "A binary image. Objects are set to 'true'. Will be used to split input.pbm into several images." },
+ { 0, 0 }
+};
+
+
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+
+ if (argc != 3)
+ return tools::usage(argv,
+ "Extract an image for each object in the input image.",
+ "input.pgm mask.pbm",
+ args_desc, "Gray level images extracted from the input.");
+
+ image2d<value::int_u8> input;
+ io::pgm::load(input, argv[1]);
+
+ image2d<bool> mask;
+ io::pbm::load(mask, argv[2]);
+
+ value::int_u8 nlabels;
+ typedef image2d<value::int_u8> lbl_t;
+ lbl_t lbl_ = labeling::blobs(mask, c8(), nlabels);
+ labeled_image<lbl_t> lbl(lbl_, nlabels);
+
+ debug::internal::filename_prefix = "split";
+
+ for (unsigned i = 1; i < lbl.nlabels(); ++i)
+ io::pgm::save(input | lbl.bbox(i), debug::filename("object.pgm"));
+
+}
--
1.5.6.5
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-07-01 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Retrieval of components whose maximize mean color difference.
* edwin/exec/color_distance.hh: Some routines about color distances.
* edwin/exec/max_delta_colormean_obj.cc: Main file for
components retrieval with respect to their mean color difference.
* edwin/mln/morpho/tree/components.hh: Minor fixes.
---
exec/color_distance.hh | 80 +++++++++++++++++
exec/max_delta_colormean_obj.cc | 179 ++++++++++++++++++++++++++++++++++++++++
mln/morpho/tree/components.hh | 15 ++-
3 files changed, 268 insertions(+), 6 deletions(-)
Index: trunk/milena/sandbox/edwin/exec/color_distance.hh
===================================================================
--- trunk/milena/sandbox/edwin/exec/color_distance.hh (revision 0)
+++ trunk/milena/sandbox/edwin/exec/color_distance.hh (revision 4225)
@@ -0,0 +1,80 @@
+//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.
+
+// From theo's sandbox ~theo/color/filter_meandist_rgb_pixels.cc
+
+
+#ifndef COLOR_DISTANCE_HH
+# define COLOR_DISTANCE_HH
+
+#include <mln/value/rgb8.hh>
+#include <mln/math/diff_abs.hh>
+
+namespace mln
+{
+
+ value::int_u8 dist_mean(const value::rgb8& c1, const value::rgb8& c2)
+ {
+ unsigned d = 0;
+ d += (math::diff_abs(c1.red(), c2.red()) + 2) / 3;
+ d += (math::diff_abs(c1.green(), c2.green()) + 2) / 3;
+ d += (math::diff_abs(c1.blue(), c2.blue()) + 2) / 3;
+ if (d > 255)
+ d = 255;
+ return d;
+ }
+
+ value::int_u8 dist_sat(const value::rgb8& c1, const value::rgb8& c2)
+ {
+ unsigned d = 0;
+ d += math::diff_abs(c1.red(), c2.red());
+ d += math::diff_abs(c1.green(), c2.green());
+ d += math::diff_abs(c1.blue(), c2.blue());
+ if (d > 255)
+ d = 255;
+ return d;
+ }
+
+ value::int_u8 dist_max(const value::rgb8& c1, const value::rgb8& c2)
+ {
+ unsigned d = 0, d_;
+ d_ = math::diff_abs(c1.red(), c2.red());
+ if (d_ > d) d = d_;
+ d_ = math::diff_abs(c1.green(), c2.green());
+ if (d_ > d) d = d_;
+ d_ = math::diff_abs(c1.blue(), c2.blue());
+ if (d_ > d) d = d_;
+ return d;
+ }
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln.
+
+#endif // ! COLOR_DISTANCE_HH
Index: trunk/milena/sandbox/edwin/exec/max_delta_colormean_obj.cc
===================================================================
--- trunk/milena/sandbox/edwin/exec/max_delta_colormean_obj.cc (revision 0)
+++ trunk/milena/sandbox/edwin/exec/max_delta_colormean_obj.cc (revision 4225)
@@ -0,0 +1,179 @@
+//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.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/rgb8.hh>
+
+#include <mln/morpho/tree/data.hh>
+#include <mln/morpho/tree/compute_attribute_image.hh>
+#include <mln/morpho/tree/components.hh>
+#include <mln/morpho/tree/propagate.hh>
+
+#include <mln/accu/stat/mean.hh>
+
+#include <mln/data/sort_psites.hh>
+#include <mln/data/convert.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/ppm/load.hh>
+#include <mln/io/pbm/save.hh>
+
+
+#include "color_distance.hh"
+#include <iostream>
+#include <cstring>
+
+using namespace mln;
+using value::int_u8;
+
+
+void usage(char** argv)
+{
+ std::cout << "Usage: " << argv[0] << " in:input.pgm in:source(.pgm|.ppm) [out:attribute.pbm]"
+ << std::endl
+ << "Compute the mean attribute image from 'source' values using 'input'"
+ " min tree structure. Then, compute the delta image d (parent(n) - n) and retrieve"
+ " components that maximizes the delta. The retrieved components are stored through a mask"
+ " where objects are set to 1 and background to 0 in 'attribute.pbm'."
+ << std::endl;
+
+ abort();
+}
+
+const char* get_extension(const char* filename)
+{
+ return (filename + strlen(filename) - 3);
+}
+
+
+template <typename T, typename S>
+inline
+mln_ch_value(typename T::function, int_u8)
+compute_delta_mean(const value::int_u8&, const T& tree, const Image<S>& source)
+{
+
+ typedef mln_ch_value(typename T::function, mln_sum(mln_value(S))) O;
+ O out = morpho::tree::compute_attribute_image_from(accu::stat::mean<mln_value(S)>(),
+ tree, source);
+
+ // Compute delta image.
+ mln_ch_value(typename T::function, int_u8) dist;
+ initialize(dist, tree.f());
+
+ mln_up_node_piter(T) n(tree);
+ for_all(n)
+ dist(n) = out(tree.parent(n)) - out(n);
+
+ return dist;
+}
+
+template <typename T, typename S>
+inline
+mln_ch_value(typename T::function, int_u8)
+compute_delta_mean(const value::rgb8&, const T& tree, const Image<S>& source)
+{
+
+ typedef mln_ch_value(typename T::function, mln_sum(mln_value(S))) O;
+ O out = morpho::tree::compute_attribute_image_from(accu::stat::mean<mln_value(S)>(),
+ tree, source);
+
+ // Compute delta image.
+ mln_ch_value(typename T::function, int_u8) dist;
+ initialize(dist, tree.f());
+
+ mln_up_node_piter(T) n(tree);
+ for_all(n)
+ {
+ // Fixme: rewrite distance routines with vector instead of convert ?
+ dist(n) = dist_mean(convert::to<value::rgb8>(out(tree.parent(n))), convert::to<value::rgb8>(out(n)));
+ }
+
+ return dist;
+}
+
+template <typename T, typename S>
+inline
+mln_ch_value(typename T::function, int_u8)
+compute_delta_mean(const T& tree, const Image<S>& source)
+{
+ return compute_delta_mean(mln_value(S) (), tree, source);
+}
+
+
+
+int main(int argc, char** argv)
+{
+
+
+ if (argc < 3)
+ usage(argv);
+
+ const char* finput = argv[1];
+ const char* fsource = argv[2];
+ const char* foutput = argc > 3 ? argv[3] : "mask.pbm";
+
+ // Image loadin'.
+ typedef image2d<value::int_u8> I;
+ I input;
+ io::pgm::load(input, finput);
+
+
+ // Tree construction.
+ typedef p_array<mln_psite_(I)> S;
+ typedef morpho::tree::data<I, S> T;
+
+ S s = data::sort_psites_increasing(input);
+ T tree(input, s, c4());
+
+ // Attribute computation.
+ mln_ch_value_(I, int_u8) delta;
+
+ const char* extension = get_extension(fsource);
+ if (strcmp(extension, "pgm") == 0)
+ {
+ image2d<value::int_u8> src;
+ io::pgm::load(src, fsource);
+ delta = compute_delta_mean(tree, src);
+ }
+ else if (strcmp(extension, "ppm") == 0)
+ {
+ image2d<value::rgb8> src;
+ io::ppm::load(src, fsource);
+ delta = compute_delta_mean(tree, src);
+ }
+ else
+ usage(argv); // Type not handled.
+
+ // Get the max components of the delta image.
+ p_array<mln_psite_(I)> obj = morpho::tree::get_components(tree, delta);
+
+ typedef mln_ch_value_(I, bool) O;
+ O out = morpho::tree::set_value_to_components(tree, obj, true, false);
+
+ io::pbm::save(out, foutput);
+}
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/components.hh
===================================================================
--- trunk/milena/sandbox/edwin/mln/morpho/tree/components.hh (revision 4224)
+++ trunk/milena/sandbox/edwin/mln/morpho/tree/components.hh (revision 4225)
@@ -49,7 +49,9 @@
namespace mln {
+
namespace morpho {
+
namespace tree {
/**
@@ -237,7 +239,6 @@
p = max_arr[arr_pos];
if (a(p) == 0)
break;
- std::cout << p << " " << a(p) << std::endl;
components.insert(p);
morpho::tree::propagate_node_to_descendants(p, tree, activity, false, nb_leaves);
morpho::tree::propagate_node_to_ancestors(p, tree, activity, false);
@@ -262,7 +263,7 @@
trace::entering("mln::morpho::tree::get_components");
const A& a = exact(attr_image);
- mln_precondition(tree.f().domain() == a.domain());
+ mln_precondition(tree.f().domain() == a.domain()); // May be to strong.
mln_precondition(a.is_valid());
p_array< mln_psite(A) > components =
@@ -280,7 +281,7 @@
trace::entering("mln::morpho::tree::get_components");
const A& a = exact(attr_image);
- mln_precondition(tree.f().domain() == a.domain());
+ mln_precondition(tree.f().domain() == a.domain()); // May be to strong.
mln_precondition(a.is_valid());
p_array< mln_psite(A) > components;
@@ -300,7 +301,7 @@
const A& a = exact(attr_image);
const P2B& predicate = exact(pred);
- mln_precondition(tree.f().domain() == a.domain());
+ mln_precondition(tree.f().domain() == a.domain()); // May be to strong.
mln_precondition(a.is_valid());
p_array< mln_psite(A) > components =
@@ -310,10 +311,12 @@
return components;
}
+# endif /* !MLN_INCLUDE_ONLY */
+
} // end of namespace mln::morpho::tree
+
} // end of namespace mln::morpho
-} // end of namespace mln
-# endif /* !MLN_INCLUDE_ONLY */
+} // end of namespace mln
#endif /* !MLN_MORPHO_TREE_COMPONENTS_HH_ */