URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-06 Matthieu Garrigues <garrigues.matthieu(a)lrde.epita.fr>
add convertion from histo to image1d
* mln/convert/to_image.hh: add the function
* tests/histo_to_image1d_b.cc: a test
mln/convert/to_image.hh | 14 ++++++++
tests/histo_to_image1d_b.cc | 77 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 91 insertions(+)
Index: trunk/milena/tests/histo_to_image1d_b.cc
===================================================================
--- trunk/milena/tests/histo_to_image1d_b.cc (revision 0)
+++ trunk/milena/tests/histo_to_image1d_b.cc (revision 1080)
@@ -0,0 +1,77 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library 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 this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library 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.
+
+/*! \file tests/histo.cc
+ *
+ * \brief Tests on mln::accu::histo<S> and mln::histo::data<S>.
+ */
+
+#include <iterator>
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/image1d_b.hh>
+
+#include <mln/value/int_u8.hh>
+
+#include <mln/debug/iota.hh>
+#include <mln/accu/histo.hh>
+#include <mln/histo/compute.hh>
+
+#include <mln/debug/println.hh>
+
+#include <mln/convert/to_image.hh>
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ {
+ accu::histo< value::set<bool> > h;
+
+ for (unsigned i = 0; i < 5; ++i)
+ h.take(false);
+ for (unsigned i = 0; i < 2; ++i)
+ h.take(true);
+ h.untake(true);
+
+ mln_assertion(h[0] * 10 + h[1] == 51);
+ mln_assertion(h(false) * 10 + h(true) == 51);
+ }
+
+ {
+ image2d_b<int_u8> ima(3, 3);
+ debug::iota(ima);
+ ima(make::point2d(0,1)) = 255;
+ debug::println(ima);
+ histo::data< value::set<int_u8> > h = histo::compute(ima);
+ std::cout << h << std::endl;
+
+ image1d_b<std::size_t> ima2 = convert::to_image(h);
+ debug::println(ima2);
+ }
+}
Index: trunk/milena/mln/convert/to_image.hh
===================================================================
--- trunk/milena/mln/convert/to_image.hh (revision 1079)
+++ trunk/milena/mln/convert/to_image.hh (revision 1080)
@@ -111,6 +111,9 @@
template <typename W>
mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>&
w_win);
+ /// Convert an histo \p h into an image1d_b.
+ template <typename S>
+ image1d_b<std::size_t> to_image(const histo::data<S>& h);
# ifndef MLN_INCLUDE_ONLY
@@ -163,6 +166,17 @@
return ima;
}
+ template <typename S>
+ image1d_b<std::size_t> to_image(const histo::data<S>& h)
+ {
+ mln_value(S)
+ v_min = h.vset()[0],
+ v_max = h.vset()[h.vset().nvalues() - 1];
+ image1d_b<std::size_t> ima(make::box1d(v_min, v_max));
+ for(std::size_t i = 0; i < h.vset().nvalues(); ++i)
+ ima[i] = h[i];
+ return ima;
+ }
# endif // ! MLN_INCLUDE_ONLY