URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-04 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Update chamfer.
* chamfer.cc: Test for chamfer.
* chamfer.hh: New split of old version.
* color_sub.cc,
* color_sub.hh,
* main.cc: Update.
---
chamfer.cc | 121 ++++++++++++------------------------------------------
chamfer.hh | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
color_sub.cc | 3 -
color_sub.hh | 23 +++++-----
main.cc | 1
5 files changed, 173 insertions(+), 106 deletions(-)
Index: trunk/milena/sandbox/duhamel/main.cc
===================================================================
--- trunk/milena/sandbox/duhamel/main.cc (revision 1242)
+++ trunk/milena/sandbox/duhamel/main.cc (revision 1243)
@@ -26,6 +26,7 @@
{
}
+
int
main (void)
{
Index: trunk/milena/sandbox/duhamel/color_sub.cc
===================================================================
--- trunk/milena/sandbox/duhamel/color_sub.cc (revision 1242)
+++ trunk/milena/sandbox/duhamel/color_sub.cc (revision 1243)
@@ -57,8 +57,7 @@
image2d_b<value::int_u8> ima(3,3);
debug::iota(ima);
std::cout << ima.domain() << std::endl;
- image2d_b<value::rgb8> out(ima.domain ().bbox ());
- color(inplace (ima | 6), out);
+ image2d_b<value::rgb8> out = color(inplace (ima | 6));
io::ppm::save(out, "out.ppm");
debug::println(out);
}
Index: trunk/milena/sandbox/duhamel/chamfer.cc
===================================================================
--- trunk/milena/sandbox/duhamel/chamfer.cc (revision 1242)
+++ trunk/milena/sandbox/duhamel/chamfer.cc (revision 1243)
@@ -1,6 +1,9 @@
#include <mln/core/image2d_b.hh>
#include <mln/core/sub_image.hh>
+#include <mln/core/image_if_value.hh>
#include <mln/core/neighb2d.hh>
+#include <mln/core/inplace.hh>
+
#include <mln/value/int_u8.hh>
#include <mln/level/fill.hh>
#include <mln/level/stretch.hh>
@@ -12,6 +15,7 @@
# include <mln/labeling/base.hh>
# include <mln/debug/println.hh>
# include <mln/core/window2d.hh>
+# include <mln/core/w_window2d_int.hh>
# include <mln/convert/to_window.hh>
# include <mln/core/concept/dpoint.hh>
# include <mln/core/concept/neighborhood.hh>
@@ -20,114 +24,43 @@
# include <mln/pw/cst.hh>
# include <mln/metal/is_a.hh>
+# include <mln/core/image_if_interval.hh>
+#include "chamfer.hh"
-namespace mln
-{
- namespace convert
- {
-// template <typename N>
-// window<mln_dpoint(N)> to_upper_window(const Neighborhood<N>&
nbh_)
-// {
-// const N& nbh = exact(nbh_);
-// typedef mln_dpoint(N) D;
-// typedef mln_point(D) P;
-// window<D> win;
-// mln_niter(N) n(nbh, P::zero);
-// for_all(n)
-// if (n > P::zero)
-// win.insert(n - P::zero);
-// return win;
-// }
- template <typename N>
- window<mln_dpoint(N)> to_lower_window(const Neighborhood<N>& nbh_)
- {
- const N& nbh = exact(nbh_);
- typedef mln_dpoint(N) D;
- typedef mln_point(D) P;
- window<D> win;
- mln_niter(N) n(nbh, P::zero);
- for_all(n)
- if (n < P::zero)
- win.insert(n - P::zero);
- return win;
- }
-
- } // end of namespace convert
-
- template <typename I, typename N, typename J>
- void
- chamfer (Image<I>& ima_, const Neighborhood<N>& nbh_,
- mln_point(I)& point, unsigned max, Image<J>& out_)
+int main()
{
- I& ima = exact (ima_);
- J& out = exact (out_);
+ using namespace mln;
+ unsigned max = 51;
- typedef window<mln_dpoint(I)> W;
+ image2d_b<bool> ima(9, 9);
- /// Init.
{
- level::fill (out, max);
- out(point) = 0;
+ level::fill(ima, false);
+ ima.at(4,4) = true;
+ const w_window2d_int& w_win = win_chamfer::mk_chamfer_3x3_int<2, 0> ();
+ image2d_b<unsigned> out = chamfer(ima, w_win, max);
+ debug::println(out | value::interval(0, 8));
}
- /// Fwd pass.
{
- mln_fwd_piter (I) p (ima.domain ());
- W win = convert::to_upper_window(nbh_);
- mln_qiter(W) n(win, p);
-
- for_all (p)
- {
- for_all (n)
- {
- if (out(n) > out(p) + 1)
- out(n) = out(p) + 1;
- }
- }
+ level::fill(ima, false);
+ ima.at(4,4) = true;
+ const w_window2d_int& w_win = win_chamfer::mk_chamfer_3x3_int<2, 3> ();
+ image2d_b<unsigned> out = chamfer(ima, w_win, max);
+ debug::println(out | value::interval(0, 8));
}
- /// Bkd pass.
{
- mln_bkd_piter (I) p (ima.domain ());
- W win = convert::to_lower_window(nbh_);
- mln_qiter(W) n( win, p);
-
+ level::fill(ima, false);
+ ima.at(4,4) = true;
+ const w_window2d_int& w_win = win_chamfer::mk_chamfer_5x5_int<4, 6, 9> ();
+ image2d_b<unsigned> out = chamfer(ima, w_win, max);
+ image2d_b<unsigned>::fwd_piter p(out.domain());
for_all (p)
- {
- for_all (n)
- {
- if (out(n) > out(p) + 1)
- out(n) = out(p) + 1;
- }
- }
+ out(p) = out(p) / 2;
+ debug::println(out | value::interval(0, 8));
}
- }
-} // end of mln
-int main ()
-{
- using namespace mln;
- using value::int_u8;
-
- {
- image2d_b<int_u8> ima (9, 9);
- image2d_b<unsigned> out (ima.domain ());
- point2d p = make::point2d(4,4);
-
- chamfer (ima, c4(), p, 255, out);
- debug::println (out);
- }
-
-
-
- {
- image2d_b<int_u8> ima (1000, 1000);
- image2d_b<unsigned> out (ima.domain ());
- point2d p = make::point2d(4,4);
-
- chamfer (ima, c4(), p, 255, out);
- }
- // debug::println (out);
}
Index: trunk/milena/sandbox/duhamel/color_sub.hh
===================================================================
--- trunk/milena/sandbox/duhamel/color_sub.hh (revision 1242)
+++ trunk/milena/sandbox/duhamel/color_sub.hh (revision 1243)
@@ -37,24 +37,27 @@
namespace mln
{
- template <typename I, typename J>
- void
- color (Image<I>& ima_ , Image<J>& out_)
+ template <typename I>
+ mln_ch_value (I, value::rgb8)
+ color (const Image<I>& input_)
{
- I& ima = exact (ima_);
- J& out = exact (out_);
- // image2d_b<value::rgb8> out(ima.domain ().bbox ());
+ const I& input = exact (input_);
- level::fill (out, value::rgb8(255, 0, 0));
+ mln_ch_value(I, value::rgb8) output;
+ initialize(output, input);
+
+ // image2d_b<value::rgb8> output(ima.domain ().bbox ());
+
+ level::fill (output, value::rgb8(255, 0, 0));
{
- mln_piter(I) p (ima.domain ());
+ mln_piter(I) p (input.domain ());
for_all (p)
{
- out(p) = value::rgb8(ima(p));
+ output(p) = value::rgb8(input(p));
}
}
- // return out;
+ return output;
}
}
Index: trunk/milena/sandbox/duhamel/chamfer.hh
===================================================================
--- trunk/milena/sandbox/duhamel/chamfer.hh (revision 0)
+++ trunk/milena/sandbox/duhamel/chamfer.hh (revision 1243)
@@ -0,0 +1,131 @@
+#include <mln/core/image2d_b.hh>
+#include <mln/core/sub_image.hh>
+#include <mln/core/image_if_value.hh>
+#include <mln/core/neighb2d.hh>
+#include <mln/core/inplace.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/level/fill.hh>
+#include <mln/level/stretch.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/core/mesh_image.hh>
+# include <mln/labeling/base.hh>
+# include <mln/debug/println.hh>
+# include <mln/core/window2d.hh>
+# include <mln/core/w_window2d_int.hh>
+# include <mln/core/w_window2d_float.hh>
+# include <mln/convert/to_window.hh>
+# include <mln/core/concept/dpoint.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/window.hh>
+# include <mln/pw/image.hh>
+# include <mln/pw/cst.hh>
+# include <mln/metal/is_a.hh>
+
+# include <mln/core/image_if_interval.hh>
+# include <mln/core/dpoint2d.hh>
+
+namespace mln
+{
+ namespace win_chamfer
+ {
+
+ template<int d10, int d11>
+ const w_window2d_int
+ mk_chamfer_3x3_int()
+ {
+ int ws[] = { d11, d10, d11,
+ d10, 0, 0,
+ 0, 0, 0 };
+
+ return (make::w_window2d(ws));
+ }
+
+ template<int d10, int d11, int d21>
+ const w_window2d_int
+ mk_chamfer_5x5_int()
+ {
+ int ws[] = { 0, d21, 0, d21, 0,
+ d21, d11, d10, d11, d21,
+ 0, d10, 0, d10, 0,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0 };
+
+ return (make::w_window2d(ws));
+ }
+
+ const w_window2d_float
+ mk_chamfer_3x3_float(float d10, float d11)
+ {
+ float ws[] = { d11, d10, d11,
+ d10, 0, 0,
+ 0, 0, 0 };
+
+ return (make::w_window2d(ws));
+ }
+
+ const w_window2d_float
+ mk_chamfer_5x5_float(float d10, float d11, float d21)
+ {
+ float ws[] = { 0, d21, 0, d21, 0,
+ d21, d11, d10, d11, d21,
+ 0, d10, 0, d10, 0,
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0 };
+
+ return (make::w_window2d(ws));
+ }
+
+ } // end of mln::win_chamfer
+
+ template <typename I, typename W>
+ mln_ch_value(I, unsigned)
+ chamfer(const Image<I>& input_, const Weighted_Window<W>& w_win_,
+ unsigned max = mln_max(unsigned))
+ {
+ const I& input = exact(input_);
+ const W& w_win = exact(w_win_);
+
+ mln_ch_value(I, unsigned) output;
+ initialize(output, input);
+
+ /// Init.
+ {
+ level::fill(inplace(output | (input | true).domain()), 0);
+ level::fill(inplace(output | (input | false).domain()), max);
+ }
+
+ /// Fwd pass.
+ {
+ mln_fwd_piter(I) p(input.domain());
+ mln_qiter(W) q(w_win, p);
+
+ for_all(p) if (input(p) == false)
+ for_all(q) if (input.has(q))
+ if (output(q) != max
+ && output(q) + q.w() < output(p))
+ output(p) = output(q) + q.w();
+ }
+
+ /// Bkd pass.
+ {
+
+ W w_win_b = geom::sym(w_win);
+
+ mln_bkd_piter(I) p(input.domain());
+ mln_qiter(W) q(w_win_b, p);
+
+ for_all(p) if (input(p) == false)
+ for_all(q) if (input.has(q))
+ if (output(q) != max
+ && output(q) + q.w() < output(p))
+ output(p) = output(q) + q.w();
+ }
+
+ return output;
+ }
+
+} // end of mln