* preprocessing/crop.hh,
* preprocessing/crop_without_localization.hh: new routines.
* tests/preprocessing/Makefile.am,
* tests/preprocessing/crop.cc,
* tests/preprocessing/crop_without_localization.cc: Associated
tests.
---
scribo/ChangeLog | 12 +++
.../dmax_default.hh => preprocessing/crop.hh} | 61 ++++++++--------
.../crop_without_localization.hh} | 73 +++++++++++---------
scribo/tests/preprocessing/Makefile.am | 10 ++-
scribo/tests/preprocessing/{unskew.cc => crop.cc} | 21 ++++--
.../{unskew.cc => crop_without_localization.cc} | 23 +++++--
6 files changed, 121 insertions(+), 79 deletions(-)
copy scribo/{primitive/link/internal/dmax_default.hh => preprocessing/crop.hh} (56%)
copy scribo/{binarization/global_threshold.hh =>
preprocessing/crop_without_localization.hh} (50%)
copy scribo/tests/preprocessing/{unskew.cc => crop.cc} (77%)
copy scribo/tests/preprocessing/{unskew.cc => crop_without_localization.cc} (73%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index eaa3502..c5476be 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,17 @@
2010-05-25 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add crop tools.
+
+ * preprocessing/crop.hh,
+ * preprocessing/crop_without_localization.hh: new routines.
+
+ * tests/preprocessing/Makefile.am,
+ * tests/preprocessing/crop.cc,
+ * tests/preprocessing/crop_without_localization.cc: Associated
+ tests.
+
+2010-05-25 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Small fixes.
* core/object_groups.hh: Fix an invalid size.
diff --git a/scribo/primitive/link/internal/dmax_default.hh
b/scribo/preprocessing/crop.hh
similarity index 56%
copy from scribo/primitive/link/internal/dmax_default.hh
copy to scribo/preprocessing/crop.hh
index 1444dfe..c289f86 100644
--- a/scribo/primitive/link/internal/dmax_default.hh
+++ b/scribo/preprocessing/crop.hh
@@ -23,61 +23,62 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_DEFAULT_HH
-# define SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_DEFAULT_HH
+#ifndef SCRIBO_PREPROCESSING_CROP_HH
+# define SCRIBO_PREPROCESSING_CROP_HH
+
+# include <mln/core/concept/image.hh>
+# include <mln/data/paste.hh>
/// \file
///
-/// Default class for dmax functors.
-
-# include <scribo/primitive/link/internal/dmax_functor_base.hh>
+/// \brief Crop an image preserving the localization.
namespace scribo
{
- namespace primitive
+ namespace preprocessing
{
- namespace link
- {
+ using namespace mln;
- namespace internal
- {
+ /*! \brief crop an image preserving the localization.
- /// \brief Base class for dmax functors.
- class dmax_default : public dmax_functor_base<dmax_default>
- {
- typedef dmax_functor_base<dmax_default> super_;
+ \param[in] input An image.
+ \param[in] domain A region of interest.
- public:
- dmax_default(const float& dmax_factor);
+ \return An image defined on the domain \p domain with the
+ corresponding data copied from \p input.
- protected:
- using super_::dmax_factor_;
- };
+ */
+ template <typename I>
+ mln_concrete(I)
+ crop(const Image<I>& input, const mln_box(I)& domain);
# ifndef MLN_INCLUDE_ONLY
- dmax_default::dmax_default(const float& dmax_factor)
- : super_(dmax_factor)
- {
- }
-
+ template <typename I>
+ mln_concrete(I)
+ crop(const Image<I>& input, const mln_box(I)& domain)
+ {
+ trace::entering("scribo::preprocessing::crop");
+ mln_assertion(exact(input).is_valid());
-# endif // ! MLN_INCLUDE_ONLY
+ mln_concrete(I) output(domain);
+ data::paste(input | domain, output);
+ trace::exiting("scribo::preprocessing::crop");
+ return output;
+ }
- } // end of namespace scribo::primitive::link::internal
- } // end of namespace scribo::primitive::link
+# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace scribo::primitive
+ } // end of namespace scribo::preprocessing
} // end of namespace scribo
-
-#endif // ! SCRIBO_PRIMITIVE_LINK_INTERNAL_DMAX_DEFAULT_HH
+#endif // ! SCRIBO_PREPROCESSING_CROP_HH
diff --git a/scribo/binarization/global_threshold.hh
b/scribo/preprocessing/crop_without_localization.hh
similarity index 50%
copy from scribo/binarization/global_threshold.hh
copy to scribo/preprocessing/crop_without_localization.hh
index ebf25c4..18c5ee7 100644
--- a/scribo/binarization/global_threshold.hh
+++ b/scribo/preprocessing/crop_without_localization.hh
@@ -23,68 +23,75 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_BINARIZATION_GLOBAL_THRESHOLD_HH
-# define SCRIBO_BINARIZATION_GLOBAL_THRESHOLD_HH
+#ifndef SCRIBO_PREPROCESSING_CROP_WITHOUT_LOCALIZATION_HH
+# define SCRIBO_PREPROCESSING_CROP_WITHOUT_LOCALIZATION_HH
# include <mln/core/concept/image.hh>
-# include <mln/value/concept/vectorial.hh>
-# include <mln/fun/v2b/threshold.hh>
-# include <mln/data/transform.hh>
+# include <mln/data/paste_without_localization.hh>
/// \file
///
-/// \brief Binarize an image using a global threshold value.
+/// \brief Crop an image without preserving the localization.
+
namespace scribo
{
- using namespace mln;
+ namespace preprocessing
+ {
+ using namespace mln;
- namespace binarization
- {
+ /*! \brief crop an image without preserving the localization.
+
+ \param[in] input An image.
+ \param[in] domain A region of interest.
+
+ \return An image defined on a domain starting from the origin
+ (literal::origin) and having the same size as \p domain. Its
+ data corresponds to the data copied from \p input in the domain
+ \p domain.
- /// \brief Binarize an image using a global threshold value.
- ///
- /// For a site 'p' in \p input image:
- ///
- /// output(p) = input(p) >= threshold
- ///
- /// \input[in] input A grayscale image.
- /// \input[in] threshold A value.
- ///
- /// \return A boolean image.
- //
+ */
template <typename I>
- mln_ch_value(I, bool)
- global_threshold(const Image<I>& input, const mln_value(I)&
threshold);
+ mln_concrete(I)
+ crop_without_localization(const Image<I>& input, const mln_box(I)&
domain);
# ifndef MLN_INCLUDE_ONLY
template <typename I>
- mln_ch_value(I, bool)
- global_threshold(const Image<I>& input, const mln_value(I)& threshold)
+ mln_concrete(I)
+ crop_without_localization(const Image<I>& input, const mln_box(I)&
domain)
{
- trace::entering("scribo::binarization::global_threshold");
+ trace::entering("scribo::preprocessing::crop_without_localization");
+ mln_assertion(exact(input).is_valid());
- mln_precondition(exact(input).is_valid());
- mlc_is_not_a(mln_value(I), value::Vectorial)::check();
- mln::fun::v2b::threshold<mln_value(I)> f(threshold);
- mln_ch_value(I, bool) output = data::transform(input, f);
+ typedef mln_site(I) P;
+ P pmin, pmax;
- trace::exiting("scribo::binarization::global_threshold");
+ for (unsigned i = 0; i < P::dim; ++i)
+ {
+ pmin[i] = 0;
+ pmax[i] = domain.pmax()[i] - domain.pmin()[i];
+ }
+
+ mln_box(I) b(pmin, pmax);
+ mln_concrete(I) output(b);
+
+ data::paste_without_localization(input | domain, output);
+
+ trace::exiting("scribo::preprocessing::crop_without_localization");
return output;
}
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace scribo::binarization
+ } // end of namespace scribo::preprocessing
} // end of namespace scribo
-
-#endif // ! SCRIBO_BINARIZATION_GLOBAL_THRESHOLD_HH
+#endif // ! SCRIBO_PREPROCESSING_CROP_WITHOUT_LOCALIZATION_HH
diff --git a/scribo/tests/preprocessing/Makefile.am
b/scribo/tests/preprocessing/Makefile.am
index 4a6790c..d180604 100644
--- a/scribo/tests/preprocessing/Makefile.am
+++ b/scribo/tests/preprocessing/Makefile.am
@@ -20,10 +20,14 @@
include $(top_srcdir)/scribo/tests/tests.mk
check_PROGRAMS = \
- unskew \
- rotate_90
+ crop \
+ crop_without_localization \
+ rotate_90 \
+ unskew
-unskew_SOURCES = unskew.cc
+crop_SOURCES = crop.cc
+crop_without_localization_SOURCES = crop_without_localization.cc
rotate_90_SOURCES = rotate_90.cc
+unskew_SOURCES = unskew.cc
TESTS = $(check_PROGRAMS)
diff --git a/scribo/tests/preprocessing/unskew.cc b/scribo/tests/preprocessing/crop.cc
similarity index 77%
copy from scribo/tests/preprocessing/unskew.cc
copy to scribo/tests/preprocessing/crop.cc
index 9c84951..be36064 100644
--- a/scribo/tests/preprocessing/unskew.cc
+++ b/scribo/tests/preprocessing/crop.cc
@@ -24,10 +24,8 @@
// executable file might be covered by the GNU General Public License.
#include <mln/core/image/image2d.hh>
-#include <mln/io/pbm/load.hh>
-#include <mln/io/pbm/save.hh>
-
-#include <scribo/preprocessing/unskew.hh>
+#include <mln/data/compare.hh>
+#include <scribo/preprocessing/crop.hh>
#include <scribo/tests/data.hh>
@@ -37,8 +35,17 @@ int main(int argc, char *argv[])
(void) argv;
using namespace mln;
- image2d<bool> ima;
- io::pbm::load(ima, SCRIBO_IMG_DIR "/text_to_group.pbm");
+ // Ref
+ image2d<bool> ref(make::box2d(2,2, 8,8));
+ data::fill(ref, 0);
+ data::fill((ref | make::box2d(2,2, 2,3)).rw(), true);
+
+ // Test
+ image2d<bool> ima(10, 10);
+ data::fill(ima, 0);
+ data::fill((ima | box2d(3, 4)).rw(), true);
+
+ image2d<bool> test = scribo::preprocessing::crop(ima, make::box2d(2,2, 8,8));
- io::pbm::save(scribo::preprocessing::unskew(ima).first(), "unskew.pbm");
+ mln_assertion(ref == test);
}
diff --git a/scribo/tests/preprocessing/unskew.cc
b/scribo/tests/preprocessing/crop_without_localization.cc
similarity index 73%
copy from scribo/tests/preprocessing/unskew.cc
copy to scribo/tests/preprocessing/crop_without_localization.cc
index 9c84951..0487ef3 100644
--- a/scribo/tests/preprocessing/unskew.cc
+++ b/scribo/tests/preprocessing/crop_without_localization.cc
@@ -24,10 +24,10 @@
// executable file might be covered by the GNU General Public License.
#include <mln/core/image/image2d.hh>
-#include <mln/io/pbm/load.hh>
-#include <mln/io/pbm/save.hh>
+#include <mln/data/compare.hh>
+#include <scribo/preprocessing/crop_without_localization.hh>
-#include <scribo/preprocessing/unskew.hh>
+#include <mln/debug/println.hh>
#include <scribo/tests/data.hh>
@@ -37,8 +37,19 @@ int main(int argc, char *argv[])
(void) argv;
using namespace mln;
- image2d<bool> ima;
- io::pbm::load(ima, SCRIBO_IMG_DIR "/text_to_group.pbm");
+ // Ref
+ image2d<bool> ref(box2d(7, 7));
+ data::fill(ref, 0);
+ data::fill((ref | box2d(1, 2)).rw(), true);
- io::pbm::save(scribo::preprocessing::unskew(ima).first(), "unskew.pbm");
+ // Test
+ image2d<bool> ima(10, 10);
+ data::fill(ima, 0);
+ data::fill((ima | box2d(3, 4)).rw(), true);
+
+ image2d<bool>
+ test = scribo::preprocessing::crop_without_localization(ima,
+ make::box2d(2,2,
+ 8,8));
+ mln_assertion(ref == test);
}
--
1.5.6.5