last-svn-commit-47-gd7f2adc Small fixes.

* binarization/sauvola_ms.hh: Remove a useless include. * debug/usage.hh: Move description output. * io/xml/save_text_lines.hh: Fix invalid xml output. * primitive/link/internal/link_ms_dmax_ratio_base.hh, * primitive/link/internal/link_single_dmax_ratio_base.hh: update distance criterion. * scribo.mk: Change compilation flags. * src/afp/components.hh: Merge data in only one array. * tests/filter/Makefile.am, * tests/filter/objects_with_holes.cc: New test. * text/clean.hh: use upsampling::hq4x instead of upsampling::hq2x. --- scribo/ChangeLog | 139 ++++++++++++-------- scribo/binarization/sauvola_ms.hh | 1 - scribo/debug/usage.hh | 8 +- scribo/io/xml/save_text_lines.hh | 40 ++++-- .../link/internal/link_ms_dmax_ratio_base.hh | 10 +- .../link/internal/link_single_dmax_ratio_base.hh | 4 +- scribo/scribo.mk | 3 +- scribo/src/afp/components.hh | 72 +--------- scribo/tests/filter/Makefile.am | 3 + scribo/tests/filter/objects_with_holes.cc | 49 +++++++ scribo/text/clean.hh | 12 +- 11 files changed, 183 insertions(+), 158 deletions(-) create mode 100644 scribo/tests/filter/objects_with_holes.cc diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 49045c7..7af1c38 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,28 @@ 2010-02-19 Guillaume Lazzara <z@lrde.epita.fr> + Small fixes. + + * binarization/sauvola_ms.hh: Remove a useless include. + + * debug/usage.hh: Move description output. + + * io/xml/save_text_lines.hh: Fix invalid xml output. + + * primitive/link/internal/link_ms_dmax_ratio_base.hh, + * primitive/link/internal/link_single_dmax_ratio_base.hh: update + distance criterion. + + * scribo.mk: Change compilation flags. + + * src/afp/components.hh: Merge data in only one array. + + * tests/filter/Makefile.am, + * tests/filter/objects_with_holes.cc: New test. + + * text/clean.hh: use upsampling::hq4x instead of upsampling::hq2x. + +2010-02-19 Guillaume Lazzara <z@lrde.epita.fr> + Keep updating code according to last changed in core classes. * debug/decision_image.hh, @@ -32,15 +55,15 @@ Improve core classes. - * scribo/core/component_info.hh, - * scribo/core/component_set.hh, - * scribo/core/line_info.hh, - * scribo/core/line_set.hh, - * scribo/core/object_groups.hh: Add more methods and constructors. + * core/component_info.hh, + * core/component_set.hh, + * core/line_info.hh, + * core/line_set.hh, + * core/object_groups.hh: Add more methods and constructors. - * scribo/core/macros.hh: Add a new macro. + * core/macros.hh: Add a new macro. - * scribo/core/tag/line.hh: Add more enums. + * core/tag/line.hh: Add more enums. 2010-02-19 Guillaume Lazzara <z@lrde.epita.fr> @@ -51,46 +74,46 @@ Introduce new Scribo core classes and start using them. - * scribo/core/component_info.hh, - * scribo/core/component_set.hh, - * scribo/core/line_info.hh, - * scribo/core/line_set.hh, - * scribo/core/macros.hh, - * scribo/core/object_groups.hh, - * scribo/core/object_links.hh, - * scribo/core/tag/anchor.hh, - * scribo/core/tag/component.hh, - * scribo/core/tag/line.hh: New core classes. - - * scribo/core/object_image.hh: Remove. - - * scribo/core/anchors.hh - * scribo/primitive/extract/objects.hh: Rename as... - - * scribo/primitive/link/internal/compute_anchor.hh, - * scribo/primitive/extract/components.hh: ... this. - - * scribo/draw/bounding_box_links.hh, - * scribo/filter/object_links_bbox_h_ratio.hh, - * scribo/filter/object_links_bbox_ratio.hh, - * scribo/filter/objects_small.hh, - * scribo/fun/v2b/objects_small_filter.hh, - * scribo/primitive/group/apply.hh, - * scribo/primitive/group/from_single_link.hh, - * scribo/primitive/internal/find_root.hh, - * scribo/primitive/internal/init_link_array.hh, - * scribo/primitive/link/compute.hh, - * scribo/primitive/link/internal/find_link.hh, - * scribo/primitive/link/internal/find_several_links.hh, - * scribo/primitive/link/internal/link_functor_base.hh, - * scribo/primitive/link/internal/link_several_dmax_base.hh, - * scribo/primitive/link/internal/link_single_dmax_base.hh, - * scribo/primitive/link/internal/link_single_dmax_ratio_base.hh, - * scribo/primitive/link/merge_double_link.hh, - * scribo/primitive/link/with_single_left_link_dmax_ratio.hh, - * scribo/primitive/link/with_single_right_link_bottom.hh, - * scribo/primitive/link/with_single_right_link_dmax_ratio.hh, - * scribo/primitive/link/with_single_right_link_top.hh: Make use of + * core/component_info.hh, + * core/component_set.hh, + * core/line_info.hh, + * core/line_set.hh, + * core/macros.hh, + * core/object_groups.hh, + * core/object_links.hh, + * core/tag/anchor.hh, + * core/tag/component.hh, + * core/tag/line.hh: New core classes. + + * core/object_image.hh: Remove. + + * core/anchors.hh + * primitive/extract/objects.hh: Rename as... + + * primitive/link/internal/compute_anchor.hh, + * primitive/extract/components.hh: ... this. + + * draw/bounding_box_links.hh, + * filter/object_links_bbox_h_ratio.hh, + * filter/object_links_bbox_ratio.hh, + * filter/objects_small.hh, + * fun/v2b/objects_small_filter.hh, + * primitive/group/apply.hh, + * primitive/group/from_single_link.hh, + * primitive/internal/find_root.hh, + * primitive/internal/init_link_array.hh, + * primitive/link/compute.hh, + * primitive/link/internal/find_link.hh, + * primitive/link/internal/find_several_links.hh, + * primitive/link/internal/link_functor_base.hh, + * primitive/link/internal/link_several_dmax_base.hh, + * primitive/link/internal/link_single_dmax_base.hh, + * primitive/link/internal/link_single_dmax_ratio_base.hh, + * primitive/link/merge_double_link.hh, + * primitive/link/with_single_left_link_dmax_ratio.hh, + * primitive/link/with_single_right_link_bottom.hh, + * primitive/link/with_single_right_link_dmax_ratio.hh, + * primitive/link/with_single_right_link_top.hh: Make use of the new core classes. 2010-02-19 Guillaume Lazzara <z@lrde.epita.fr> @@ -180,18 +203,18 @@ 2010-02-19 Guillaume Lazzara <z@lrde.epita.fr> - * scribo/src/text_in_photo_ppm.cc: Improve output. + * src/text_in_photo_ppm.cc: Improve output. 2010-02-19 Guillaume Lazzara <z@lrde.epita.fr> Cleanup and avoid warnings in Sauvola related files. - * scribo/binarization/sauvola_ms.hh, - * scribo/binarization/sauvola_threshold.hh, - * scribo/canvas/integral_browsing.hh, - * scribo/src/binarization/sauvola_ms.cc, - * scribo/src/binarization/sauvola_pgm.cc,x - * scribo/subsampling/integral_single_image.hh: Cleanup and avoir + * binarization/sauvola_ms.hh, + * binarization/sauvola_threshold.hh, + * canvas/integral_browsing.hh, + * src/binarization/sauvola_ms.cc, + * src/binarization/sauvola_pgm.cc,x + * subsampling/integral_single_image.hh: Cleanup and avoir warnings. 2009-12-15 Guillaume Lazzara <z@lrde.epita.fr> @@ -316,17 +339,17 @@ Add a new example in Scribo. - * scribo/src/primitive/extract/Makefile.am: Add a new target. + * src/primitive/extract/Makefile.am: Add a new target. - * scribo/src/primitive/extract/lines_pattern.cc: New. + * src/primitive/extract/lines_pattern.cc: New. 2009-11-03 Guillaume Lazzara <z@lrde.epita.fr> First draft of multiscale Sauvola's binarization. - * scribo/src/binarization/Makefile.am: Add new target. + * src/binarization/Makefile.am: Add new target. - * scribo/src/binarization/sauvola_ms.cc: New. + * src/binarization/sauvola_ms.cc: New. 2009-11-03 Guillaume Lazzara <z@lrde.epita.fr> diff --git a/scribo/binarization/sauvola_ms.hh b/scribo/binarization/sauvola_ms.hh index fce5832..858a1d3 100644 --- a/scribo/binarization/sauvola_ms.hh +++ b/scribo/binarization/sauvola_ms.hh @@ -43,7 +43,6 @@ # include <scribo/subsampling/integral_single_image.hh> # include <scribo/core/macros.hh> -# include <scribo/core/object_image.hh> # include <scribo/binarization/sauvola_threshold.hh> # include <scribo/binarization/internal/first_pass_functor.hh> diff --git a/scribo/debug/usage.hh b/scribo/debug/usage.hh index 131a338..e3872a9 100644 --- a/scribo/debug/usage.hh +++ b/scribo/debug/usage.hh @@ -55,13 +55,13 @@ namespace scribo usage(char* argv[], const char *desc, const char* args, const char*args_desc[][2], const char *out_desc) { - std::cout << std::endl - << desc << std::endl - << std::endl; - std::cout << "-----------" << std::endl; std::cout << "Usage: " << argv[0] << " " << args << std::endl << std::endl; + std::cout << "-----------" << std::endl; + std::cout << std::endl + << desc << std::endl + << std::endl; for (unsigned i = 0; args_desc[i][0] != 0; ++i) std::cout << " " << args_desc[i][0] << ": " << args_desc[i][1] diff --git a/scribo/io/xml/save_text_lines.hh b/scribo/io/xml/save_text_lines.hh index c86f121..22aa3d9 100644 --- a/scribo/io/xml/save_text_lines.hh +++ b/scribo/io/xml/save_text_lines.hh @@ -81,17 +81,17 @@ namespace scribo } file << "<?xml version=\"1.0\"?>" << std::endl; - file << "<pcGts xmlns=\"http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16 http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16/pagecontent.xsd\" pcGtsId=\"" << input_name << "\">" << std::endl; + file << "<PcGts xmlns=\"http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16 http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16/pagecontent.xsd\" pcGtsId=\"" << input_name << "\">" << std::endl; - file << " <pcMetadata>" << std::endl; - file << " <pcCreator>LRDE</pcCreator>" << std::endl; - file << " <pcCreated/>" << std::endl; - file << " <pcLastChange/>" << std::endl; - file << " <pcComments/>" << std::endl; - file << " </pcMetadata>" << std::endl; + file << " <Metadata>" << std::endl; + file << " <Creator>LRDE</pcCreator>" << std::endl; + file << " <Created/>" << std::endl; + file << " <LastChange/>" << std::endl; + file << " <Comments>Generated by Scribo from Olena.</pcComments>" << std::endl; + file << " </Metadata>" << std::endl; - file << " <page image_filename=\"" << input_name + file << " <Page image_filename=\"" << input_name << "\" image_width=\"" << lines.component_set_().labeled_image().ncols() << "\" image_height=\"" << lines.component_set_().labeled_image().nrows() << "\">" << std::endl; @@ -99,11 +99,21 @@ namespace scribo for_all_lines(l, lines) { file << " <text_region id=\"" << lines(l).id() - << "\" txt_orientation=\"0.000\" " - << "txt_reading_orientation=\"0.000\" " - << "txt_reading_direction=\"Left_To_Right\" " - << "txt_reverse_video=\"No\" " - << "txt_indented=\"No\">" + << "\" txt_orientation=\"" << lines(l).orientation() + << "\" txt_reading_orientation=\"" << lines(l).reading_orientation() + << "\" txt_reading_direction=\"" << lines(l).reading_direction() + << "\" txt_reverse_video=\"" << (lines(l).reverse_video() ? "true" : "false") + << "\" txt_indented=\"" << (lines(l).indented() ? "true" : "false") + // EXTENSIONS - Not officially supported + << "\" baseline=\"" << lines(l).baseline() + << "\" median=\"" << lines(l).median() + << "\" x_height=\"" << lines(l).x_height() + << "\" d_height=\"" << lines(l).d_height() + << "\" a_height=\"" << lines(l).a_height() + << "\" char_space=\"" << lines(l).char_space() + << "\" char_width=\"" << lines(l).char_width() + // End of EXTENSIONS + << "\">" << std::endl; file << " <coords>" << std::endl @@ -123,8 +133,8 @@ namespace scribo } file << " </text_region>" << std::endl; - file << " </page>" << std::endl; - file << "</pcGts>" << std::endl; + file << " </Page>" << std::endl; + file << "</PcGts>" << std::endl; diff --git a/scribo/primitive/link/internal/link_ms_dmax_ratio_base.hh b/scribo/primitive/link/internal/link_ms_dmax_ratio_base.hh index 8eca53d..915296d 100644 --- a/scribo/primitive/link/internal/link_ms_dmax_ratio_base.hh +++ b/scribo/primitive/link/internal/link_ms_dmax_ratio_base.hh @@ -147,11 +147,11 @@ namespace scribo unsigned current_object) { float - w = (this->objects_.bbox(current_object).pmax().col() - - this->objects_.bbox(current_object).pmin().col()), - h = (this->objects_.bbox(current_object).pmax().row() - - this->objects_.bbox(current_object).pmin().row()); - dmax_ = (w / 2.0f) + (dmax_ratio_ * math::max(w, h)); + w = this->objects_.bbox(current_object).width(); +// h = (this->objects_.bbox(current_object).pmax().row() +// - this->objects_.bbox(current_object).pmin().row()); +// dmax_ = (w / 2.0f) + (dmax_ratio_ * math::max(w, h)); + dmax_ = (w / 2.0f) + (dmax_ratio_ * w); } diff --git a/scribo/primitive/link/internal/link_single_dmax_ratio_base.hh b/scribo/primitive/link/internal/link_single_dmax_ratio_base.hh index 65806cc..1a4cb73 100644 --- a/scribo/primitive/link/internal/link_single_dmax_ratio_base.hh +++ b/scribo/primitive/link/internal/link_single_dmax_ratio_base.hh @@ -151,7 +151,9 @@ namespace scribo float w = this->components_.info(current_object).bbox().width(), h = this->components_.info(current_object).bbox().height(); - dmax_ = (w / 2.0f) + (dmax_ratio_ * math::max(w, h)); +// dmax_ = (w / 2.0f) + (dmax_ratio_ * math::max(w, h)); +// dmax_ = (w / 2.0f) + (dmax_ratio_ * w); + dmax_ = (w / 2.0f) + (h + w); } diff --git a/scribo/scribo.mk b/scribo/scribo.mk index 62ffcad..13520d4 100644 --- a/scribo/scribo.mk +++ b/scribo/scribo.mk @@ -18,4 +18,5 @@ # Add path to Scribo's headers AM_CPPFLAGS = -I$(top_srcdir)/ -I$(top_builddir)/ -I$(top_srcdir)/milena -I$(top_builddir)/milena -AM_CXXFLAGS = -DNDEBUG -O2 \ No newline at end of file +AM_CXXFLAGS = -DNDEBUG -O2 -Wall -Wextra +#AM_CXXFLAGS = -O0 -ggdb -Wall -Wextra -DNDEBUG diff --git a/scribo/src/afp/components.hh b/scribo/src/afp/components.hh index 7db8572..fd463eb 100644 --- a/scribo/src/afp/components.hh +++ b/scribo/src/afp/components.hh @@ -82,13 +82,11 @@ namespace mln }; - template <typename V> image2d<V> extract_components(const image2d<bool>& input, V& nlabels, - util::array<box2d>& bboxes, - util::array<point2d>& mass_centers) + util::array<std::pair<box2d, std::pair<point2d, unsigned> > >& attribs) { typedef image2d<bool> I; @@ -97,8 +95,7 @@ namespace mln nrows = input.nrows(), ncols = input.ncols(); - bboxes.resize(1); - mass_centers.resize(1); + attribs.resize(1); image2d<info> data; image2d<V> label; @@ -175,9 +172,10 @@ namespace mln { label.element(p) = ++current_label; - bboxes.append(box2d(dta.p_min, dta.p_max)); - mass_centers.append(point2d(dta.row_sum / dta.card, - dta.col_sum / dta.card)); + attribs.append( + std::make_pair(box2d(dta.p_min, dta.p_max), + std::make_pair(point2d(dta.row_sum / dta.card, + dta.col_sum / dta.card), dta.card))); } } else @@ -195,61 +193,3 @@ namespace mln } // mln - -// void usage(char* argv[]) -// { -// std::cerr << argv[0] << " input.pbm output.pgm" << std::endl; -// std::abort(); -// } - - -// int main(int argc, char* argv[]) -// { -// if (argc != 3) -// usage(argv); - -// using namespace mln; - -// image2d<bool> input; -// io::pbm::load(input, argv[1]); - - -// image2d<unsigned> ref; - -// // { -// // util::timer t; -// // t.start(); - -// // unsigned nlabels; -// // ref = labeling::foreground(input, c4(), nlabels); - -// // float ts = t.stop(); -// // std::cout << "tufa: " << ts << " " << nlabels << std::endl; -// // } - -// { -// util::timer t; -// t.start(); - - -// util::array<box2d> bboxes(1, box2d(1,1)); -// util::array<point2d> mass_centers(1, point2d(0,0)); - -// // util::array<std::pair<box2d, point2d> > data_out(1); -// unsigned nlabels; -// image2d<unsigned> comps = extract_components(input, nlabels, bboxes, mass_centers); - -// float ts = t.stop(); -// std::cout << ts << " " << nlabels << std::endl; - -// // std::cout << bboxes << std::endl; -// // std::cout << mass_centers << std::endl; - -// // if (comps != ref) -// // std::cout << "diff" << std::endl; - -// io::pgm::save(labeling::wrap(value::int_u8(), comps), -// argv[2]); -// } - -// } diff --git a/scribo/tests/filter/Makefile.am b/scribo/tests/filter/Makefile.am index fd3299e..a023e4e 100644 --- a/scribo/tests/filter/Makefile.am +++ b/scribo/tests/filter/Makefile.am @@ -20,8 +20,11 @@ include $(top_srcdir)/scribo/tests/tests.mk check_PROGRAMS = \ + objects_with_holes \ small_and_large_bboxes + +objects_with_holes_SOURCES = objects_with_holes.cc small_and_large_bboxes_SOURCES = small_and_large_bboxes.cc TESTS = $(check_PROGRAMS) diff --git a/scribo/tests/filter/objects_with_holes.cc b/scribo/tests/filter/objects_with_holes.cc new file mode 100644 index 0000000..5396962 --- /dev/null +++ b/scribo/tests/filter/objects_with_holes.cc @@ -0,0 +1,49 @@ +#include <mln/core/image/image2d.hh> +#include <mln/core/alias/neighb2d.hh> +#include <mln/io/pbm/load.hh> +#include <mln/value/label_8.hh> + +#include <mln/util/timer.hh> +#include <mln/labeling/background.hh> +#include <mln/value/label_32.hh> +#include <mln/data/convert.hh> +#include <mln/data/wrap.hh> + +#include <mln/debug/println.hh> + + + +#include <scribo/filter/objects_with_holes.hh> +#include <scribo/primitive/extract/objects.hh> + +int main(int argc, char *argv[]) +{ + using namespace mln; + + if (argc != 2) + return 1; + + image2d<bool> input; + io::pbm::load(input, argv[1]); + + value::label_16 nlabels; + typedef object_image(image2d<value::label_16>) O; + O objects = scribo::primitive::extract::objects(input, c8(), nlabels); + + util::timer timer; + timer.start(); + + value::label_16 nbglabels; + image2d<bool> bin = data::convert(bool(), objects); + image2d<value::label_16> lbl_bg = labeling::background(bin, c8(), nbglabels); + float t_ = timer; + std::cout << t_ << std::endl; + + timer.restart(); + O out = scribo::filter::objects_with_holes(objects, 2, 1); +// debug::println(out); + + t_ = timer; + std::cout << t_ << std::endl; + io::pgm::save(data::wrap(value::label_8(), out), "out.pgm"); +} diff --git a/scribo/text/clean.hh b/scribo/text/clean.hh index cd8657e..ba200fc 100644 --- a/scribo/text/clean.hh +++ b/scribo/text/clean.hh @@ -65,8 +65,7 @@ #include <mln/io/pgm/all.hh> #include <sandbox/inim/2009/ocr/resize.hh> -#include <sandbox/fabien/mln/upsampling/hq4x.hh> - +#include <sandbox/fabien/mln/upsampling/hq2x.hh> namespace scribo { @@ -92,7 +91,6 @@ namespace scribo # ifndef MLN_INCLUDE_ONLY - template <typename I, typename W> mln_concrete(I) clean(const Image<I>& input_, const Weighted_Window<W>& dmap_win_) @@ -111,11 +109,11 @@ namespace scribo // Resize typedef image2d<value::rgb8> J; J tmp = data::convert(value::rgb8(), input); - J clarge = mln::upsampling::hq4x(tmp); + J clarge = tmp;//mln::upsampling::hq2x(tmp); (FIXME: re-enable) //FIXME: not generic! - if (input.domain().pmax()[0] - input.domain().pmin()[0] <= 10) - clarge = mln::upsampling::hq4x(clarge); +// if (input.domain().pmax()[0] - input.domain().pmin()[0] <= 10) +// clarge = mln::upsampling::hq4x(clarge); I input_large = data::convert(bool(), clarge); @@ -139,7 +137,7 @@ namespace scribo // io::pgm::save(arith::revert(blur), "blur_revert.pgm"); // io::pgm::save(blur, "gaussian.pgm"); // io::pbm::save(input_large, mln::debug::filename("input_large_4x.pbm")); -// io::pbm::save(K, mln::debug::filename("K.pbm")); +// io::pbm::save(K, mln::debug::filename("K.pbm")); // io::pbm::save(skel_on_gaussian, mln::debug::filename("skeleton_on_gaussian.pbm")); // io::pbm::save(dilate_on_gaussian, mln::debug::filename("dilation_on_gaussian.pbm")); -- 1.5.6.5
participants (1)
-
Guillaume Lazzara