* scribo/deskew/all.hh: rename as...
* scribo/preprocessing/all.hh: ... this.
* scribo/preprocessing/unskew.hh: new routine.
---
milena/sandbox/ChangeLog | 9 ++
.../scribo/{deskew => preprocessing}/all.hh | 18 ++--
milena/sandbox/scribo/preprocessing/unskew.hh | 111 ++++++++++++++++++++
3 files changed, 129 insertions(+), 9 deletions(-)
rename milena/sandbox/scribo/{deskew => preprocessing}/all.hh (79%)
create mode 100644 milena/sandbox/scribo/preprocessing/unskew.hh
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index 058d82f..8421040 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,5 +1,14 @@
2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add the unskew routine.
+
+ * scribo/deskew/all.hh: rename as...
+ * scribo/preprocessing/all.hh: ... this.
+
+ * scribo/preprocessing/unskew.hh: new routine.
+
+2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add routines for primitive extraction.
* scribo/extract/primitive/canvas.hh,
diff --git a/milena/sandbox/scribo/deskew/all.hh b/milena/sandbox/scribo/preprocessing/all.hh
similarity index 79%
rename from milena/sandbox/scribo/deskew/all.hh
rename to milena/sandbox/scribo/preprocessing/all.hh
index 8e15e9c..145d6f4 100644
--- a/milena/sandbox/scribo/deskew/all.hh
+++ b/milena/sandbox/scribo/preprocessing/all.hh
@@ -25,24 +25,24 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef SCRIBO_DESKEW_ALL_HH
-# define SCRIBO_DESKEW_ALL_HH
+#ifndef SCRIBO_PREPROCESSING_ALL_HH
+# define SCRIBO_PREPROCESSING_ALL_HH
-/// \file scribo/deskew/all.hh
+/// \file scribo/preprocessing/all.hh
///
-/// Include all headers located in scribo/deskew.
+/// Include all headers located in scribo/preprocessing.
namespace scribo
{
- /// Namespace of deskew routines.
- namespace deskew
+ /// Namespace of preprocessing routines.
+ namespace preprocessing
{
- } // end of namespace scribo::deskew
+ } // end of namespace scribo::preprocessing
} // end of namespace scribo
-# include <scribo/deskew/hough.hh>
+# include <scribo/preprocessing/hough.hh>
-#endif // ! SCRIBO_DESKEW_ALL_HH
+#endif // ! SCRIBO_PREPROCESSING_ALL_HH
diff --git a/milena/sandbox/scribo/preprocessing/unskew.hh b/milena/sandbox/scribo/preprocessing/unskew.hh
new file mode 100644
index 0000000..bb71505
--- /dev/null
+++ b/milena/sandbox/scribo/preprocessing/unskew.hh
@@ -0,0 +1,111 @@
+// 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_UNSKEW_HOUGH_HH
+# define SCRIBO_UNSKEW_HOUGH_HH
+
+/// \file scribo/preprocessing/unskew.hh
+///
+/// Unskew an image.
+
+# include <mln/core/image/image2d.hh>
+
+# include <mln/accu/compute.hh>
+# include <mln/accu/max_site.hh>
+
+# include <mln/transform/hough.hh>
+# include <mln/transformation/rotate.hh>
+
+namespace scribo
+{
+
+ namespace preprocessing
+ {
+
+ using namespace mln;
+
+ /// Unskew a document.
+ /// Based on the Hough transform.
+ ///
+ /// \param[in] input_ A binary image. Objects to be unskewed must be set
+ /// to "true".
+ ///
+ /// \return A binary image.
+ //
+ template <typename I>
+ mln_concrete(I)
+ unskew(const Image<I>& input_);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ mln_concrete(I)
+ unskew(const Image<I>& input_)
+ {
+ trace::entering("scribo::preprocessing::unskew");
+
+ const I& input = exact(input_);
+ mlc_equal(mln_value(I), bool)::check();
+ mln_precondition(input.is_valid());
+
+ image2d<float> hough_ima = transform::hough(input);
+
+ point2d max_p = accu::compute(accu::max_site<image2d<float> >(), hough_ima);
+
+ std::cout << max_p.col() << std::endl;
+ double angle = 0;
+ int max_angle = max_p.col();
+
+ if (max_angle > 180)
+ max_angle = - max_angle % 180;
+
+ if (max_angle < 90 && max_angle > 0)
+ angle = - max_angle;
+ else if (max_angle < 0 && max_angle > -90)
+ angle = max_angle;
+ else if (max_angle < 180 && max_angle > 90)
+ angle = 180 - max_angle;
+ else if (max_angle < -90 && max_angle > -180)
+ angle = 180 + max_angle;
+
+ mln_concrete(I) output = transformation::rotate(input, angle);
+
+ trace::exiting("scribo::preprocessing::unskew");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::preprocessing
+
+} // end of namespace mln
+
+# endif // SCRIBO_UNSKEW_HOUGH_HH
--
1.5.6.5
* 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(a)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(a)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
* mln/util/pix.hh: Do not store a const reference of a psite, but a
const psite instead. More information is available in this file.
---
milena/ChangeLog | 7 +++++++
milena/mln/util/pix.hh | 20 +++++++++++++++++---
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 6ea258c..bf45e27 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,12 @@
2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Fix a bug in util::pix.
+
+ * mln/util/pix.hh: Do not store a const reference of a psite, but a
+ const psite instead. More information is available in this file.
+
+2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add accu::max_site.
* mln/accu/max_site.hh: new accu.
diff --git a/milena/mln/util/pix.hh b/milena/mln/util/pix.hh
index baa20db..0445e93 100644
--- a/milena/mln/util/pix.hh
+++ b/milena/mln/util/pix.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2007, 2008, 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
@@ -105,7 +105,15 @@ namespace mln
const I& ima_;
/// The psite associate to pix.
- const mln_psite(I)& p_;
+ //
+ // FIXME: Do we want a reference here?
+ // I (Z) guess we don't since I got invalid values
+ // when converting a pixter to a util::pix.
+ // The automatic conversion creates a temporary psite which invalided
+ // this reference once it was destroyed. see 'operator util::pix()' in
+ // core/pixter2d.hh.
+ //
+ const mln_psite(I) p_;
};
@@ -117,6 +125,7 @@ namespace mln
: ima_(exact(ima)),
p_(p)
{
+ mln_postcondition(exact(ima).is_valid());
}
template <typename I>
@@ -124,6 +133,7 @@ namespace mln
const I&
pix<I>::ima() const
{
+ mln_precondition(ima_.is_valid());
return ima_;
}
@@ -132,6 +142,8 @@ namespace mln
const mln_psite(I)&
pix<I>::p() const
{
+ mln_precondition(ima_.is_valid());
+ mln_precondition(ima_.has(p_));
return p_;
}
@@ -140,6 +152,8 @@ namespace mln
mln_rvalue(I)
pix<I>::v() const
{
+ mln_precondition(ima_.is_valid());
+ mln_precondition(ima_.has(p_));
return ima_(p_);
}
--
1.5.6.5
* mln/accu/max_site.hh: new accu.
* tests/accu/Makefile.am,
* tests/accu/max_site.cc: new associated test.
---
milena/ChangeLog | 9 ++
milena/mln/accu/max_site.hh | 187 +++++++++++++++++++++++++++++++++++++++++
milena/tests/accu/Makefile.am | 2 +
milena/tests/accu/max_site.cc | 55 ++++++++++++
4 files changed, 253 insertions(+), 0 deletions(-)
create mode 100644 milena/mln/accu/max_site.hh
create mode 100644 milena/tests/accu/max_site.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 6938aa3..6ea258c 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,14 @@
2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add accu::max_site.
+
+ * mln/accu/max_site.hh: new accu.
+
+ * tests/accu/Makefile.am,
+ * tests/accu/max_site.cc: new associated test.
+
+2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add new routines related to constrained skeletons.
* mln/morpho/skeleton_constrained.hh: cleanup.
diff --git a/milena/mln/accu/max_site.hh b/milena/mln/accu/max_site.hh
new file mode 100644
index 0000000..56bd2c2
--- /dev/null
+++ b/milena/mln/accu/max_site.hh
@@ -0,0 +1,187 @@
+// 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 MLN_ACCU_MAX_SITE_HH
+# define MLN_ACCU_MAX_SITE_HH
+
+/// \file mln/accu/max_site.hh
+///
+/// Define an accumulator that computes the first site with the maximum value
+/// in an image.
+///
+/// \todo Use accu::pair just like in accu::min_max.
+
+# include <mln/accu/internal/base.hh>
+# include <mln/util/pix.hh>
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+
+ /// \brief Define an accumulator that computes the first site with the maximum
+ /// value in an image.
+ ///
+ /// \ingroup modaccuimages
+ //
+ template <typename I>
+ struct max_site : public mln::accu::internal::base< mln_psite(I), max_site<I> >
+ {
+ typedef mln::util::pix<I> argument;
+ typedef mln_psite(I) result;
+
+ max_site();
+
+ /// Manipulators.
+ /// \{
+ void init();
+ void take(const argument& t);
+ void take(const max_site<I>& other);
+ /// \}
+
+ /// Get the value of the accumulator.
+ mln_psite(I) to_result() const;
+ operator mln_psite(I) () const;
+
+ /// Underlying value.
+ mln_value(I) value_() const;
+
+ /// Check whether this accu is able to return a result.
+ /// Always true here.
+ bool is_valid() const;
+
+ protected:
+ bool is_valid_;
+ mln_psite(I) max_p_;
+ mln_value(I) max_v_;
+ };
+
+
+
+ namespace meta
+ {
+
+ /// Meta accumulator for max_site.
+ struct max_site : public Meta_Accumulator< max_site >
+ {
+ template <typename I>
+ struct with
+ {
+ typedef accu::max_site<I> ret;
+ };
+ };
+
+ } // end of namespace mln::accu::meta
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ inline
+ max_site<I>::max_site()
+ {
+ init();
+ }
+
+ template <typename I>
+ inline
+ void
+ max_site<I>::init()
+ {
+ is_valid_ = false;
+ max_v_ = mln_min(mln_value(I));
+ }
+
+ template <typename I>
+ inline
+ void max_site<I>::take(const argument& t)
+ {
+ if (t.v() > max_v_)
+ {
+ max_v_ = t.v();
+ max_p_ = t.p();
+ is_valid_ = true;
+ }
+ }
+
+ template <typename I>
+ inline
+ void
+ max_site<I>::take(const max_site<I>& other)
+ {
+ mln_precondition(other.is_valid());
+
+ if (other.value_() > max_v_)
+ {
+ max_v_ = other.value_();
+ max_p_ = other.to_result();
+ is_valid_ = true;
+ }
+ }
+
+ template <typename I>
+ inline
+ mln_psite(I)
+ max_site<I>::to_result() const
+ {
+ mln_precondition(is_valid());
+ return max_p_;
+ }
+
+ template <typename I>
+ inline
+ max_site<I>::operator mln_psite(I)() const
+ {
+ return to_result();
+ }
+
+ template <typename I>
+ inline
+ mln_value(I)
+ max_site<I>::value_() const
+ {
+ return max_v_;
+ }
+
+ template <typename I>
+ inline
+ bool
+ max_site<I>::is_valid() const
+ {
+ return is_valid_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_MAX_SITE_HH
diff --git a/milena/tests/accu/Makefile.am b/milena/tests/accu/Makefile.am
index 9e0f437..2694266 100644
--- a/milena/tests/accu/Makefile.am
+++ b/milena/tests/accu/Makefile.am
@@ -16,6 +16,7 @@ check_PROGRAMS = \
line \
max \
max_h \
+ max_site \
mean \
median_h \
min \
@@ -39,6 +40,7 @@ histo_SOURCES = histo.cc
line_SOURCES = line.cc
max_SOURCES = max.cc
max_h_SOURCES = max_h.cc
+max_site_SOURCES = max_site.cc
mean_SOURCES = mean.cc
median_h_SOURCES = median_h.cc
min_SOURCES = min.cc
diff --git a/milena/tests/accu/max_site.cc b/milena/tests/accu/max_site.cc
new file mode 100644
index 0000000..0bd82e5
--- /dev/null
+++ b/milena/tests/accu/max_site.cc
@@ -0,0 +1,55 @@
+// 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.
+
+/// \file tests/accu/max_site.cc
+///
+/// Tests on mln::accu::max_site.
+
+
+#include <mln/core/image/image2d.hh>
+#include <mln/accu/max_site.hh>
+#include <mln/make/image2d.hh>
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d<unsigned> I;
+
+ unsigned values[] = { 0, 2, 3,
+ 1, 9, 2,
+ 3, 4, 8 };
+
+ I ima = make::image2d(values);
+ accu::max_site<I> accu;
+
+ mln_pixter_(I) p(ima);
+ for_all(p)
+ accu.take(p);
+
+ mln_assertion(accu.to_result() == point2d(1,1));
+}
--
1.5.6.5
* mln/morpho/skeleton_constrained.hh: cleanup.
* mln/topo/skeleton/crest.hh,
* mln/topo/skeleton/is_simple_point.hh: new routines.
* tests/topo/Makefile.am,
* tests/topo/skeleton/Makefile.am,
* tests/topo/skeleton/crest.cc,
* tests/topo/skeleton/is_simple_point: new tests.
---
milena/ChangeLog | 14 ++
milena/mln/morpho/skeleton_constrained.hh | 29 ++--
milena/mln/topo/skeleton/crest.hh | 123 +++++++++++
milena/mln/topo/skeleton/is_simple_point.hh | 287 +++++++++++++++++++++++++
milena/tests/topo/Makefile.am | 2 +
milena/tests/topo/skeleton/Makefile.am | 12 +
milena/tests/topo/skeleton/crest.cc | 85 ++++++++
milena/tests/topo/skeleton/is_simple_point.cc | 53 +++++
8 files changed, 592 insertions(+), 13 deletions(-)
create mode 100644 milena/mln/topo/skeleton/crest.hh
create mode 100644 milena/mln/topo/skeleton/is_simple_point.hh
create mode 100644 milena/tests/topo/skeleton/Makefile.am
create mode 100644 milena/tests/topo/skeleton/crest.cc
create mode 100644 milena/tests/topo/skeleton/is_simple_point.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index d4ff83d..6938aa3 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,19 @@
2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add new routines related to constrained skeletons.
+
+ * mln/morpho/skeleton_constrained.hh: cleanup.
+
+ * mln/topo/skeleton/crest.hh,
+ * mln/topo/skeleton/is_simple_point.hh: new routines.
+
+ * tests/topo/Makefile.am,
+ * tests/topo/skeleton/Makefile.am,
+ * tests/topo/skeleton/crest.cc,
+ * tests/topo/skeleton/is_simple_point: new tests.
+
+2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add transformation::rotation.
* mln/transformation/all.hh,
diff --git a/milena/mln/morpho/skeleton_constrained.hh b/milena/mln/morpho/skeleton_constrained.hh
index 273a259..0b4e00c 100644
--- a/milena/mln/morpho/skeleton_constrained.hh
+++ b/milena/mln/morpho/skeleton_constrained.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 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
@@ -69,11 +70,18 @@ namespace mln
const Neighborhood<N>& nbh_, const F& is_simple,
const Image<K>& constraint_, const Image<R>& priority_)
{
+ trace::entering("morpho::skeleton_constrained");
+
const I& input = exact(input_);
const N& nbh = exact(nbh_);
const K& constraint = exact(constraint_);
const R& priority = exact(priority_);
+ mln_precondition(input.is_valid());
+ mln_precondition(nbh.is_valid());
+ mln_precondition(constraint.is_valid());
+ mln_precondition(priority.is_valid());
+
extension::adjust_duplicate(input, nbh);
// FIXME: Tests!
@@ -92,17 +100,13 @@ namespace mln
mln_piter(I) p(input.domain());
for_all(p)
- if ( input(p) == false &&
- is_simple(input, nbh, p) ) // p is a simple point of the background.
+ if (input(p) == false &&
+ is_simple(input, nbh, p)) // p is a simple point of the background.
{
q.push(priority(p), p);
- // std::cout << p << " ";
}
- std::cout << std::endl;
}
- // std::cout << std::endl << "propagation..." << std::endl;
-
// Propagation.
{
P p;
@@ -111,19 +115,18 @@ namespace mln
{
p = q.pop_front();
for_all(n)
- if ( output.has(n) &&
- output(n) == true &&
- constraint(n) == false &&
- is_simple(output, nbh, n) )
+ if (output.has(n) &&
+ output(n) == true &&
+ constraint(n) == false &&
+ is_simple(output, nbh, n))
{
output(n) = false; // Remove n from object.
q.push(priority(n), n);
- // std::cout << n << " ";
}
}
- std::cout << std::endl;
}
+ trace::exiting("morpho::skeleton_constrained");
return output;
}
diff --git a/milena/mln/topo/skeleton/crest.hh b/milena/mln/topo/skeleton/crest.hh
new file mode 100644
index 0000000..432b57c
--- /dev/null
+++ b/milena/mln/topo/skeleton/crest.hh
@@ -0,0 +1,123 @@
+// 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 MLN_TOPO_SKELETON_CREST_HH
+# define MLN_TOPO_SKELETON_CREST_HH
+
+/// \file mln/topo/skeleton/crest.hh
+///
+/// Compute skeletization constraints.
+
+
+namespace mln
+{
+
+ namespace topo
+ {
+
+ namespace skeleton
+ {
+
+
+ /// Compute skeletization constraints.
+ ///
+ /// \param[in] input_ A binary image.
+ /// \param[in] dist_map_ A distance map of \p input. Contains the
+ /// inner object distance map.
+ /// \param[in] nbh_ A neighborhood.
+ ///
+ /// \result A binary image.
+ //
+ template <typename I, typename D, typename N>
+ mln_concrete(I)
+ crest(const Image<I>& input_, const Image<D>& dist_map_,
+ const Neighborhood<N>& nbh_);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I, typename D, typename N>
+ mln_concrete(I)
+ crest(const Image<I>& input_, const Image<D>& dist_map_,
+ const Neighborhood<N>& nbh_)
+ {
+ trace::entering("topo::skeleton::crest");
+ const I& input = exact(input_);
+ const D& dist_map = exact(dist_map_);
+ const N& nbh = exact(nbh_);
+
+ mlc_equal(mln_value(I), bool)::check();
+ mln_precondition(input.is_valid());
+ mln_precondition(dist_map.is_valid());
+ mln_precondition(nbh.is_valid());
+
+ mln_concrete(I) is_crest;
+ initialize(is_crest, input);
+ data::fill(is_crest, false);
+
+ mln_piter(I) p(input.domain());
+ mln_niter(N) n(nbh, p);
+ for_all(p)
+ {
+ if (!input(p) || dist_map(p) < 0)
+ continue;
+
+ unsigned nb_eq = 0;
+ unsigned nb_gt = 0;
+ unsigned nb_lt = 0;
+ for_all(n)
+ if (input.domain().has(n))
+ {
+ if (dist_map(n) == dist_map(p))
+ ++nb_eq;
+ else if (dist_map(n) > dist_map(p))
+ ++nb_gt;
+ else
+ ++nb_lt;
+ }
+
+ if ((nb_lt + nb_eq) > 5) // Pixel Superiority index
+ is_crest(p) = true;
+ }
+
+ trace::exiting("topo::skeleton::crest");
+ return is_crest;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace mln::topo::skeleton
+
+ } // end of namespace mln::topo
+
+} // end of namespace mln
+
+#endif // ! MLN_TOPO_SKELETON_CREST_HH
diff --git a/milena/mln/topo/skeleton/is_simple_point.hh b/milena/mln/topo/skeleton/is_simple_point.hh
new file mode 100644
index 0000000..4d31dfc
--- /dev/null
+++ b/milena/mln/topo/skeleton/is_simple_point.hh
@@ -0,0 +1,287 @@
+// 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 MLN_TOPO_SKELETON_IS_SIMPLE_POINT_HH
+# define MLN_TOPO_SKELETON_IS_SIMPLE_POINT_HH
+
+/// \file mln/topo/skeleton/is_simple_point.hh
+///
+/// is_simple_point tells if a point is simple or not.
+/// For more information refer to bertrand.07.chap.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/alias/point2d.hh>
+# include <mln/core/alias/neighb2d.hh>
+
+namespace mln
+{
+
+ namespace topo
+ {
+
+ namespace skeleton
+ {
+
+ /*! Tell if a point is simple or not. A point of an object is simple
+ * if in its c8 neiborhood, there is exactly one connected component of the
+ * object, and only one connected component of the background
+ * Examples : ( | == object, - = background)
+ * \verbatim
+
+ - - |
+ | P | Here p is simple in the c4 and c8 case.
+ | | |
+
+ - | -
+ | P | Here p is never simple.
+ | | |
+
+ \endverbatim
+ */
+ template <typename I, typename N>
+ bool
+ is_simple_point(const Image<I>& ima,
+ const Neighborhood<N>& nbh,
+ const mln_site(I)& p);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+
+ static const unsigned char nb_connexity_c8[256] =
+ {
+ 0, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1,
+ 1, 2, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1,
+ 1, 2, 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1,
+ 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1,
+
+ 1, 2, 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1,
+ 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1,
+ 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2,
+ 1, 2, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1,
+ 2, 3, 3, 3, 3, 4, 3, 3, 2, 2, 2, 2, 3, 3, 2, 2,
+ 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1,
+
+ 1, 2, 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1,
+ 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1,
+ 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
+ };
+
+ static const unsigned char nb_connexity_c4[256] =
+ {
+ 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1,
+ 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 2, 2, 2, 2, 1,
+ 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1,
+ 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 2, 2, 2, 2, 1,
+
+ 1, 1, 2, 2, 1, 1, 2, 2, 2, 2, 3, 2, 2, 2, 3, 2,
+ 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 3, 3, 3, 3, 2,
+ 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 2, 1,
+ 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 1,
+
+ 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1,
+ 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 2, 2, 2, 2, 1,
+ 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1,
+ 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 2, 2, 2, 2, 1,
+
+ 1, 1, 2, 2, 1, 1, 2, 2, 2, 2, 3, 2, 2, 2, 3, 2,
+ 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 2, 2, 2, 2, 1,
+ 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 2, 1,
+ 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1
+ };
+
+
+
+ template <typename I, typename N>
+ inline
+ unsigned
+ nb_connexity2d(const I& ima,
+ const N& nbh,
+ const mln_site(I)& p,
+ bool object)
+ {
+ unsigned res = 0;
+
+ mln_bkd_niter(N) n(c8(), p);
+ for_all(n)
+ {
+ res = (res << 1);
+ if (ima.domain().has(n) && ima(n) == object)
+ res = res | 1;
+ }
+
+ if (nbh == c8())
+ return nb_connexity_c8[res];
+ else
+ {
+ mln_assertion(nbh == c4());
+ return nb_connexity_c4[res];
+ }
+ }
+
+
+ template <typename N>
+ neighb2d
+ complement2d(const Neighborhood<N>& nbh_)
+ {
+ const N& nbh = exact(nbh_);
+ mln_precondition(nbh.is_valid());
+ mln_precondition(nbh == c4() || nbh == c8());
+
+ if (nbh == c4())
+ return c8();
+ else
+ return c4();
+ }
+
+
+ // Tests.
+
+ template <typename I, typename N>
+ inline
+ void
+ is_simple_point_tests(const Image<I>& ima_,
+ const Neighborhood<N>& nbh_,
+ const mln_site(I)& p)
+ {
+ const I& ima = exact(ima_);
+ const N& nbh = exact(nbh_);
+
+ mln_assertion(nbh == c4() || nbh == c8());
+ mln_precondition(ima.is_valid());
+ mln_precondition(nbh.is_valid());
+
+ (void) ima;
+ (void) nbh;
+ (void) p;
+ }
+
+ } // end of namespace mln::topo::skeleton::internal
+
+
+
+ // Implementations
+
+ namespace impl
+ {
+
+ template <typename I, typename N>
+ inline
+ bool
+ is_simple_point2d(const Image<I>& ima_,
+ const Neighborhood<N>& nbh_,
+ const point2d& p)
+ {
+ const I& ima = exact(ima_);
+ const N& nbh = exact(nbh_);
+
+ internal::is_simple_point_tests(ima, nbh, p);
+
+ bool b = (internal::nb_connexity2d(ima, nbh, p, true) == 1)
+ && (internal::nb_connexity2d(ima, internal::complement2d(nbh),
+ p, false) == 1);
+
+ trace::exiting("topo::skeleton::is_simple_point2d");
+ return b;
+ }
+
+ } // end of namespace mln::topo::skeleton::impl
+
+
+
+
+ // Dispatch
+
+ namespace internal
+ {
+
+ template <typename I, typename N>
+ inline
+ bool
+ is_simple_point_dispatch(const Image<I>& ima,
+ const Neighborhood<N>& nbh,
+ const point2d& p)
+ {
+ return impl::is_simple_point2d(ima, nbh, p);
+ }
+
+
+ template <typename I, typename N>
+ inline
+ bool
+ is_simple_point_dispatch(const Image<I>& ima,
+ const Neighborhood<N>& nbh,
+ const mln_site(I)& p)
+ {
+ /// Not implemented for that site type yet.
+ mlc_abort(I)::check();
+ return false;
+ }
+
+ } // end of namespace mln::topo::skeleton::internal
+
+
+
+
+
+ // Facade
+
+ template <typename I, typename N>
+ inline
+ bool
+ is_simple_point(const Image<I>& ima,
+ const Neighborhood<N>& nbh,
+ const mln_site(I)& p)
+ {
+ trace::entering("topo::skeleton::is_simple_point2d");
+
+ internal::is_simple_point_tests(ima, nbh, p);
+
+ bool b = internal::is_simple_point_dispatch(ima, nbh, p);
+
+ trace::exiting("topo::skeleton::is_simple_point2d");
+ return b;
+ }
+
+
+# endif // MLN_TOPO_SKELETON_INCLUDE_ONLY
+
+ } // end of namespace mln::topo::skeleton
+
+ } // end of namespace mln::topo
+
+} // end of namespace mln
+
+#endif // ! MLN_TOPO_SKELETON_IS_SIMPLE_POINT_HH
diff --git a/milena/tests/topo/Makefile.am b/milena/tests/topo/Makefile.am
index b955229..b9b3982 100644
--- a/milena/tests/topo/Makefile.am
+++ b/milena/tests/topo/Makefile.am
@@ -2,6 +2,8 @@
include $(top_srcdir)/milena/tests/tests.mk
+SUBDIRS = skeleton
+
check_PROGRAMS = \
complex
diff --git a/milena/tests/topo/skeleton/Makefile.am b/milena/tests/topo/skeleton/Makefile.am
new file mode 100644
index 0000000..ff96b31
--- /dev/null
+++ b/milena/tests/topo/skeleton/Makefile.am
@@ -0,0 +1,12 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include $(top_srcdir)/milena/tests/tests.mk
+
+check_PROGRAMS = \
+ crest \
+ is_simple_point
+
+crest_SOURCES = crest.cc
+is_simple_point_SOURCES = is_simple_point.cc
+
+TESTS = $(check_PROGRAMS)
diff --git a/milena/tests/topo/skeleton/crest.cc b/milena/tests/topo/skeleton/crest.cc
new file mode 100644
index 0000000..ba2c500
--- /dev/null
+++ b/milena/tests/topo/skeleton/crest.cc
@@ -0,0 +1,85 @@
+// 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.
+
+/// \file tests/topo/skeleton/crest.cc
+///
+/// Test of mln::topo::skeleton::crest.
+
+# include <mln/core/alias/neighb2d.hh>
+# include <mln/core/image/image2d.hh>
+
+# include <mln/level/compare.hh>
+
+# include <mln/logical/not.hh>
+
+# include <mln/make/image.hh>
+# include <mln/make/w_window2d_int.hh>
+
+# include <mln/topo/skeleton/crest.hh>
+
+# include <mln/transform/distance_front.hh>
+
+# include <mln/value/int_u8.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ bool ref_dat[][9] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0, 1, 0, 0, 0 },
+ { 0, 0, 0, 0, 1, 1, 0, 1, 0 },
+ { 0, 1, 1, 1, 1, 1, 0, 1, 0 },
+ { 0, 0, 0, 0, 1, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 1, 0, 1, 0, 0 },
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
+
+ bool in_dat[][9] = { { 0, 0, 0, 0, 1, 1, 1, 0, 0 },
+ { 0, 0, 0, 1, 1, 1, 1, 0, 0 },
+ { 0, 0, 1, 1, 1, 1, 1, 1, 1 },
+ { 0, 1, 1, 1, 1, 1, 1, 1, 1 },
+ { 0, 0, 1, 1, 1, 1, 1, 0, 0 },
+ { 0, 0, 0, 1, 1, 1, 1, 0, 0 },
+ { 0, 0, 0, 0, 1, 0, 0, 0, 0 } };
+
+ int vals[] = { 0, 9, 0, 9, 0,
+ 9, 6, 4, 6, 9,
+ 0, 4, 0, 4, 0, // Values of distances.
+ 9, 6, 4, 6, 9,
+ 0, 9, 0, 9, 0 };
+
+ image2d<bool> input = make::image(in_dat);
+ image2d<bool> crest_ref = make::image(ref_dat);
+
+ image2d<value::int_u8>
+ dist_map = transform::distance_front(logical::not_(input), c8(),
+ make::w_window2d_int(vals),
+ mln_max(value::int_u8));
+ image2d<bool> crest_ima = topo::skeleton::crest(input, dist_map, c8());
+
+ mln_assertion(crest_ima == crest_ref);
+}
diff --git a/milena/tests/topo/skeleton/is_simple_point.cc b/milena/tests/topo/skeleton/is_simple_point.cc
new file mode 100644
index 0000000..23cb97c
--- /dev/null
+++ b/milena/tests/topo/skeleton/is_simple_point.cc
@@ -0,0 +1,53 @@
+// 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.
+
+/// \file tests/topo/skeleton/is_simple_point.cc
+///
+/// Test mln::topo::skeleton::is_simple_point.
+
+#include <mln/make/image2d.hh>
+#include <mln/topo/skeleton/is_simple_point.hh>
+#include <mln/make/image.hh>
+
+#include <mln/debug/println.hh>
+
+static const unsigned ref[] = { 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0 };
+
+int main()
+{
+ using namespace mln;
+
+ bool vals[][6] = { { 0, 1, 0, 0, 1, 1 },
+ { 0, 0, 0, 0, 1, 1 } };
+
+ image2d<bool> ima = make::image(vals);
+
+ unsigned i = 0;
+ mln_piter_(image2d<bool>) p(ima.domain());
+ for_all(p)
+ mln_assertion(ref[i++] == topo::skeleton::is_simple_point(ima, c8(), p));
+}
--
1.5.6.5
* mln/transformation/all.hh,
* mln/transformation/essential.hh: new headers.
* mln/transformation/rotate.hh: new routine.
* tests/transformation/Makefile.am,
* tests/transformation/rotate.cc: new associated test.
---
milena/ChangeLog | 12 +++
milena/mln/transformation/all.hh | 45 +++++++++++
milena/mln/transformation/essential.hh | 33 ++++++++
milena/mln/transformation/rotate.hh | 128 +++++++++++++++++++++++++++++++
milena/tests/Makefile.am | 1 +
milena/tests/transformation/Makefile.am | 10 +++
milena/tests/transformation/rotate.cc | 60 ++++++++++++++
7 files changed, 289 insertions(+), 0 deletions(-)
create mode 100644 milena/mln/transformation/all.hh
create mode 100644 milena/mln/transformation/essential.hh
create mode 100644 milena/mln/transformation/rotate.hh
create mode 100644 milena/tests/transformation/Makefile.am
create mode 100644 milena/tests/transformation/rotate.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index c6701bf..d4ff83d 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,17 @@
2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add transformation::rotation.
+
+ * mln/transformation/all.hh,
+ * mln/transformation/essential.hh: new headers.
+
+ * mln/transformation/rotate.hh: new routine.
+
+ * tests/transformation/Makefile.am,
+ * tests/transformation/rotate.cc: new associated test.
+
+2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Improve io::magick tests.
* tests/io/magick/Makefile.am,
diff --git a/milena/mln/transformation/all.hh b/milena/mln/transformation/all.hh
new file mode 100644
index 0000000..1379093
--- /dev/null
+++ b/milena/mln/transformation/all.hh
@@ -0,0 +1,45 @@
+// 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 MLN_TRANSFORMATION_ALL_HH_
+# define MLN_TRANSFORMATION_ALL_HH_
+
+namespace mln
+{
+
+ /// Namespace of transformation routines.
+ namespace transformation
+ {
+
+ } // end of namespace mln::transformation
+
+} // end of namespace mln
+
+
+# include <mln/transformation/rotation.hh>
+
+# endif // ! MLN_TRANSFORMATION_ALL_HH_
diff --git a/milena/mln/transformation/essential.hh b/milena/mln/transformation/essential.hh
new file mode 100644
index 0000000..990bf83
--- /dev/null
+++ b/milena/mln/transformation/essential.hh
@@ -0,0 +1,33 @@
+// 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 MLN_TRANSFORMATION_ESSENTIAL_HH_
+# define MLN_TRANSFORMATION_ESSENTIAL_HH_
+
+// None.
+
+# endif // ! MLN_TRANSFORMATION_ESSENTIAL_HH_
diff --git a/milena/mln/transformation/rotate.hh b/milena/mln/transformation/rotate.hh
new file mode 100644
index 0000000..635db66
--- /dev/null
+++ b/milena/mln/transformation/rotate.hh
@@ -0,0 +1,128 @@
+// 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 MLN_TRANSFORMATION_ROTATE_HH
+# define MLN_TRANSFORMATION_ROTATE_HH
+
+# include <mln/core/routine/extend.hh>
+
+# include <mln/core/image/tr_image.hh>
+
+# include <mln/data/paste.hh>
+
+# include <mln/geom/bbox.hh>
+
+# include <mln/fun/x2x/composed.hh>
+# include <mln/fun/x2x/rotation.hh>
+# include <mln/fun/x2x/translation.hh>
+
+# include <mln/literal/zero.hh>
+
+# include <mln/math/pi.hh>
+
+
+namespace mln
+{
+
+ namespace transformation
+ {
+
+ /// Perform a rotation from the center of an image.
+ ///
+ /// \param[in] input_ An image.
+ /// \param[in] angle An angle in degrees.
+ /// \param[in] extension_ Function, image or value which will be used as
+ /// extension. This extension allows to map values
+ /// to sites which where not part of the domain
+ /// before the rotation.
+ ///
+ /// \return An image with the same domain as \p input_.
+ //
+ template <typename I, typename Ext>
+ mln_concrete(I)
+ rotate(const Image<I>& input_, double angle, const Ext& extension_);
+
+
+ /// \overload
+ /// Use literal::zero as default value for the extension.
+ template <typename I>
+ mln_concrete(I)
+ rotate(const Image<I>& input_, double angle);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I, typename Ext>
+ mln_concrete(I)
+ rotate(const Image<I>& input_, double angle, const Ext& extension_)
+ {
+ trace::entering("transformation::rotate");
+
+ const I& input = exact(input_);
+
+ mln_precondition(input.is_valid());
+ mln_precondition(angle >= -360.0f && angle <= 360.0f);
+ /// FIXME: A precondition is probably missing for the extension value.
+
+ mln_site(I) c = geom::bbox(input).center();
+ fun::x2x::translation<2,double>
+ t(-1 * c.to_vec()),
+ t_1(c.to_vec());
+
+ typedef fun::x2x::rotation<2,double> rot_t;
+ rot_t rot(math::pi * angle / 180.f, literal::origin);
+
+ mln_concrete(I) output;
+ initialize(output, input);
+ data::paste(transposed_image(input.domain(),
+ extend(input, extension_),
+ compose(t_1, compose(rot, t))),
+ output);
+
+ trace::exiting("transformation::rotate");
+ return output;
+ }
+
+
+ template <typename I>
+ mln_concrete(I)
+ rotate(const Image<I>& input, double angle)
+ {
+ return rotate(input, angle, literal::zero);
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace mln::transformation
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRANSFORMATION_ROTATE_HH
diff --git a/milena/tests/Makefile.am b/milena/tests/Makefile.am
index cf419b8..53e12ab 100644
--- a/milena/tests/Makefile.am
+++ b/milena/tests/Makefile.am
@@ -43,6 +43,7 @@ SUBDIRS = \
trace \
trait \
transform \
+ transformation \
unit_test \
util \
value \
diff --git a/milena/tests/transformation/Makefile.am b/milena/tests/transformation/Makefile.am
new file mode 100644
index 0000000..39471ee
--- /dev/null
+++ b/milena/tests/transformation/Makefile.am
@@ -0,0 +1,10 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include $(top_srcdir)/milena/tests/tests.mk
+
+check_PROGRAMS = \
+ rotate
+
+rotate_SOURCES = rotate.cc
+
+TESTS = $(check_PROGRAMS)
diff --git a/milena/tests/transformation/rotate.cc b/milena/tests/transformation/rotate.cc
new file mode 100644
index 0000000..8bdd90c
--- /dev/null
+++ b/milena/tests/transformation/rotate.cc
@@ -0,0 +1,60 @@
+// 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.
+
+/// \file tests/transformation/rotate.cc
+///
+/// Test mln::transformation::rotate.
+
+# include <mln/core/image/image2d.hh>
+# include <mln/transformation/rotate.hh>
+# include <mln/make/image.hh>
+# include <mln/level/compare.hh>
+
+# include <mln/debug/println.hh>
+
+int main()
+{
+ using namespace mln;
+
+ bool ref_values[][5] = { { 0, 1, 0, 0, 0 },
+ { 0, 1, 1, 0, 0 },
+ { 0, 0, 1, 1, 0 },
+ { 0, 0, 0, 1, 1 },
+ { 0, 0, 0, 0, 1 } };
+
+ bool values[][5] = { { 0, 0, 1, 0, 0 },
+ { 0, 0, 1, 0, 0 },
+ { 0, 0, 1, 0, 0 },
+ { 0, 0, 1, 0, 0 },
+ { 0, 0, 1, 0, 0 } };
+
+ image2d<bool> ima = make::image(values);
+ image2d<bool> ref = make::image(ref_values);
+
+ image2d<bool> ima_rot = transformation::rotate(ima, 45);
+ mln_assertion(ima_rot == ref);
+}
--
1.5.6.5
* mln/transform/hough.hh: new routine.
* tests/transform/Makefile.am,
* tests/transform/hough.cc: new associated test.
---
milena/ChangeLog | 9 ++
milena/mln/transform/hough.hh | 216 ++++++++++++++++++++++++++++++++++++
milena/tests/transform/Makefile.am | 2 +
milena/tests/transform/hough.cc | 59 ++++++++++
4 files changed, 286 insertions(+), 0 deletions(-)
create mode 100644 milena/mln/transform/hough.hh
create mode 100644 milena/tests/transform/hough.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index fb68d60..40f9f88 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,12 @@
+2009-05-15 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Add hough transform.
+
+ * mln/transform/hough.hh: new routine.
+
+ * tests/transform/Makefile.am,
+ * tests/transform/hough.cc: new associated test.
+
2009-05-15 Roland Levillain <roland(a)lrde.epita.fr>
Regen Makefile helpers.
diff --git a/milena/mln/transform/hough.hh b/milena/mln/transform/hough.hh
new file mode 100644
index 0000000..61ecc4f
--- /dev/null
+++ b/milena/mln/transform/hough.hh
@@ -0,0 +1,216 @@
+// 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 MLN_TRANSFORM_HOUGH_HH
+# define MLN_TRANSFORM_HOUGH_HH
+
+/// \file mln/transform/hough.hh
+///
+/// Compute the hough transform.
+
+
+# include <mln/core/image/image2d.hh>
+# include <mln/data/fill.hh>
+
+# include <mln/geom/nrows.hh>
+# include <mln/geom/ncols.hh>
+# include <mln/geom/bbox.hh>
+
+# include <mln/opt/at.hh>
+
+# include <mln/math/sin.hh>
+# include <mln/math/cos.hh>
+# include <mln/math/pi.hh>
+
+# include <mln/make/box2d.hh>
+
+# include <mln/value/int_u8.hh>
+
+
+//FIXME: to be removed. For debug purpose.
+//#include <mln/level/convert.hh>
+//#include <mln/value/rgb8.hh>
+//#include <mln/draw/line.hh>
+//#include <mln/literal/colors.hh>
+//#include <mln/io/ppm/save.hh>
+
+
+namespace mln
+{
+
+ namespace transform
+ {
+
+ /// Compute the hough transform from a binary image.
+ /// Objects used for computation must be set to 'true'.
+ ///
+ /// \param[in] input_ A binary image.
+ /// \param[in] min_angle Minimum angle which can be found.
+ /// \param[in] max_angle Maximum angle which can be found.
+ ///
+ /// \return A 2D image of float. Rows are used for the distance and
+ /// columns are used for the angles. Angles go from 0 to 359.
+ /// Distance goes from 0 to the maximum distance between the center and a
+ /// corner.
+ /// The site having the maximum value indicates through its column index
+ /// the document inclination.
+ //
+ template <typename I>
+ image2d<float>
+ hough(const Image<I>& input_, int min_angle, int max_angle);
+
+
+ /// \overload
+ template <typename I>
+ image2d<float>
+ hough(const Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ image2d<float>
+ hough(const Image<I>& input_, int min_angle, int max_angle)
+ {
+ trace::entering("mln::transform::hough");
+ mln_precondition(min_angle < max_angle);
+
+ const I& input = exact(input_);
+ mlc_equal(mln_value(I), bool)::check();
+ mln_precondition(input.is_valid());
+
+ math::round<int> rd;
+ double deg2rad = math::pi / 180.0f;
+ int range = rd(sqrt((double)(geom::ncols(input) * geom::ncols(input)
+ + geom::nrows(input) * geom::nrows(input))));
+
+ long temp = min_angle;
+ min_angle = 450 - max_angle;
+ max_angle = 450 - temp;
+
+ // Pre-compute sin and cos values.
+ util::array<double> sin_cache(360),
+ cos_cache(360);
+ for (int omega = 0; omega < 360; ++omega)
+ {
+ sin_cache[omega] = math::sin((double)(omega * deg2rad));
+ cos_cache[omega] = math::cos((double)(omega * deg2rad));
+ }
+
+ image2d<float> output(make::box2d(range,360));
+ data::fill(output, 0);
+
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ if (input(p)) // Is this site part of an objet?
+ {
+
+ long teta1 = min_angle;
+ long teta2 = max_angle;
+ for (int omega = teta1; omega < teta2; ++omega)
+ {
+ long tetad = omega%360;
+ long r = rd(p.col() * sin_cache[tetad]
+ + p.row() * cos_cache[tetad]);
+ if (r > 0 && r < range)
+ output.at_(r, tetad) += 1;
+ }
+
+ teta1 = min_angle + 180;
+ teta2 = max_angle + 180;
+ for (int omega = teta1; omega < teta2; ++omega)
+ {
+ long tetad = omega%360;
+ long r = rd(p.col() * sin_cache[tetad]
+ + p.row() * cos_cache[tetad]);
+ if (r > 0 && r < range)
+ output.at_(r, tetad) += 1;
+ }
+
+ }
+
+// {
+// point2d max_p(0,0);
+// mln_piter_(image2d<float>) p(output.domain());
+// for_all(p)
+// if (output(max_p) < output(p))
+// max_p = p;
+//
+// point2d b,e;
+// b.col() = 0;
+// b.row() = max_p.row()/cos(deg2rad*max_p.col());
+// if (b.row() < 0)
+// {
+// b.row() = 0;
+// b.col() = max_p.row()/sin(deg2rad*max_p.col());
+// } else if (b.row() >= input.nrows())
+// {
+// b.row() = input.nrows() - 1;
+// b.col() = max_p.row() - b.row() * cos(deg2rad*max_p.col())/sin(deg2rad*max_p.col());
+// }
+//
+// e.col() = input.ncols() - 1;
+// e.row() = max_p.row() - e.col() * sin(deg2rad*max_p.col()) / cos(deg2rad*max_p.col());
+// if (e.row() < 0)
+// {
+// e.row() = 0;
+// e.col() = max_p.row()/sin(deg2rad*max_p.col());
+// } else if (e.row() >= input.nrows())
+// {
+// e.row() = input.nrows() - 1;
+// e.col() = max_p.row() - e.row() * cos(deg2rad*max_p.col())/sin(deg2rad*max_p.col());
+// }
+//
+// std::cout << b << " - " << e << std::endl;
+//
+// image2d<value::rgb8> toto = level::convert(value::rgb8(), input);
+// draw::line(toto, b, e, literal::red);
+// io::ppm::save(toto, "tmp_input.ppm");
+// }
+ trace::exiting("mln::transform::hough");
+ return output;
+ }
+
+
+ template <typename I>
+ image2d<float>
+ hough(const Image<I>& input)
+ {
+ return hough(input, -180, 180);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::transform
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRANSFORM_HOUGH_HH
+
diff --git a/milena/tests/transform/Makefile.am b/milena/tests/transform/Makefile.am
index a1a9788..f5ff98d 100644
--- a/milena/tests/transform/Makefile.am
+++ b/milena/tests/transform/Makefile.am
@@ -7,6 +7,7 @@ check_PROGRAMS = \
distance_and_closest_point_geodesic \
distance_front \
distance_geodesic \
+ hough \
influence_zone_front \
influence_zone_geodesic
@@ -14,6 +15,7 @@ bench_closest_point_geodesic_SOURCES = bench_closest_point_geodesic.cc
distance_and_closest_point_geodesic_SOURCES = distance_and_closest_point_geodesic.cc
distance_front_SOURCES = distance_front.cc
distance_geodesic_SOURCES = distance_geodesic.cc
+hough_SOURCES = hough.cc
influence_zone_front_SOURCES = influence_zone_front.cc
influence_zone_geodesic_SOURCES = influence_zone_geodesic.cc
diff --git a/milena/tests/transform/hough.cc b/milena/tests/transform/hough.cc
new file mode 100644
index 0000000..dd42043
--- /dev/null
+++ b/milena/tests/transform/hough.cc
@@ -0,0 +1,59 @@
+// 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.
+
+/// \file tests/transform/hough.cc
+///
+/// Test on mln::transform::hough.
+
+# include <mln/core/image/image2d.hh>
+# include <mln/transform/hough.hh>
+# include <mln/make/image.hh>
+
+int main()
+{
+ using namespace mln;
+
+ bool values[][5] = { { 0, 0, 0, 0, 0 },
+ { 1, 0, 0, 0, 0 },
+ { 0, 1, 1, 1, 0 },
+ { 0, 0, 0, 0, 1 },
+ { 0, 0, 0, 0, 0 } };
+
+ image2d<bool> ima = make::image(values);
+
+ image2d<float> hough = transform::hough(ima);
+
+ point2d max_p(0,0);
+ mln_piter_(image2d<float>) p(hough.domain());
+ for_all(p)
+ if (hough(max_p) < hough(p))
+ max_p = p;
+
+ // Checking angle value.
+ mln_assertion(max_p.col() == 335);
+}
+
--
1.5.6.5