4678: Add new debug routines.

* debug/alignment_decision_image.hh, * debug/links_decision_image.hh, * debug/save_object_diff.hh, * debug/several_links_decision_image.hh: New. --- scribo/ChangeLog | 9 ++ scribo/debug/alignment_decision_image.hh | 170 +++++++++++++++++++++++ scribo/debug/links_decision_image.hh | 127 ++++++++++++++++++ scribo/debug/save_object_diff.hh | 98 ++++++++++++++ scribo/debug/several_links_decision_image.hh | 185 ++++++++++++++++++++++++++ 5 files changed, 589 insertions(+), 0 deletions(-) create mode 100644 scribo/debug/alignment_decision_image.hh create mode 100644 scribo/debug/links_decision_image.hh create mode 100644 scribo/debug/save_object_diff.hh create mode 100644 scribo/debug/several_links_decision_image.hh diff --git a/scribo/ChangeLog b/scribo/ChangeLog index deee412..5e2d69e 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,14 @@ 2009-10-22 Guillaume Lazzara <z@lrde.epita.fr> + Add new debug routines. + + * debug/alignment_decision_image.hh, + * debug/links_decision_image.hh, + * debug/save_object_diff.hh, + * debug/several_links_decision_image.hh: New. + +2009-10-22 Guillaume Lazzara <z@lrde.epita.fr> + Revamp Sauvola binarization. * binarization/sauvola.hh: Revamp and now returns a threshold diff --git a/scribo/debug/alignment_decision_image.hh b/scribo/debug/alignment_decision_image.hh new file mode 100644 index 0000000..9a4fa50 --- /dev/null +++ b/scribo/debug/alignment_decision_image.hh @@ -0,0 +1,170 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef SCRIBO_DEBUG_ALIGNMENT_DECISION_IMAGE_HH +# define SCRIBO_DEBUG_ALIGNMENT_DECISION_IMAGE_HH + +/// \file +/// +/// Save a color image showing the difference between to object groups. + +# include <mln/core/concept/image.hh> +# include <mln/data/convert.hh> +# include <mln/value/rgb8.hh> +# include <mln/literal/colors.hh> +# include <mln/util/array.hh> +# include <mln/util/couple.hh> + +# include <scribo/core/object_groups.hh> +# include <scribo/draw/bounding_boxes.hh> + + +namespace scribo +{ + + namespace debug + { + + using namespace mln; + + enum Alignment { top, center, bottom }; + + /*! \brief Save a color image showing the difference between to + object links. + + \input[in] input An image. It's value type must be convertible + towards rgb8. + \input[in] links Object links information. + \input[in] filtered_links A copy of \p links which have been + filtered. + + \return A color image. Non filtered links are drawn in + green. Others are drawn in red. + */ + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + alignment_decision_image(const Image<I>& input_, + const object_links<L>& links, + const object_links<L>& filtered_links, + const Alignment& alignment); + + +# ifndef MLN_INCLUDE_ONLY + + + namespace internal + { + + template <typename L> + mln::util::couple<mln_site(L),mln_site(L)> + find_anchors(const object_image(L)& objects, + unsigned i, + unsigned link_i, + const Alignment& alignment) + { + mln_site(L) + a1 = objects.bbox(i).center(), + a2 = objects.bbox(link_i).center(); + + switch (alignment) + { + case top: + a1.row() = objects.bbox(i).pmin().row(); + a2.row() = objects.bbox(link_i).pmin().row(); + break; + + case center: + break; + + case bottom: + a1.row() = objects.bbox(i).pmax().row(); + a2.row() = objects.bbox(link_i).pmax().row(); + break; + + } + return make::couple(a1, a2); + } + + } + + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + alignment_decision_image(const Image<I>& input_, + const object_links<L>& links, + const object_links<L>& filtered_links, + const Alignment& alignment) + { + trace::entering("scribo::debug::alignment_decision_image"); + const I& input = exact(input_); + + const object_image(L)& objects = links.object_image_(); + + mln_precondition(input.is_valid()); + mln_precondition(links.is_valid()); + mln_precondition(filtered_links.is_valid()); + mln_precondition(links.size() == filtered_links.size()); + mln_precondition(links.object_image_() != filtered_links.object_image_()); + /// Fixme: check that objects has been computed from input. + + image2d<value::rgb8> + decision_image = data::convert(value::rgb8(), input); + + for_all_components(i, objects.bboxes()) + mln::draw::box(decision_image, objects.bbox(i), literal::blue); + + typedef mln_site(L) P; + + for (unsigned i = 1; i < links.size(); ++i) + { + + if (links[i] != i) + { + value::rgb8 value = literal::green; + if (links[i] != filtered_links[i]) + value = literal::red; + + mln::util::couple<P,P> + anchors = internal::find_anchors(objects, i, links[i], alignment); + mln::draw::line(decision_image, + anchors.first(), + anchors.second(), + value); + } + } + + trace::exiting("scribo::debug::alignment_decision_image"); + return decision_image; + } + + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace scribo::debug + +} // end of namespace scribo + + +#endif // ! SCRIBO_DEBUG_ALIGNMENT_DECISION_IMAGE_HH diff --git a/scribo/debug/links_decision_image.hh b/scribo/debug/links_decision_image.hh new file mode 100644 index 0000000..368d9b7 --- /dev/null +++ b/scribo/debug/links_decision_image.hh @@ -0,0 +1,127 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef SCRIBO_DEBUG_LINKS_DECISION_IMAGE_HH +# define SCRIBO_DEBUG_LINKS_DECISION_IMAGE_HH + +/// \file +/// +/// Save a color image showing the difference between to object groups. + +# include <mln/core/concept/image.hh> +# include <mln/accu/center.hh> +# include <mln/data/convert.hh> +# include <mln/value/rgb8.hh> +# include <mln/literal/colors.hh> +# include <mln/util/array.hh> + +# include <scribo/core/object_groups.hh> +# include <scribo/draw/bounding_boxes.hh> + + +namespace scribo +{ + + namespace debug + { + + using namespace mln; + + /// FIXME: DOC! + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + links_decision_image(const Image<I>& input_, + const object_links<L>& links, + const object_links<L>& filtered_links); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + links_decision_image(const Image<I>& input_, + const object_links<L>& links, + const object_links<L>& filtered_links) + { + trace::entering("scribo::debug::links_decision_image"); + const I& input = exact(input_); + + const object_image(L)& objects = links.object_image_(); + + mln_precondition(input.is_valid()); + mln_precondition(objects.is_valid()); + mln_precondition(links.is_valid()); + mln_precondition(filtered_links.is_valid()); + mln_precondition(links.size() == filtered_links.size()); + mln_precondition(links.object_image_() != filtered_links.object_image_()); + /// Fixme: check that objects has been computed from input. + + image2d<value::rgb8> + links_decision_image = data::convert(value::rgb8(), input); + + for_all_components(i, objects.bboxes()) + mln::draw::box(links_decision_image, objects.bbox(i), literal::blue); + + // Computing mass centers. + mln::util::array<mln_result(accu::center<mln_psite(I)>)> + mass_centers = labeling::compute(accu::meta::center(), + objects, objects.nlabels()); + + for (unsigned i = 1; i < links.size(); ++i) + { + + if (links[i] != i) + { + value::rgb8 value = literal::green; + if (links[i] != filtered_links[i]) + value = literal::red; + + mln_site(I) + p1 = mass_centers[i], + p2 = p1 + mln::right; // FIXME: not generic + + while (objects(p2) != links[i] && objects.domain().has(p2)) + ++p2.col(); + + mln::draw::line(links_decision_image, + p1, + p2, + value); + } + } + + trace::exiting("scribo::debug::links_decision_image"); + return links_decision_image; + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace scribo::debug + +} // end of namespace scribo + + +#endif // ! SCRIBO_DEBUG_LINKS_DECISION_IMAGE_HH diff --git a/scribo/debug/save_object_diff.hh b/scribo/debug/save_object_diff.hh new file mode 100644 index 0000000..e4f49f4 --- /dev/null +++ b/scribo/debug/save_object_diff.hh @@ -0,0 +1,98 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef SCRIBO_DEBUG_SAVE_OBJECT_DIFF_HH +# define SCRIBO_DEBUG_SAVE_OBJECT_DIFF_HH + +/// \file +/// +/// Show the difference between two object images. + +# include <mln/core/image/image2d.hh> +# include <mln/core/concept/image.hh> +# include <mln/data/fill.hh> +# include <mln/labeling/colorize.hh> +# include <mln/value/rgb8.hh> +# include <mln/io/ppm/save.hh> +# include <mln/literal/black.hh> +# include <mln/literal/colors.hh> +# include <mln/pw/all.hh> +# include <mln/core/image/dmorph/image_if.hh> + +# include <scribo/core/macros.hh> +# include <scribo/core/object_image.hh> + +namespace scribo +{ + + namespace debug + { + + using namespace mln; + + /*! \brief Show the difference between two object images. + + \param[in] lbl An object image. + \param[in] lbl_2 Another object image. + \param[in] filename The output filename. + + */ + template <typename L, typename L2> + void + save_object_diff(const object_image(L)& lbl, const object_image(L2)& lbl_2, + const std::string& filename); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename L, typename L2> + void + save_object_diff(const object_image(L)& lbl, const object_image(L2)& lbl_2, + const std::string& filename) + { + image2d<value::rgb8> output; + initialize(output, lbl_2); + + data::fill(output, literal::black); + + for_all_components(i, lbl.bboxes()) + data::fill(((output | lbl.bbox(i)).rw() | (pw::value(lbl) == i)).rw(), literal::red); + + for_all_components(i, lbl_2.bboxes()) + data::fill(((output | lbl_2.bbox(i)).rw() | (pw::value(lbl_2) == i)).rw(), literal::green); + + io::ppm::save(output, filename); + } + + +# endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace scribo::debug + +} // end of namespace scribo + +#endif // ! SCRIBO_DEBUG_SAVE_OBJECT_DIFF_HH diff --git a/scribo/debug/several_links_decision_image.hh b/scribo/debug/several_links_decision_image.hh new file mode 100644 index 0000000..ca70d44 --- /dev/null +++ b/scribo/debug/several_links_decision_image.hh @@ -0,0 +1,185 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef SCRIBO_DEBUG_SEVERAL_LINKS_DECISION_IMAGE_HH +# define SCRIBO_DEBUG_SEVERAL_LINKS_DECISION_IMAGE_HH + +/// \file +/// +/// Save a color image showing the difference between to object groups. + +# include <mln/core/concept/image.hh> +# include <mln/accu/center.hh> +# include <mln/data/convert.hh> +# include <mln/value/rgb8.hh> +# include <mln/literal/colors.hh> +# include <mln/util/array.hh> + +# include <scribo/core/object_groups.hh> +# include <scribo/draw/bounding_boxes.hh> + + +namespace scribo +{ + + namespace debug + { + + using namespace mln; + + /// FIXME: DOC! + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + several_links_decision_image(const Image<I>& input_, + const object_links<L>& links, + const object_links<L>& filtered_links); + + +# ifndef MLN_INCLUDE_ONLY + + + + namespace internal + { + + template <typename L, typename I> + bool + draw_line(const L& objects, I& output, + unsigned link, + const mln_site(L)& p1, const mln_site(L)& p2, + const mln_value(I)& value) + { + + if (objects.domain().has(p2)) + if (objects(p2) == link) + { + mln::draw::line(output, p1, p2, value); + return true; + } + return false; + } + + } + + + + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + several_links_decision_image(const Image<I>& input_, + const object_links<L>& links, + const object_links<L>& filtered_links) + { + trace::entering("scribo::debug::several_links_decision_image"); + const I& input = exact(input_); + + const object_image(L)& objects = links.object_image_(); + + mln_precondition(input.is_valid()); + mln_precondition(objects.is_valid()); + mln_precondition(links.is_valid()); + mln_precondition(filtered_links.is_valid()); + mln_precondition(links.size() == filtered_links.size()); + mln_precondition(links.object_image_() != filtered_links.object_image_()); + /// Fixme: check that objects has been computed from input. + + image2d<value::rgb8> + links_decision_image = data::convert(value::rgb8(), input); + + for_all_components(i, objects.bboxes()) + mln::draw::box(links_decision_image, objects.bbox(i), literal::blue); + + // Computing mass centers. + mln::util::array<mln_result(accu::center<mln_psite(I)>)> + mass_centers = labeling::compute(accu::meta::center(), + objects, objects.nlabels()); + + for (unsigned i = 1; i < links.size(); ++i) + { + + if (links[i] != i) + { + value::rgb8 value = literal::green; + if (links[i] != filtered_links[i]) + value = literal::red; + + mln_site(L) c = objects.bbox(i).center(); + + // Right link from the top anchor. + mln_site(L) a1 = c; + a1.row() = objects.bbox(i).pmin().row() + + (c.row() - objects.bbox(i).pmin().row()) / 4; + + // Right link from the central site + mln_site(I) p1 = mass_centers[i]; + + // Right link from the bottom anchor. + mln_site(L) a2 = c; + a2.row() = objects.bbox(i).pmax().row() + - (c.row() - objects.bbox(i).pmin().row()) / 4; + + mln_site(L) + a1_bak = a1, + a2_bak = a2; + + mln_site(L) tmp; + while(objects.domain().has(a1) + || objects.domain().has(a2) + || objects.domain().has(p1)) + { + if (internal::draw_line(objects, links_decision_image, links[i], + a1_bak, a1, value)) + break; + else + ++a1.col(); + + if (internal::draw_line(objects, links_decision_image, links[i], + mass_centers[i], p1, value)) + break; + else + ++p1.col(); + + if (internal::draw_line(objects, links_decision_image, links[i], + a2_bak, a2, value)) + break; + else + ++a2.col(); + + } + } + } + + trace::exiting("scribo::debug::several_links_decision_image"); + return links_decision_image; + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace scribo::debug + +} // end of namespace scribo + + +#endif // ! SCRIBO_DEBUG_SEVERAL_LINKS_DECISION_IMAGE_HH -- 1.5.6.5
participants (1)
-
Guillaume Lazzara