https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add morpho elementary dilation and internal gradient.
* mln/border/resize.hh: Remove precondition.
This test cannot be verified since this operation may be
a no-op (for images without borders).
* mln/border/adjust.hh: Likewise.
* mln/morpho/elementary/like_ero_set.hh: Fix missing
initialization.
* mln/morpho/elementary/like_ero_fun.hh: Likewise.
(f_accu): Move into the internal namespace.
* mln/morpho/elementary/dilation.hh: New.
* mln/morpho/elementary/gradient_internal.hh: New.
* mln/morpho/elementary/all.hh: Update.
* tests/morpho/elementary/dilation.cc: New.
* tests/morpho/elementary/gradient_internal.cc: New.
mln/border/adjust.hh | 2 -
mln/border/resize.hh | 2 -
mln/morpho/elementary/all.hh | 3 +
mln/morpho/elementary/dilation.hh | 36 ++++++++++-----------
mln/morpho/elementary/gradient_internal.hh | 45 ++++++++++++++++-----------
mln/morpho/elementary/like_ero_fun.hh | 11 ++++++
mln/morpho/elementary/like_ero_set.hh | 8 ++++
tests/morpho/elementary/dilation.cc | 18 +++++-----
tests/morpho/elementary/gradient_internal.cc | 23 ++++++++-----
9 files changed, 90 insertions(+), 58 deletions(-)
Index: tests/morpho/elementary/dilation.cc
--- tests/morpho/elementary/dilation.cc (revision 2712)
+++ tests/morpho/elementary/dilation.cc (working copy)
@@ -25,9 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/morpho/elementary/erosion.cc
+/*! \file tests/morpho/elementary/dilation.cc
*
- * \brief Test on mln::morpho::elementary::erosion.
+ * \brief Test on mln::morpho::elementary::dilation.
*/
#include <mln/core/image/image2d.hh>
@@ -37,7 +37,7 @@
#include <mln/debug/iota.hh>
#include <mln/debug/println.hh>
-#include <mln/morpho/elementary/erosion.hh>
+#include <mln/morpho/elementary/dilation.hh>
int main()
@@ -51,18 +51,18 @@
debug::iota(ima);
debug::println(ima);
{
- image2d<int_u8> ero = morpho::elementary::erosion(ima, c4());
- mln_assertion(ero.border() == 1);
- debug::println(ero);
+ image2d<int_u8> dil = morpho::elementary::dilation(ima, c4());
+ mln_assertion(dil.border() == 1);
+ debug::println(dil);
}
image2d<bool> msk(3, 3, 0);
level::fill(msk, pw::value(ima) >= pw::cst(5));
debug::println(msk);
{
- image2d<bool> ero = morpho::elementary::erosion(msk, c4());
- mln_assertion(ero.border() == 1);
- debug::println(ero);
+ image2d<bool> dil = morpho::elementary::dilation(msk, c4());
+ mln_assertion(dil.border() == 1);
+ debug::println(dil);
}
}
Index: tests/morpho/elementary/gradient_internal.cc
--- tests/morpho/elementary/gradient_internal.cc (revision 2712)
+++ tests/morpho/elementary/gradient_internal.cc (working copy)
@@ -25,19 +25,21 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/morpho/elementary/erosion.cc
+/*! \file tests/morpho/elementary/gradient_internal.cc
*
- * \brief Test on mln::morpho::elementary::erosion.
+ * \brief Test on mln::morpho::elementary::gradient_internal.
*/
#include <mln/core/image/image2d.hh>
+#include <mln/core/image/sub_image.hh>
#include <mln/core/alias/neighb2d.hh>
+#include <mln/core/var.hh>
#include <mln/value/int_u8.hh>
#include <mln/debug/iota.hh>
#include <mln/debug/println.hh>
-#include <mln/morpho/elementary/erosion.hh>
+#include <mln/morpho/elementary/gradient_internal.hh>
int main()
@@ -50,19 +52,22 @@
image2d<int_u8> ima(3, 3, 0);
debug::iota(ima);
debug::println(ima);
+
+ mln_VAR(b, ima.domain());
+
{
- image2d<int_u8> ero = morpho::elementary::erosion(ima, c4());
- mln_assertion(ero.border() == 1);
- debug::println(ero);
+ mln_VAR(gra,
+ morpho::elementary::gradient_internal(ima | b, c4()));
+ debug::println(gra);
}
image2d<bool> msk(3, 3, 0);
level::fill(msk, pw::value(ima) >= pw::cst(5));
debug::println(msk);
{
- image2d<bool> ero = morpho::elementary::erosion(msk, c4());
- mln_assertion(ero.border() == 1);
- debug::println(ero);
+ mln_VAR(gra,
+ morpho::elementary::gradient_internal(msk | b, c4()));
+ debug::println(gra);
}
}
Index: mln/border/resize.hh
--- mln/border/resize.hh (revision 2712)
+++ mln/border/resize.hh (working copy)
@@ -176,8 +176,6 @@
impl::resize_(ima, thickness);
- mln_postcondition(border::get(ima) == thickness);
-
trace::exiting("border::resize");
}
Index: mln/border/adjust.hh
--- mln/border/adjust.hh (revision 2712)
+++ mln/border/adjust.hh (working copy)
@@ -73,8 +73,6 @@
if (border::get(ima) < min_thickness)
border::resize(ima, min_thickness);
-
- mln_postcondition(border::get(ima) >= min_thickness);
}
trace::exiting("border::adjust");
Index: mln/morpho/elementary/like_ero_fun.hh
--- mln/morpho/elementary/like_ero_fun.hh (revision 2712)
+++ mln/morpho/elementary/like_ero_fun.hh (working copy)
@@ -29,6 +29,9 @@
# define MLN_MORPHO_ELEMENTARY_LIKE_ERO_FUN_HH
/// \file mln/morpho/elementary/like_ero_fun.hh
+///
+/// \todo Add a choice between adjust_fill and adjust_duplicate.
+
# include <mln/morpho/includes.hh>
@@ -49,6 +52,12 @@
const Image<I>& input, const Neighborhood<N>& nbh);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
struct f_accu
{
template <typename V, typename A>
@@ -58,8 +67,8 @@
}
};
+ } // end of namespace mln::morpho::elementary::internal
-# ifndef MLN_INCLUDE_ONLY
namespace impl
{
Index: mln/morpho/elementary/dilation.hh
--- mln/morpho/elementary/dilation.hh (revision 2712)
+++ mln/morpho/elementary/dilation.hh (working copy)
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_MORPHO_ELEMENTARY_EROSION_HH
-# define MLN_MORPHO_ELEMENTARY_EROSION_HH
+#ifndef MLN_MORPHO_ELEMENTARY_DILATION_HH
+# define MLN_MORPHO_ELEMENTARY_DILATION_HH
-/// \file mln/morpho/elementary/erosion.hh
+/// \file mln/morpho/elementary/dilation.hh
# include <mln/morpho/elementary/like_ero_fun.hh>
# include <mln/morpho/elementary/like_ero_set.hh>
@@ -46,7 +46,7 @@
template <typename I, typename N>
mln_concrete(I)
- erosion(const Image<I>& input, const Neighborhood<N>& nbh);
+ dilation(const Image<I>& input, const Neighborhood<N>& nbh);
# ifndef MLN_INCLUDE_ONLY
@@ -58,33 +58,33 @@
template <typename I, typename N>
mln_concrete(I)
- erosion_dispatch(trait::image::kind::any,
+ dilation_dispatch(trait::image::kind::any,
const Image<I>& input, const Neighborhood<N>& nbh)
{
- return like_ero_fun(accu::meta::min(), f_accu(), input, nbh);
+ return like_ero_fun(accu::meta::max(), f_accu(), input, nbh);
}
template <typename I, typename N>
mln_concrete(I)
- erosion_dispatch(trait::image::kind::logic,
+ dilation_dispatch(trait::image::kind::logic,
const Image<I>& input, const Neighborhood<N>& nbh)
{
bool val[] =
{
- 1, // ext_value
+ 0, // ext_value
1, // do_clone
- 1, // on_input_p
- 0, // on_input_n
- 0, // output_p
+ 0, // on_input_p
+ 1, // on_input_n
+ 1, // output_p
};
return like_ero_set(val, input, nbh);
}
template <typename I, typename N>
mln_concrete(I)
- erosion_dispatch(const Image<I>& input, const Neighborhood<N>& nbh)
+ dilation_dispatch(const Image<I>& input, const Neighborhood<N>&
nbh)
{
- return erosion_dispatch(mln_trait_image_kind(I)(),
+ return dilation_dispatch(mln_trait_image_kind(I)(),
input, nbh);
}
@@ -95,16 +95,16 @@
template <typename I, typename N>
mln_concrete(I)
- erosion(const Image<I>& input, const Neighborhood<N>& nbh)
+ dilation(const Image<I>& input, const Neighborhood<N>& nbh)
{
- trace::entering("morpho::elementary::erosion");
+ trace::entering("morpho::elementary::dilation");
mln_precondition(exact(input).has_data());
// mln_precondition(exact(nbh).is_valid());
- mln_concrete(I) output = internal::erosion_dispatch(input, nbh);
+ mln_concrete(I) output = internal::dilation_dispatch(input, nbh);
- trace::exiting("morpho::elementary::erosion");
+ trace::exiting("morpho::elementary::dilation");
return output;
}
@@ -117,4 +117,4 @@
} // end of namespace mln
-#endif // ! MLN_MORPHO_ELEMENTARY_EROSION_HH
+#endif // ! MLN_MORPHO_ELEMENTARY_DILATION_HH
Index: mln/morpho/elementary/like_ero_set.hh
--- mln/morpho/elementary/like_ero_set.hh (revision 2712)
+++ mln/morpho/elementary/like_ero_set.hh (working copy)
@@ -29,6 +29,8 @@
# define MLN_MORPHO_ELEMENTARY_LIKE_ERO_SET_HH
/// \file mln/morpho/elementary/like_ero_set.hh
+///
+/// \todo Add a choice between adjust_fill and adjust_duplicate.
# include <mln/morpho/includes.hh>
@@ -79,7 +81,10 @@
if (do_clone)
output = clone(input);
else
+ {
+ initialize(output, input);
level::fill(output, false);
+ }
mln_piter(I) p(input.domain());
mln_niter(N) n(nbh, p);
@@ -119,7 +124,10 @@
if (do_clone)
output = clone(input);
else
+ {
+ initialize(output, input);
level::fill(output, false);
+ }
mln_pixter(const I) p_in(input);
mln_pixter(I) p_out(output);
Index: mln/morpho/elementary/all.hh
--- mln/morpho/elementary/all.hh (revision 2712)
+++ mln/morpho/elementary/all.hh (working copy)
@@ -47,6 +47,9 @@
}
# include <mln/morpho/elementary/erosion.hh>
+# include <mln/morpho/elementary/dilation.hh>
+# include <mln/morpho/elementary/gradient_internal.hh>
+# include <mln/morpho/elementary/gradient_external.hh>
Index: mln/morpho/elementary/gradient_internal.hh
--- mln/morpho/elementary/gradient_internal.hh (revision 2712)
+++ mln/morpho/elementary/gradient_internal.hh (working copy)
@@ -25,10 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_MORPHO_ELEMENTARY_EROSION_HH
-# define MLN_MORPHO_ELEMENTARY_EROSION_HH
+#ifndef MLN_MORPHO_ELEMENTARY_GRADIENT_INTERNAL_HH
+# define MLN_MORPHO_ELEMENTARY_GRADIENT_INTERNAL_HH
-/// \file mln/morpho/elementary/erosion.hh
+/// \file mln/morpho/elementary/gradient_internal.hh
+///
+/// \todo Fix the extension issue (see todo in like_ero_fun and _set).
# include <mln/morpho/elementary/like_ero_fun.hh>
# include <mln/morpho/elementary/like_ero_set.hh>
@@ -46,7 +48,7 @@
template <typename I, typename N>
mln_concrete(I)
- erosion(const Image<I>& input, const Neighborhood<N>& nbh);
+ gradient_internal(const Image<I>& input, const Neighborhood<N>&
nbh);
# ifndef MLN_INCLUDE_ONLY
@@ -54,37 +56,46 @@
namespace internal
{
+ struct f_grad_int
+ {
+ template <typename V, typename A>
+ V operator()(const V& input_p, const A& a) const
+ {
+ return input_p - a.to_result();
+ }
+ };
+
// Dispatch.
template <typename I, typename N>
mln_concrete(I)
- erosion_dispatch(trait::image::kind::any,
+ gradient_internal_dispatch(trait::image::kind::any,
const Image<I>& input, const Neighborhood<N>& nbh)
{
- return like_ero_fun(accu::meta::min(), f_accu(), input, nbh);
+ return like_ero_fun(accu::meta::min(), f_grad_int(), input, nbh);
}
template <typename I, typename N>
mln_concrete(I)
- erosion_dispatch(trait::image::kind::logic,
+ gradient_internal_dispatch(trait::image::kind::logic,
const Image<I>& input, const Neighborhood<N>& nbh)
{
bool val[] =
{
- 1, // ext_value
- 1, // do_clone
+ 0, // ext_value
+ 0, // do_clone
1, // on_input_p
0, // on_input_n
- 0, // output_p
+ 1, // output_p
};
return like_ero_set(val, input, nbh);
}
template <typename I, typename N>
mln_concrete(I)
- erosion_dispatch(const Image<I>& input, const Neighborhood<N>& nbh)
+ gradient_internal_dispatch(const Image<I>& input, const
Neighborhood<N>& nbh)
{
- return erosion_dispatch(mln_trait_image_kind(I)(),
+ return gradient_internal_dispatch(mln_trait_image_kind(I)(),
input, nbh);
}
@@ -95,16 +106,16 @@
template <typename I, typename N>
mln_concrete(I)
- erosion(const Image<I>& input, const Neighborhood<N>& nbh)
+ gradient_internal(const Image<I>& input, const Neighborhood<N>&
nbh)
{
- trace::entering("morpho::elementary::erosion");
+ trace::entering("morpho::elementary::gradient_internal");
mln_precondition(exact(input).has_data());
// mln_precondition(exact(nbh).is_valid());
- mln_concrete(I) output = internal::erosion_dispatch(input, nbh);
+ mln_concrete(I) output = internal::gradient_internal_dispatch(input, nbh);
- trace::exiting("morpho::elementary::erosion");
+ trace::exiting("morpho::elementary::gradient_internal");
return output;
}
@@ -117,4 +128,4 @@
} // end of namespace mln
-#endif // ! MLN_MORPHO_ELEMENTARY_EROSION_HH
+#endif // ! MLN_MORPHO_ELEMENTARY_GRADIENT_INTERNAL_HH