* scribo/toolchain/text_in_doc_preprocess.hh: New.
* src/text_in_doc_preprocess.cc: Make use of this new toolchain.
---
scribo/ChangeLog | 8 +
scribo/scribo/toolchain/text_in_doc_preprocess.hh | 152 +++++++++++++++++++++
scribo/src/text_in_doc_preprocess.cc | 41 ++----
3 files changed, 170 insertions(+), 31 deletions(-)
create mode 100644 scribo/scribo/toolchain/text_in_doc_preprocess.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 8b7d143..f839cc5 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,13 @@
2010-08-25 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add a preprocessing toolchain.
+
+ * scribo/toolchain/text_in_doc_preprocess.hh: New.
+
+ * src/text_in_doc_preprocess.cc: Make use of this new toolchain.
+
+2010-08-25 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Fix namespace ambiguities.
* scribo/binarization/sauvola_ms.hh,
diff --git a/scribo/scribo/toolchain/text_in_doc_preprocess.hh
b/scribo/scribo/toolchain/text_in_doc_preprocess.hh
new file mode 100644
index 0000000..cff99f7
--- /dev/null
+++ b/scribo/scribo/toolchain/text_in_doc_preprocess.hh
@@ -0,0 +1,152 @@
+// Copyright (C) 2010 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_TOOLCHAIN_TEXT_IN_DOC_PREPROCESS_HH
+# define SCRIBO_TOOLCHAIN_TEXT_IN_DOC_PREPROCESS_HH
+
+/// \file
+///
+/// \brief Preprocess a document before looking for its content.
+
+
+#include <mln/core/concept/image.hh>
+#include <mln/logical/not.hh>
+
+#include <scribo/binarization/sauvola_ms.hh>
+
+#include <scribo/preprocessing/split_bg_fg.hh>
+#include <scribo/preprocessing/deskew.hh>
+
+
+namespace scribo
+{
+
+ namespace toolchain
+ {
+
+ using namespace mln;
+
+ /*! \brief Preprocess a document before looking for its content.
+
+ \param[in] input An image.
+ \param[in] enable_fg_bg Enable/Disable background removal.
+
+ If \p enable_fg_bg is set to 'True' then a background removal is
+ performed. Its parameter lambda is automatically set according
+ to the input image size.
+
+ */
+ template <typename I>
+ mln_ch_value(I,bool)
+ text_in_doc_preprocess(const Image<I>& input, bool enable_fg_bg);
+
+ /*! \brief Preprocess a document before looking for its content.
+
+ \param[in] input An image.
+ \param[in] lambda Parameter to the background removal.
+
+ If lambda is set to '0' no background removal is
+ performed. Otherwise, a background removal is performed with the
+ given \p lambda value.
+
+ */
+ template <typename I>
+ mln_ch_value(I,bool)
+ text_in_doc_preprocess(const Image<I>& input, unsigned lambda);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ mln_ch_value(I,bool)
+ text_in_doc_preprocess(const Image<I>& input_, bool enable_fg_bg)
+ {
+ trace::entering("scribo::toolchain::text_in_doc_preprocess");
+
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ unsigned lambda = 0;
+ if (enable_fg_bg)
+ lambda = 1.2 * (input.nrows() + input.ncols());
+
+ mln_ch_value(I,bool) output = text_in_doc_preprocess(input, lambda);
+
+ trace::exiting("scribo::toolchain::text_in_doc_preprocess");
+ return output;
+ }
+
+
+ template <typename I>
+ mln_ch_value(I,bool)
+ text_in_doc_preprocess(const Image<I>& input_, unsigned lambda)
+ {
+ trace::entering("scribo::toolchain::text_in_doc_preprocess");
+
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
+ mln_concrete(I) input_rgb = input;
+
+ // Extract foreground
+ if (lambda != 0)
+ {
+ std::cout << "Extracting foreground..." << std::endl;
+ input_rgb = preprocessing::split_bg_fg(input, lambda, 32).second();
+ }
+
+ // Convert to Gray level image.
+ mln_ch_value(I,value::int_u8)
+ input_gl = data::transform(input_rgb,
+ mln::fun::v2v::rgb_to_int_u<8>());
+
+
+ // Deskewing
+ std::cout << "Deskew if needed..." << std::endl;
+ input_gl = preprocessing::deskew(input_gl);
+
+ // Binarize foreground to use it in the processing chain.
+ std::cout << "Binarizing foreground..." << std::endl;
+ mln_ch_value(I,bool)
+ input_bin = scribo::binarization::sauvola_ms(input_gl, 101, 3);
+
+ logical::not_inplace(input_bin);
+
+ trace::exiting("scribo::toolchain::text_in_doc_preprocess");
+ return input_bin;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace scribo::toolchain
+
+} // end of namespace scribo
+
+
+#endif // SCRIBO_TOOLCHAIN_TEXT_IN_DOC_PREPROCESS_HH
+
diff --git a/scribo/src/text_in_doc_preprocess.cc b/scribo/src/text_in_doc_preprocess.cc
index 27ed9ed..b731272 100644
--- a/scribo/src/text_in_doc_preprocess.cc
+++ b/scribo/src/text_in_doc_preprocess.cc
@@ -34,17 +34,9 @@
#include <mln/value/rgb8.hh>
-#include <mln/logical/not.hh>
-
-#include <scribo/binarization/sauvola_ms.hh>
-
#include <scribo/debug/usage.hh>
-#include <scribo/preprocessing/split_bg_fg.hh>
-#include <scribo/preprocessing/deskew.hh>
-
-
-#include <mln/io/pgm/all.hh>
+#include <scribo/toolchain/text_in_doc_preprocess.hh>
const char *args_desc[][2] =
@@ -74,30 +66,17 @@ int main(int argc, char* argv[])
unsigned lambda;
if (argc == 5)
lambda = atoi(argv[4]);
- else
- lambda = 1.2 * (input_rgb.nrows() + input_rgb.ncols());
- // Extract foreground
- if (argc >= 4 && atoi(argv[3]) == 1)
- {
- std::cout << "Extracting foreground..." << std::endl;
- input_rgb = preprocessing::split_bg_fg(input_rgb, lambda, 32).second();
- }
+ bool remove_bg = false;
+ if (argc >= 4)
+ remove_bg = (atoi(argv[3]) == 1);
- // Convert to Gray level image.
- image2d<value::int_u8>
- input_gl = data::transform(input_rgb, mln::fun::v2v::rgb_to_int_u<8>());
+ image2d<bool> output;
+ if (argc == 5 && remove_bg)
+ output = toolchain::text_in_doc_preprocess(input_rgb, lambda);
+ else
+ output = toolchain::text_in_doc_preprocess(input_rgb, remove_bg);
- // Deskewing
- std::cout << "Deskew if needed..." << std::endl;
- input_gl = preprocessing::deskew(input_gl);
-
- // Binarize foreground to use it in the processing chain.
- std::cout << "Binarizing foreground..." << std::endl;
- image2d<bool> input_bin = scribo::binarization::sauvola_ms(input_gl, 101, 3);
-
- logical::not_inplace(input_bin);
-
- mln::io::pbm::save(input_bin, argv[2]);
+ mln::io::pbm::save(output, argv[2]);
}
--
1.5.6.5