3840: Add routines for primitive extraction.

* scribo/extract/primitive/canvas.hh, * scribo/extract/primitive/cells.hh, * scribo/extract/primitive/lines_discontinued.hh, * scribo/extract/primitive/lines_h_discontinued.hh, * scribo/extract/primitive/lines_thick.hh, * scribo/extract/primitive/lines_v_discontinued.hh, * scribo/extract/primitive/objects.hh: new routines. --- milena/sandbox/ChangeLog | 12 ++ milena/sandbox/scribo/extract/primitive/canvas.hh | 132 ++++++++++++++ milena/sandbox/scribo/extract/primitive/cells.hh | 121 ++++++++++++ .../scribo/extract/primitive/lines_discontinued.hh | 192 ++++++++++++++++++++ .../extract/primitive/lines_h_discontinued.hh | 160 ++++++++++++++++ .../scribo/extract/primitive/lines_thick.hh | 178 ++++++++++++++++++ .../extract/primitive/lines_v_discontinued.hh | 161 ++++++++++++++++ milena/sandbox/scribo/extract/primitive/objects.hh | 158 ++++++++++++++++ 8 files changed, 1114 insertions(+), 0 deletions(-) create mode 100644 milena/sandbox/scribo/extract/primitive/canvas.hh create mode 100644 milena/sandbox/scribo/extract/primitive/cells.hh create mode 100644 milena/sandbox/scribo/extract/primitive/lines_discontinued.hh create mode 100644 milena/sandbox/scribo/extract/primitive/lines_h_discontinued.hh create mode 100644 milena/sandbox/scribo/extract/primitive/lines_thick.hh create mode 100644 milena/sandbox/scribo/extract/primitive/lines_v_discontinued.hh create mode 100644 milena/sandbox/scribo/extract/primitive/objects.hh diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog index 17196d9..058d82f 100644 --- a/milena/sandbox/ChangeLog +++ b/milena/sandbox/ChangeLog @@ -1,3 +1,15 @@ +2009-05-15 Guillaume Lazzara <lazzara@lrde.epita.fr> + + Add routines for primitive extraction. + + * scribo/extract/primitive/canvas.hh, + * scribo/extract/primitive/cells.hh, + * scribo/extract/primitive/lines_discontinued.hh, + * scribo/extract/primitive/lines_h_discontinued.hh, + * scribo/extract/primitive/lines_thick.hh, + * scribo/extract/primitive/lines_v_discontinued.hh, + * scribo/extract/primitive/objects.hh: new routines. + 2009-05-15 Edwin Carlinet <carlinet@lrde.epita.fr> Move inim project to sandbox/inim. diff --git a/milena/sandbox/scribo/extract/primitive/canvas.hh b/milena/sandbox/scribo/extract/primitive/canvas.hh new file mode 100644 index 0000000..07387d9 --- /dev/null +++ b/milena/sandbox/scribo/extract/primitive/canvas.hh @@ -0,0 +1,132 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// 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 SCRIBO_EXTRACT_PRIMITIVE_CANVAS_HH +# define SCRIBO_EXTRACT_PRIMITIVE_CANVAS_HH + +/// \file scribo/primitive/canvas.hh +/// +/// Rebuild a table from its line bounding boxes. + +# include <mln/core/concept/image.hh> +# include <mln/labeling/background.hh> +# include <mln/util/array.hh> +# include <mln/util/couple.hh> +# include <mln/value/label_8.hh> + +# include <scribo/table/align_lines_verticaly.hh> +# include <scribo/table/align_lines_horizontaly.hh> +# include <scribo/table/connect_vertical_lines.hh> +# include <scribo/table/connect_horizontal_lines.hh> +# include <scribo/table/repair_horizontal_lines.hh> +# include <scribo/table/repair_vertical_lines.hh> + +# include <scribo/debug/save_table_image.hh> + + + +namespace scribo +{ + + namespace extract + { + + namespace primitive + { + + + /// Rebuild a table from its line bounding boxes. + /*! + ** \param[in] input_ A binary image. + ** \param[in] hlines_ Vorizontal line bounding boxes. + ** \param[in] vlines_ vertical line bounding boxes. + ** \param[in] max_dist_lines The maximum distance allowed between + ** vertical and horizontal lines to connect + ** them eachother. + ** + ** \return The canvas as a binary image. canvas lines are set to true. + */ + template <typename I, typename V> + mln_ch_value(I,bool) + canvas(const Image<I>& input_, + const util::array<box<mln_site(I)> >& hlines_, + const util::array<box<mln_site(I)> >& vlines_, + unsigned max_dist_lines); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename I, typename V> + mln_ch_value(I,bool) + canvas(const Image<I>& input_, + const util::array<box<mln_site(I)> >& hlines, + const util::array<box<mln_site(I)> >& vlines, + unsigned max_dist_lines); + { + trace::entering("scribo::primitive::canvas"); + const I& input = exact(input_); + + mlc_equal(mln_value(I), bool)::check(); + mln_precondition(input.is_valid()); + + typedef util::array<box<mln_site(I)> > lines_t; + util::couple<lines_t, lines_t> lines = make::couple(hlines, vlines); + + util::array<int> rows = align_lines_horizontaly(input, hlines, 5); + util::array<int> cols = align_lines_verticaly(input, vlines, 5); + + repair_vertical_lines(input, lines, 30); + repair_horizontal_lines(input, lines, 30); + + // Connect vertical lines with horizontal lines. + connect_vertical_lines(rows, lines, input, max_dist_lines); + connect_horizontal_lines(cols, lines, input, max_dist_lines); + + mln_ch_value(I,bool) res; + initialize(res, input); + data::fill(res, false); + for_all_elements(i, lines.first()) + mln::draw::box(res, lines.first()[i], true); + for_all_elements(i, lines.second()) + mln::draw::box(res, lines.second()[i], true); + + trace::exiting("scribo::primitive::canvas"); + return res; + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace scribo::extract::primitive + + } // end of namespace scribo::extract + +} // end of namespace scribo + +#endif // ! SCRIBO_EXTRACT_PRIMITIVE_CANVAS_HH diff --git a/milena/sandbox/scribo/extract/primitive/cells.hh b/milena/sandbox/scribo/extract/primitive/cells.hh new file mode 100644 index 0000000..91d9c59 --- /dev/null +++ b/milena/sandbox/scribo/extract/primitive/cells.hh @@ -0,0 +1,121 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// 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 SCRIBO_EXTRACT_PRIMITIVE_CELLS_HH +# define SCRIBO_EXTRACT_PRIMITIVE_CELLS_HH + +/// \file scribo/primitive/cells.hh +/// +/// Extract canvas cells from a binary image. + +# include <mln/core/concept/image.hh> + +# include <mln/accu/bbox.hh> + +# include <mln/util/couple.hh> +# include <mln/util/array.hh> + +# include <mln/labeling/compute.hh> + +# include <scribo/table/rebuild.hh> +# include <scribo/table/erase.hh> + +# include <scribo/primitive/discontinued_lines.hh> + +# include <scribo/make/debug_filename.hh> + + +namespace scribo +{ + + namespace extract + { + + namespace primitive + { + + /// Extract canvas cells from a binary image. + /// Use arbitrary criterions. + /* + ** \param[in] input_ A binary image. + ** \param[in,out] ncells Will store the number of cells found. + ** + ** \return A list of cell bounding boxes. + */ + template <typename I, typename V> + util::couple<util::array<box<mln_site(I)> > + cells(const Image<I>& input_, + const Neighborhood<N>& nbh_, const V& label_type); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename N, typename V> + inline + util::couple<util::array<box<mln_site(I)> > + cells(const Image<I>& input_, + const Neighborhood<N>& nbh_, const V& label_type) + { + trace::entering("scribo::primitive::cells"); + + const I& input = exact(input_); + const N& nbh = exact(nbh_); + mln_precondition(input.is_valid()); + mln_precondition(nbh.is_valid()); + mlc_equal(mln_value(I), bool)::check(); + + typedef util::array< box<mln_site(I)> > boxarray_t; + + V ncells; + win::line<mln_grid(I::site), 0, mln_coord(I::site)> vline(51); + win::line<mln_grid(I::site), 1, mln_coord(I::site)> hline(51); + boxarray_t + vlines = primitive::discontinued_lines(input, nbh, ncells, vline, 6), + hlines = primitive::discontinued_lines(input, nbh, ncells, hline, 6); + + typedef mln_ch_value(I,V) cells_ima_t; + + cells_ima_t + cells = scribo::table::rebuild(input, make::couple(vlines,hlines), + 30, ncells).first(); + util::array<box<mln_site(I)> > + cellbboxes = labeling::compute(accu::meta::bbox(), cells, ncells); + + trace::exiting("scribo::primitive::cells"); + return cellbboxes; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace scribo::extract::primitive + + } // end of namespace scribo::extract + +} // end of namespace scribo + +#endif // ! SCRIBO_EXTRACT_PRIMITIVE_CELLS_HH diff --git a/milena/sandbox/scribo/extract/primitive/lines_discontinued.hh b/milena/sandbox/scribo/extract/primitive/lines_discontinued.hh new file mode 100644 index 0000000..5730fcc --- /dev/null +++ b/milena/sandbox/scribo/extract/primitive/lines_discontinued.hh @@ -0,0 +1,192 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// 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 SCRIBO_EXTRACT_PRIMITIVE_LINES_DISCONTINUED_HH +# define SCRIBO_EXTRACT_PRIMITIVE_LINES_DISCONTINUED_HH + +/// \file scribo/primitive/lines/discontinued.hh +/// +/// Extract discontinued lines in a binary image. + + +# include <mln/core/concept/image.hh> +# include <mln/core/concept/window.hh> +# include <mln/core/concept/neighborhood.hh> +# include <mln/core/site_set/box.hh> + +# include <mln/labeling/blobs.hh> + +# include <mln/morpho/rank_filter.hh> + +# include <mln/accu/bbox.hh> + +# include <mln/util/array.hh> +# include <mln/util/couple.hh> + +# include <scribo/core/macros.hh> +# include <scribo/core/component_bboxes.hh> + +namespace scribo +{ + + namespace extract + { + + namespace primitive + { + + using namespace mln; + + + /// Extract discontinued lines in a binary image. + /*! + * Based on a rank filter. + * + * \param[in] input_ A binary image. + * \param[in] nbh_ The neighborhood used for labeling image + * components. + * \param[in,out] nlines The label type used for labeling. + * \param[in] win_ A Window used to extract lines. + * \param[in] rank_k Rank used for filtering. + * \param[in,out] line_bboxes line bounding boxes. + * + * \return An image in which lines are labeled. + */ + template <typename I, typename N, typename V, typename W> + mln_ch_value(I,V) + discontinued(const Image<I>& input_, + const Neighborhood<N>& nbh_, V& nlines, + const Window<W>& win_, unsigned rank_k, + util::array<box<mln_site(I)> >& line_bboxes); + + + /// \overload + template <typename I, typename N, typename V, typename W> + mln_ch_value(I,V) + discontinued(const Image<I>& input_, + const Neighborhood<N>& nbh_, V& nlines, + const Window<W>& win_, unsigned rank_k); + + + + +# ifndef MLN_INCLUDE_ONLY + + + namespace internal + { + + template <typename I, typename N, typename V, typename W> + void + discontinued_tests(const Image<I>& input_, + const Neighborhood<N>& nbh_, V& nlines, + const Window<W>& win_, unsigned rank_k) + { + mlc_equal(mln_value(I),bool)::check(); + mlc_equal(mln_site(I)::dim, 2)::check(); + mlc_is_a(V, mln::value::Symbolic)::check(); + + mln_precondition(exact(input).is_valid()); + mln_precondition(exact(nbh).is_valid()); + mln_precondition(exact(win).is_valid()); + + (void) nlines; + (void) rank_k; + } + + } // end of namespace scribo::primitive::internal + + + + template <typename I, typename N, typename V, typename W> + inline + mln_ch_value(I,V) + discontinued(const Image<I>& input_, + const Neighborhood<N>& nbh_, V& nlines, + const Window<W>& win_, unsigned rank_k) + { + trace::entering("scribo::primitive::discontinued"); + + internal::discontinued_tests(input_, nbh_, nlines, win_, rank_k); + + const I& input = exact(input_); + const N& nbh = exact(nbh_); + const W& win = exact(win_); + + mln_ch_value(I,bool) filter = morpho::rank_filter(input, win, vrank_k); + mln_ch_value(I,V) output = labeling::blobs(filter, nbh, nlines); + + trace::exiting("scribo::primitive::discontinued"); + return output; + } + + + + + template <typename I, typename N, typename V, typename W> + inline + mln_ch_value(I,V) + discontinued(const Image<I>& input_, + const Neighborhood<N>& nbh_, V& nlines, + const Window<W>& win_, unsigned rank_k, + util::array<box<mln_site(I)> >& line_bboxes) + { + trace::entering("scribo::primitive::discontinued"); + + internal::discontinued_tests(input_, nbh_, nlines, win_, rank_k); + + const I& input = exact(input_); + const N& nbh = exact(nbh_); + const W& win = exact(win_); + + mln_ch_value(I,V) + output = discontinued(input, nbh, nlines, win, rank_k); + + line_bboxes = labeling::compute(accu::meta::bbox(), output, nlines); + mln_postcondition(line_bboxes.nelements() == nlines.next()); + // for_all_components(i, line_bboxes) + // { + // line_bboxes[i].enlarge(0, win.length() / 2); + // line_bboxes[i].crop_wrt(input.domain()); + // } + + trace::exiting("scribo::primitive::discontinued"); + return output; + } + +# endif // !MLN_INCLUDE_ONLY + + + } // end of namespace scribo::extract::primitive + + } // end of namespace scribo::extract + +} // end of namespace scribo + +#endif // ! SCRIBO_EXTRACT_PRIMITIVE_LINES_DISCONTINUED_HH diff --git a/milena/sandbox/scribo/extract/primitive/lines_h_discontinued.hh b/milena/sandbox/scribo/extract/primitive/lines_h_discontinued.hh new file mode 100644 index 0000000..7f31bff --- /dev/null +++ b/milena/sandbox/scribo/extract/primitive/lines_h_discontinued.hh @@ -0,0 +1,160 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// 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 SCRIBO_EXTRACT_PRIMITIVE_LINES_H_DISCONTINUED_HH +# define SCRIBO_EXTRACT_PRIMITIVE_LINES_H_DISCONTINUED_HH + +/// \file scribo/primitive/lines_h_discontinued.hh +/// +/// Extract horizontal discontinued lines. + +# include <mln/core/concept/image.hh> +# include <mln/core/concept/neighborhood.hh> +# include <mln/win/hline2d.hh> + +namespace scribo +{ + + namespace extract + { + + namespace primitive + { + + + /// Extract horizontal discontinued lines. + /*! + * \param[in] input A binary image. + * \param[in] nbh A neighborhood used to label lines. + * \param[in,out] nlines The number of lines found. + * \param[in] line_length The minimum line length expected. (must be + * odd). + * \param[in] rank_k Rank filter parameter. + * + * \result An image in which lines are labeled with a value different + * from 0. + */ + template <typename I, typename N, typename V> + mln_ch_value(I,V) + lines_h_discontinued(const Image<I>& input, + const Neighborhood<N>& nbh, V& nlines, + unsigned line_length, unsigned rank_k); + + + /// \overload + template <typename I, typename N, typename V> + mln_ch_value(I,V) + lines_h_discontinued(const Image<I>& input, + const Neighborhood<N>& nbh, V& nlines, + unsigned line_length, unsigned rank_k, + util::array<box<mln_site(I)> >& line_bboxes); + + +# ifndef MLN_INCLUDE_ONLY + + + namespace internal + { + + template <typename I, typename N, typename V, typename W> + void + lines_h_discontinued_tests(const Image<I>& input_, + const Neighborhood<N>& nbh_, V& nlines, + unsigned line_length, unsigned rank_k) + { + mlc_equal(mln_value(I),bool)::check(); + mlc_equal(mln_site(I)::dim, 2)::check(); + mlc_is_a(V, mln::value::Symbolic)::check(); + + mln_precondition(exact(input).is_valid()); + mln_precondition(exact(nbh).is_valid()); + mln_precondition(exact(win).is_valid()); + mln_precondition(!(line_length % 2)); + + (void) nlines; + (void) rank_k; + } + + } // end of namespace scribo::primitive::internal + + + + template <typename I, typename N, typename V> + mln_ch_value(I,V) + lines_h_discontinued(const Image<I>& input, + const Neighborhood<N>& nbh, V& nlines, + unsigned line_length, unsigned rank_k) + { + trace::entering("scribo::primitive::lines_h_discontinued"); + + internal::line_h_discontinued_tests(input, nbh, nlines, + line_length, rank_k); + + win::hline2d win(line_length); + + mln_ch_value(I,V) + output = lines_discontinued(input, nh, nlines, win, rank_k); + + trace::exiting("scribo::primitive::lines_h_discontinued"); + return output; + } + + + + template <typename I, typename N, typename V> + mln_ch_value(I,V) + lines_h_discontinued(const Image<I>& input, + const Neighborhood<N>& nbh, V& nlines, + unsigned line_length, unsigned rank_k, + util::array<box<mln_site(I)> >& line_bboxes) + { + trace::entering("scribo::primitive::lines_h_discontinued"); + + internal::line_h_discontinued_tests(input, nbh, nlines, + line_length, rank_k); + + win::hline2d win(line_length); + mln_ch_value(I,V) + output = internal::line_h_discontinued_tests(input, nbh, nlines, + line_length, rank_k, + line_bboxes); + + trace::exiting("scribo::primitive::lines_h_discontinued"); + return output; + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace scribo::extract::primitive + + } // end of namespace scribo::extract + +} // end of namespace scribo + +#endif // ! SCRIBO_EXTRACT_PRIMITIVE_LINES_H_DISCONTINUED_HH diff --git a/milena/sandbox/scribo/extract/primitive/lines_thick.hh b/milena/sandbox/scribo/extract/primitive/lines_thick.hh new file mode 100644 index 0000000..ea5e8d1 --- /dev/null +++ b/milena/sandbox/scribo/extract/primitive/lines_thick.hh @@ -0,0 +1,178 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// 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 SCRIBO_EXTRACT_PRIMITIVE_LINES_THICK_HH +# define SCRIBO_EXTRACT_PRIMITIVE_LINES_THICK_HH + +/// \file scribo/primitive/lines_thick.hh +/// +/// Extract thick lines in a binary image. + + +# include <mln/core/concept/image.hh> +# include <mln/core/concept/window.hh> +# include <mln/core/concept/neighborhood.hh> +# include <mln/core/site_set/box.hh> + +# include <mln/morpho/erosion.hh> + +# include <mln/accu/bbox.hh> + +# include <mln/util/array.hh> +# include <mln/util/couple.hh> + +# include <scribo/core/macros.hh> +# include <scribo/core/component_bboxes.hh> + +namespace scribo +{ + + namespace extract + { + + namespace primitive + { + + + using namespace mln; + + /// Extract thick lines in a binary image. + /*! + * Only non discontinued lines are correctly extracted with this routine. + * + * \param[in] input_ A binary image. + * \param[in] nbh_ The neighborhood used for labeling image + * components. + * \param[in,out] nlines Type used for labeling. + * \param[in] win_ Window used to extract the lines + * \param[in,out] line_bboxes Line bounding boxes. + * + * \return An image in which lines are labeled. + */ + template <typename I, typename N, typename V, typename W> + mln_ch_value(I,V) + lines_thick(const Image<I>& input_, + const Neighborhood<N>& nbh_, V& nlines, + const Window<W>& win_, + util::array<box<mln_site(I)>& line_bboxes); + + /// \overload + template <typename I, typename N, typename V, typename W> + mln_ch_value(I,V) + lines_thick(const Image<I>& input_, + const Neighborhood<N>& nbh_, V& nlines, + const Window<W>& win_); + + + +# ifndef MLN_INCLUDE_ONLY + + + namespace internal + { + + template <typename I, typename N, typename V, typename W> + void + lines_thick_tests(const Image<I>& input_, + const Neighborhood<N>& nbh_, V& nlines, + const Window<W>& win_) + { + mlc_equal(mln_value(I),bool)::check(); + mlc_equal(mln_site(I)::dim, 2)::check(); + mlc_is_a(V, mln::value::Symbolic)::check(); + + mln_precondition(exact(input).is_valid()); + mln_precondition(exact(nbh).is_valid()); + mln_precondition(exact(win).is_valid()); + + (void) nlines; + } + + } // end of namespace scribo::primitive::internal + + + + template <typename I, typename N, typename V, typename W> + inline + mln_ch_value(I,V) + lines_thick(const Image<I>& input_, + const Neighborhood<N>& nbh_, V& nlines, + const Window<W>& win_) + { + trace::entering("scribo::primitive::lines_thick"); + + internal::lines_thick_tests(input_, nbh_, nlines, win_); + + const I& input = exact(input_); + const N& nbh = exact(nbh_); + const W& win = exact(win_); + + mln_ch_value(I,bool) filter = morpho::opening::structural(input, win); + mln_ch_value(I,V) output = labeling::blobs(filter, nbh, nlines); + + trace::exiting("scribo::primitive::lines_thick"); + return output; + } + + + + template <typename I, typename N, typename V, typename W> + inline + mln_ch_value(I,V) + lines_thick(const Image<I>& input_, + const Neighborhood<N>& nbh_, V& nlines, + const Window<W>& win_, + util::array<box<mln_site(I)>& line_bboxes) + { + trace::entering("scribo::primitive::lines_thick"); + + internal::lines_thick_tests(input_, nbh_, nlines, win_); + + const I& input = exact(input_); + const N& nbh = exact(nbh_); + const W& win = exact(win_); + + mln_ch_value(I,V) output = lines_thick(input, nbh, nlines, win); + + line_bboxes = labeling::compute(accu::meta::bbox(), output, nlines); + mln_postcondition(line_bboxes.nelements() == nlines.next()); + + trace::exiting("scribo::primitive::lines_thick"); + return output; + } + +# endif // !MLN_INCLUDE_ONLY + + } // end of namespace scribo::extract::primitive + + } // end of namespace scribo::extract::primitive + +} // end of namespace scribo + +#endif // ! SCRIBO_EXTRACT_PRIMITIVE_VERTICAL_LINES_THICK_HH diff --git a/milena/sandbox/scribo/extract/primitive/lines_v_discontinued.hh b/milena/sandbox/scribo/extract/primitive/lines_v_discontinued.hh new file mode 100644 index 0000000..26edbb4 --- /dev/null +++ b/milena/sandbox/scribo/extract/primitive/lines_v_discontinued.hh @@ -0,0 +1,161 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// 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 SCRIBO_EXTRACT_PRIMITIVE_LINES_V_DISCONTINUED_HH +# define SCRIBO_EXTRACT_PRIMITIVE_LINES_V_DISCONTINUED_HH + +/// \file scribo/primitive/lines_v_discontinued.hh +/// +/// Extract vertical discontinued lines. + +# include <mln/core/concept/image.hh> +# include <mln/core/concept/neighborhood.hh> + + +namespace scribo +{ + + namespace extract + { + + namespace primitive + { + + + /// Extract vertical discontinued lines. + /*! + * \param[in] input A binary image. + * \param[in] nbh A neighborhood used to label lines. + * \param[in,out] nlines The number of lines found. + * \param[in] line_length The minimum line length expected. (must be + * odd). + * \param[in] rank_k Rank filter parameter. + * \param[in,out] line_bboxes Will store the line bounding boxes. + * + * \result An image in which lines are labeled with a value different + * from 0. + */ + template <typename I, typename N, typename V> + mln_ch_value(I,V) + lines_v_discontinued(const Image<I>& input, + const Neighborhood<N>& nbh, V& nlines, + unsigned line_length, unsigned rank_k, + util::array<box<mln_site(I)> >& line_bboxes); + + /// \overload + template <typename I, typename N, typename V> + mln_ch_value(I,V) + lines_v_discontinued(const Image<I>& input, + const Neighborhood<N>& nbh, V& nlines, + unsigned line_length, unsigned rank_k); + + +# ifndef MLN_INCLUDE_ONLY + + + namespace internal + { + + template <typename I, typename N, typename V, typename W> + void + lines_v_discontinued_tests(const Image<I>& input_, + const Neighborhood<N>& nbh_, V& nlines, + unsigned line_length, unsigned rank_k) + { + mlc_equal(mln_value(I),bool)::check(); + mlc_equal(mln_site(I)::dim, 2)::check(); + mlc_is_a(V, mln::value::Symbolic)::check(); + + mln_precondition(exact(input).is_valid()); + mln_precondition(exact(nbh).is_valid()); + mln_precondition(exact(win).is_valid()); + mln_precondition(!(line_length % 2)); + + (void) nlines; + (void) rank_k; + } + + } // end of namespace scribo::primitive::internal + + + + template <typename I, typename N, typename V> + mln_ch_value(I,V) + lines_v_discontinued(const Image<I>& input, + const Neighborhood<N>& nbh, V& nlines, + unsigned line_length, unsigned rank_k) + { + trace::entering("scribo::primitive::lines_v_discontinued"); + + internal::line_v_discontinued_tests(input, nbh, nlines, + line_length, rank_k); + + win::hline2d win(line_length); + + mln_ch_value(I,V) + output = lines_discontinued(input, nh, nlines, win, rank_k); + + trace::exiting("scribo::primitive::lines_v_discontinued"); + return output; + } + + + + template <typename I, typename N, typename V> + mln_ch_value(I,V) + lines_v_discontinued(const Image<I>& input, + const Neighborhood<N>& nbh, V& nlines, + unsigned line_length, unsigned rank_k, + util::array<box<mln_site(I)> >& line_bboxes) + { + trace::entering("scribo::primitive::lines_v_discontinued"); + + internal::line_v_discontinued_tests(input, nbh, nlines, + line_length, rank_k); + + win::vline2d win(line_length); + mln_ch_value(I,V) + output = internal::line_v_discontinued_tests(input, nbh, nlines, + line_length, rank_k, + line_bboxes); + + trace::exiting("scribo::primitive::lines_v_discontinued"); + return output; + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace scribo::extract::primitive + + } // end of namespace scribo::extract + +} // end of namespace scribo + + +#endif // ! SCRIBO_EXTRACT_PRIMITIVE_LINES_V_DISCONTINUED_HH diff --git a/milena/sandbox/scribo/extract/primitive/objects.hh b/milena/sandbox/scribo/extract/primitive/objects.hh new file mode 100644 index 0000000..cc55d72 --- /dev/null +++ b/milena/sandbox/scribo/extract/primitive/objects.hh @@ -0,0 +1,158 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// 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 SCRIBO_EXTRACT_PRIMITIVE_OBJECTS_HH +# define SCRIBO_EXTRACT_PRIMITIVE_OBJECTS_HH + +/// \file scribo/core/objects.hh +/// +/// Extract objects in a binary image. + + +# include <mln/core/concept/image.hh> +# include <mln/core/concept/neighborhood.hh> +# include <mln/core/site_set/box.hh> + +# include <mln/labeling/blobs.hh> +# include <mln/labeling/compute.hh> + +# include <mln/util/array.hh> + +# include <mln/debug/println.hh> + +namespace scribo +{ + + namespace extract + { + + namespace primitive + { + + using namespace mln; + + /// Extract objects in a binary image. + /// + /// \param[in] input A binary image. Objects are must be set to 'true' + /// and background to 'false'. + /// \param[in] nbh A neighborhood to be used for labeling. + /// \param[in,out] nobjects Will store the numbers of objects found. + /// \param[in,out] bboxes Will store the objects bounding boxes. + /// + /// \return An image of labeled objects. + // + template <typename I, typename N, typename V> + inline + mln_ch_value(I,V) + objects(const Image<I>& input, + const Neighborhood<N>& nbh, V& nobjects, + util::array< box<mln_site(I)> >& bboxes); + + + /// Extract objects in a binary image. + /// \overload + // + template <typename I, typename N, typename V> + inline + mln_ch_value(I,V) + objects(const Image<I>& input, + const Neighborhood<N>& nbh, V& nobjects); + + +# ifndef MLN_INCLUDE_ONLY + + + namespace internal + { + + template <typename I, typename N, typename V> + inline + void + objects_tests(const Image<I>& input, + const Neighborhood<N>& nbh, V& nobjects) + { + mlc_equal(mln_value(I),bool)::check(); + mlc_is_a(V, mln::value::Symbolic)::check(); + mln_precondition(exact(input).is_valid()); + mln_precondition(exact(nbh).is_valid()); + (void) input; + (void) nbh; + (void) nobjects; + } + + + } // end of namespace scribo::extract::primitive::internal + + + template <typename I, typename N, typename V> + inline + mln_ch_value(I,V) + objects(const Image<I>& input, + const Neighborhood<N>& nbh, V& nobjects, + util::array< box<mln_site(I)> >& bboxes) + { + trace::entering("scribo::objects"); + + internal::objects_tests(input, nbh, nobjects); + + mln_ch_value(I,V) object = objects(input, nbh, nobjects); + + bboxes = labeling::compute(accu::meta::bbox(), lbl, nobjects); + + trace::exiting("scribo::objects"); + return output; + } + + + template <typename I, typename N, typename V> + inline + mln_ch_value(I,V) + objects(const Image<I>& input, + const Neighborhood<N>& nbh, V& nobjects) + { + trace::entering("scribo::objects"); + + internal::objects_tests(input, nbh, nobjects); + + mln_ch_value(I,V) object = labeling::blobs(input, nbh, nobjects); + + trace::exiting("scribo::objects"); + return output; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace scribo::extract::primitive + + } // end of namespace scribo::extract + +} // end of namespace scribo + + +#endif // ! SCRIBO_EXTRACT_PRIMITIVE_OBJECTS_HH -- 1.5.6.5
participants (1)
-
Guillaume Lazzara