URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-01-14 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Begin a process to extract arrays.
* sandbox/garrigues/factures/array_global.cc: New.
* sandbox/garrigues/factures/facture.pgm: An receipt image.
* sandbox/garrigues/factures: New.
---
array_global.cc | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)
Index: trunk/milena/sandbox/garrigues/factures/array_global.cc
===================================================================
--- trunk/milena/sandbox/garrigues/factures/array_global.cc (revision 0)
+++ trunk/milena/sandbox/garrigues/factures/array_global.cc (revision 1661)
@@ -0,0 +1,101 @@
+// 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.
+
+#include <mln/core/image2d.hh>
+#include <mln/io/pgm/all.hh>
+#include <mln/io/pbm/all.hh>
+#include <mln/geom/resize.hh>
+#include <mln/display/all.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/morpho/closing.hh>
+#include <mln/win/rectangle2d.hh>
+
+#include <mln/pw/all.hh>
+#include <mln/core/inplace.hh>
+#include <mln/level/stretch.hh>
+#include <mln/labeling/level.hh>
+#include <mln/core/neighb2d.hh>
+
+#include <mln/accu/all.hh>
+
+int main()
+{
+ using namespace mln;
+ using namespace mln;
+
+ typedef image2d<bool> ima2d_bool;
+ typedef image2d<unsigned> ima2d_unsigned;
+
+ image2d<value::int_u8> in;
+
+ io::pgm::load(in , "facture.pgm");
+
+ // Resize 50%.
+ image2d<value::int_u8> small = in; //geom::resize(in, 0.5);
+
+ // Binarisation.
+ ima2d_bool bin(small.domain());
+ level::paste(inplace(pw::value(small) > pw::cst(50) | small.domain()), bin);
+
+ // Labeling.
+ unsigned nlabels;
+ image2d<unsigned> labels = labeling::level(bin, true, c4(), nlabels);
+
+ // Get the caracteristics of the connected components.
+ std::vector< accu::pair_< accu::bbox<point2d>, accu::count_<point2d> > > caracteristics(nlabels);
+ mln_fwd_piter_(ima2d_unsigned) p(labels.domain());
+ for_all(p)
+ caracteristics[labels(p)].take(p);
+
+ // Filter the connected components.
+ std::vector<bool> is_array(nlabels);
+ for (int i = 0; i < nlabels; i++)
+ {
+ box_<point2d> b = caracteristics[i].to_result().first;
+ unsigned n = caracteristics[i].to_result().second;
+ float ratio;
+ if (b.pmax() == b.pmin() || n < 10)
+ {
+ is_array[i] = false;
+ continue;
+ }
+
+ if (0 != (b.pmax()[1] - b.pmin()[1]))
+ ratio = float(b.pmax()[0] - b.pmin()[0]) / (b.pmax()[1] - b.pmin()[1]);
+ else
+ ratio = float(b.pmax()[1] - b.pmin()[1]) / (b.pmax()[0] - b.pmin()[0]);
+
+ int area = (b.pmax()[0] - b.pmin()[0]) * (b.pmax()[1] - b.pmin()[1]);
+ is_array[i] = ratio < 0.1 || ratio > 10 || (float(n) / area) < 0.2;
+ }
+
+ // Clean the image.
+ for_all(p)
+ bin(p) = is_array[labels(p)];
+
+ io::pbm::save(bin, "array.pbm");
+}
Index: trunk/milena/sandbox/garrigues/factures/facture.pgm
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: trunk/milena/sandbox/garrigues/factures/facture.pgm
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-01-17 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Highlight hlives and vlines in extract_array.
* sandbox/garrigues/factures/extract_array_highlight.cc: New.
Highlight hlives and vlines in extract_array.
* sandbox/garrigues/factures/array_global.cc: Rename as...
* sandbox/garrigues/factures/extract_array.cc: this.
* mln/geom/resize.hh: Use mln_sum type.
---
mln/geom/resize.hh | 2
sandbox/garrigues/factures/extract_array.cc | 114 ++++++++++++
sandbox/garrigues/factures/extract_array_highlight.cc | 160 ++++++++++++++++++
3 files changed, 275 insertions(+), 1 deletion(-)
Index: trunk/milena/mln/geom/resize.hh
===================================================================
--- trunk/milena/mln/geom/resize.hh (revision 1668)
+++ trunk/milena/mln/geom/resize.hh (revision 1669)
@@ -101,7 +101,7 @@
resize_2d_(const I& input, const float ratio)
{
trace::entering("mln::geom::impl::resize_2d_");
- typedef mln_value(I) V;
+ typedef mln_sum(mln_value(I)) V;
std::size_t rows = input.bbox().len(0);
std::size_t cols = input.bbox().len(1);
Index: trunk/milena/sandbox/garrigues/factures/extract_array_highlight.cc
===================================================================
--- trunk/milena/sandbox/garrigues/factures/extract_array_highlight.cc (revision 0)
+++ trunk/milena/sandbox/garrigues/factures/extract_array_highlight.cc (revision 1669)
@@ -0,0 +1,160 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#include <mln/core/image2d.hh>
+#include <mln/io/pgm/all.hh>
+#include <mln/io/pbm/all.hh>
+#include <mln/geom/resize.hh>
+#include <mln/display/all.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/morpho/opening.hh>
+#include <mln/win/hline2d.hh>
+#include <mln/win/vline2d.hh>
+#include <mln/win/disk2d.hh>
+
+#include <mln/pw/all.hh>
+#include <mln/core/inplace.hh>
+#include <mln/level/stretch.hh>
+#include <mln/level/median.hh>
+#include <mln/morpho/gradient.hh>
+
+#include <mln/labeling/level.hh>
+#include <mln/literal/all.hh>
+
+#include <mln/core/neighb2d.hh>
+
+#include <mln/accu/all.hh>
+
+#include <mln/draw/box.hh>
+
+using namespace mln;
+typedef image2d<bool> ima2d_bool;
+typedef image2d<unsigned> ima2d_unsigned;
+
+image2d<bool>
+filter_arrays(image2d<bool> in)
+{
+ // Labeling.
+ unsigned nlabels;
+ image2d<unsigned> labels = labeling::level(in, true, c4(), nlabels);
+
+ // Get the caracteristics of the connected components.
+ std::vector< accu::pair_< accu::bbox<point2d>, accu::count_<point2d> > > caracteristics(nlabels + 1);
+ mln_fwd_piter_(ima2d_unsigned) p(labels.domain());
+ for_all(p)
+ caracteristics[labels(p)].take(p);
+
+ // Filter each connected components.
+ std::vector<bool> is_array(nlabels);
+ for (int i = 0; i < nlabels; i++)
+ {
+ box_<point2d> b = caracteristics[i].to_result().first;
+ unsigned n = caracteristics[i].to_result().second;
+ float ratio;
+ if (b.pmax() == b.pmin() || n < 10)
+ {
+ is_array[i] = false;
+ continue;
+ }
+
+ if (0 != (b.pmax()[1] - b.pmin()[1]))
+ ratio = float(b.pmax()[0] - b.pmin()[0]) / (b.pmax()[1] - b.pmin()[1]);
+ else
+ ratio = float(b.pmax()[1] - b.pmin()[1]) / (b.pmax()[0] - b.pmin()[0]);
+
+ int area = (b.pmax()[0] - b.pmin()[0]) * (b.pmax()[1] - b.pmin()[1]);
+ is_array[i] = ratio < 0.1 || ratio > 10 || (float(n) / area) < 0.2;
+ }
+
+ // Clean the image.
+ image2d<bool> output(in.domain());
+ for_all(p)
+ output(p) = is_array[labels(p)];
+
+ return output;
+}
+
+image2d<value::rgb8>
+highlight_vlines(image2d<bool> in)
+{
+
+ image2d<bool> tmp;
+ tmp = filter_arrays(in);
+
+ // Opening.
+ tmp = morpho::opening(tmp, win::vline2d(5));
+
+ image2d<value::rgb8> output(tmp.domain());
+ mln_fwd_piter_(ima2d_unsigned) p(tmp.domain());
+ for_all(p)
+ if (tmp(p))
+ output(p) = literal::red;
+ else
+ output(p) = literal::black;
+
+ return output;
+}
+
+
+image2d<value::rgb8>
+highlight_hlines(image2d<bool> in)
+{
+
+ image2d<bool> tmp;
+ tmp = filter_arrays(in);
+ // Opening.
+ tmp = morpho::opening(tmp, win::hline2d(5));
+
+ image2d<value::rgb8> output(tmp.domain());
+ mln_fwd_piter_(ima2d_unsigned) p(tmp.domain());
+ for_all(p)
+ if (tmp(p))
+ output(p) = literal::green;
+ else
+ output(p) = literal::black;
+
+ return output;
+}
+
+
+int main()
+{
+
+ image2d<value::int_u8> in;
+
+ io::pgm::load(in , "facture.pgm");
+
+ // Binarisation.
+ ima2d_bool bin(in.domain());
+ level::paste(inplace(pw::value(in) > pw::cst(50) | in.domain()), bin);
+
+ image2d<value::rgb8> output_h = highlight_hlines(bin);
+ image2d<value::rgb8> output_v = highlight_vlines(bin);
+
+ image2d<value::rgb8> sum = output_v + output_h;
+ io::ppm::save(sum, "array.ppm");
+}
Index: trunk/milena/sandbox/garrigues/factures/extract_array.cc
===================================================================
--- trunk/milena/sandbox/garrigues/factures/extract_array.cc (revision 0)
+++ trunk/milena/sandbox/garrigues/factures/extract_array.cc (revision 1669)
@@ -0,0 +1,114 @@
+// 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.
+
+#include <mln/core/image2d.hh>
+#include <mln/io/pgm/all.hh>
+#include <mln/io/pbm/all.hh>
+#include <mln/geom/resize.hh>
+#include <mln/display/all.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/morpho/closing.hh>
+#include <mln/win/rectangle2d.hh>
+
+#include <mln/pw/all.hh>
+#include <mln/core/inplace.hh>
+#include <mln/level/stretch.hh>
+#include <mln/labeling/level.hh>
+#include <mln/literal/all.hh>
+
+#include <mln/core/neighb2d.hh>
+
+#include <mln/accu/all.hh>
+
+#include <mln/draw/box.hh>
+
+int main()
+{
+ using namespace mln;
+ using namespace mln;
+
+ typedef image2d<bool> ima2d_bool;
+ typedef image2d<unsigned> ima2d_unsigned;
+
+ image2d<value::int_u8> in;
+
+ io::pgm::load(in , "facture.pgm");
+
+ // Resize 50%.
+ image2d<value::int_u8> small = in; //geom::resize(in, 0.5);
+
+ // Binarisation.
+ ima2d_bool bin(small.domain());
+ level::paste(inplace(pw::value(small) > pw::cst(50) | small.domain()), bin);
+
+ // Labeling.
+ unsigned nlabels;
+ image2d<unsigned> labels = labeling::level(bin, true, c4(), nlabels);
+
+ // Get the caracteristics of the connected components.
+ std::vector< accu::pair_< accu::bbox<point2d>, accu::count_<point2d> > > caracteristics(nlabels);
+ mln_fwd_piter_(ima2d_unsigned) p(labels.domain());
+ for_all(p)
+ caracteristics[labels(p)].take(p);
+
+ // Filter each connected components.
+ std::vector<bool> is_array(nlabels);
+ for (int i = 0; i < nlabels; i++)
+ {
+ box_<point2d> b = caracteristics[i].to_result().first;
+ unsigned n = caracteristics[i].to_result().second;
+ float ratio;
+ if (b.pmax() == b.pmin() || n < 10)
+ {
+ is_array[i] = false;
+ continue;
+ }
+
+ if (0 != (b.pmax()[1] - b.pmin()[1]))
+ ratio = float(b.pmax()[0] - b.pmin()[0]) / (b.pmax()[1] - b.pmin()[1]);
+ else
+ ratio = float(b.pmax()[1] - b.pmin()[1]) / (b.pmax()[0] - b.pmin()[0]);
+
+ int area = (b.pmax()[0] - b.pmin()[0]) * (b.pmax()[1] - b.pmin()[1]);
+ is_array[i] = ratio < 0.14 || ratio > 7 || (float(n) / area) < 0.2;
+ }
+
+ // Clean the image.
+ image2d<value::rgb8> output(small.domain());
+ for_all(p)
+ if (is_array[labels(p)])
+ output(p) = literal::white;
+ else
+ output(p) = literal::black;
+
+ // Draw the bounding boxes.
+ for (int i = 0; i < nlabels; i++)
+ if (is_array[i])
+ draw::box(output, inplace(caracteristics[i].to_result().first), inplace(value::rgb8(literal::green)));
+
+ io::ppm::save(output, "array.ppm");
+}
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-01-15 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add processing pipeline for recognize scores.
* sandbox/nivault/extract_score.cc: New.
---
extract_score.cc | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 148 insertions(+)
Index: trunk/milena/sandbox/nivault/extract_score.cc
===================================================================
--- trunk/milena/sandbox/nivault/extract_score.cc (revision 0)
+++ trunk/milena/sandbox/nivault/extract_score.cc (revision 1666)
@@ -0,0 +1,148 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+# include <vector>
+
+# include <mln/core/image2d.hh>
+# include <mln/io/pgm/save.hh>
+# include <mln/io/pgm/load.hh>
+# include <mln/io/pbm/save.hh>
+# include <mln/io/ppm/save.hh>
+# include <mln/debug/println.hh>
+# include <mln/logical/not.hh>
+# include <mln/logical/or.hh>
+# include <mln/io/pbm/save.hh>
+
+# include <mln/morpho/erosion.hh>
+# include <mln/morpho/dilation.hh>
+# include <mln/morpho/complementation.hh>
+# include <mln/morpho/closing.hh>
+# include <mln/morpho/opening.hh>
+# include <mln/make/w_window2d.hh>
+# include <mln/win/rectangle2d.hh>
+# include <mln/win/vline2d.hh>
+# include <mln/win/hline2d.hh>
+# include <mln/win/disk2d.hh>
+# include <mln/level/fill.hh>
+# include <mln/labeling/blobs.hh>
+# include <mln/core/neighb2d.hh>
+
+# include <mln/accu/mean.hh>
+# include <mln/accu/bbox.hh>
+# include <mln/accu/p.hh>
+# include <mln/accu/count.hh>
+
+# include <mln/value/scalar.hh>
+# include <mln/make/voronoi.hh>
+# include <mln/geom/seeds2tiling.hh>
+# include <mln/core/mesh_p.hh>
+# include <mln/draw/mesh.hh>
+
+# include <mln/level/stretch.hh>
+
+# include <mln/core/image_if_value.hh>
+# include <mln/core/sub_image.hh>
+# include <mln/level/paste.hh>
+# include <mln/literal/all.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/morpho/opening_area.hh>
+
+using namespace mln;
+
+using value::int_u8;
+using value::rgb8;
+
+typedef point2d P;
+typedef image2d<bool> IB;
+typedef image2d<int_u8> IU;
+typedef image2d<value::rgb8> O;
+
+template <typename I>
+void
+draw_bbox(I& image, box2d box, value::rgb8 val)
+{
+ point2d pmin = box.pmin();
+ point2d pmax = box.pmax();
+
+ point2d p1 (pmin[0], pmin[1]);
+ point2d p2 (pmax[0], pmin[1]);
+ point2d p3 (pmin[0], pmax[1]);
+ point2d p4 (pmax[0], pmax[1]);
+
+ draw::line (image, p1, p2, val);
+ draw::line (image, p2, p4, val);
+ draw::line (image, p4, p3, val);
+ draw::line (image, p3, p1, val);
+}
+
+IB to_binary(IU in, mln_value_(IU) val)
+{
+// Divise L'image en deux :
+// box2d gb = score_u.domain();
+// box2d sb(gb.nrows() / 2, gb.ncols() / 2);
+
+// image2d< accu::mean_<int_u8> > ima_mean(sb);
+
+// {
+// mln_piter_(IU) p(gb);
+
+// for_all(p)
+// ima_mean(point2d(p[0] / 2, p[1] / 2)).take(score_u(p));
+// }
+
+ IB score_b(in.domain());
+
+ {
+ mln_piter_(IU) p(in.domain());
+
+ for_all(p)
+ score_b(p) = in(p) < val;
+// score_b(p) = ima_mean(p).to_result() < 175;
+ }
+ return score_b;
+}
+
+int
+main(int argc, char** argv)
+{
+
+ if (argc != 3)
+ {
+ std::cerr << "Usage : " << argv[0]
+ << " input.pgm output.pbm" << std::endl;
+ exit(1);
+ }
+
+ IU score_u;
+
+ io::pgm::load(score_u, argv[1]);
+
+ IB score_b = to_binary(score_u, 175);
+
+ io::pbm::save(score_b, argv[2]);
+}
+