URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-03-20 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Implement binary 2d specific routines.
* mln/world/binary_2d/projected_histo.hh: New projected histogram
for binary 2d images.
* mln/world/binary_2d/subsample.hh: Update.
---
projected_histo.hh | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++
subsample.hh | 69 ++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 139 insertions(+), 7 deletions(-)
Index: trunk/milena/mln/world/binary_2d/projected_histo.hh
===================================================================
--- trunk/milena/mln/world/binary_2d/projected_histo.hh (revision 0)
+++ trunk/milena/mln/world/binary_2d/projected_histo.hh (revision 3557)
@@ -0,0 +1,77 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// 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.
+
+#ifndef MLN_WORLD_BINARY_2D_PROJECTED_HISTO_HH
+# define MLN_WORLD_BINARY_2D_PROJECTED_HISTO_HH
+
+/// \file mln/world/binary_2d/projected_histo.hh
+///
+/// FIXME: insert comment.
+
+# include <mln/core/image/image1d.hh>
+# include <mln/core/image/image2d.hh>
+# include <mln/core/alias/dpoint2d.hh>
+# include <mln/value/int_u12.hh>
+
+namespace mln
+{
+
+ namespace world
+ {
+
+ namespace binary_2d
+ {
+
+ void projected_histo(const image2d<bool>& input,
+ image1d<value::int_u12>& row_histo,
+ image1d<value::int_u12>& col_histo)
+ {
+ const unsigned nrows = input.nrows();
+ const unsigned ncols = input.ncols();
+ mln_precondition(row_histo.nelements() == nrows);
+ mln_precondition(col_histo.nelements() == ncols);
+
+ for (unsigned row = 0; row < nrows; ++row)
+ {
+ for (unsigned col = 0; col < ncols; ++col)
+ {
+ if (input(point2d(row, col)))
+ {
+ ++row_histo(point1d(row));
+ ++col_histo(point1d(col));
+ }
+ }
+ }
+ }
+
+ } // end of namespace mln::world::binary_2d
+
+ } // end of namspace mln::world
+
+} // end of namespace mln
+
+#endif // ! MLN_WORLD_BINARY_2D_PROJECTED_HISTO_HH
Index: trunk/milena/mln/world/binary_2d/subsample.hh
===================================================================
--- trunk/milena/mln/world/binary_2d/subsample.hh (revision 3556)
+++ trunk/milena/mln/world/binary_2d/subsample.hh (revision 3557)
@@ -1,13 +1,57 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// 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.
-// FIXME: Complete this file.
+#ifndef MLN_WORLD_BINARY_2D_SUBSAMPLE_HH
+# define MLN_WORLD_BINARY_2D_SUBSAMPLE_HH
+/// \file mln/world/binary_2d/subsample.hh
+///
+/// FIXME: insert comment.
-template <typename I>
-image2d<int_u8> subsample(const image2d<bool>& input, unsigned n)
+# include <mln/core/image/image2d.hh>
+# include <mln/core/alias/dpoint2d.hh>
+# include <mln/value/int_u8.hh>
+
+namespace mln
+{
+
+ namespace world
+ {
+
+ namespace binary_2d
+ {
+
+ image2d<value::int_u8> subsample(const image2d<bool>& input, unsigned n)
{
- typedef bool* ptr;
- ptr p = new ptr(n);
+ bool* ptr = new bool[n];
const unsigned nrows = input.nrows() / n;
+ const unsigned ncols = input.ncols() / n;
+ image2d<value::int_u8> output;
+ initialize(output, input);
dpoint2d dp_row(1, 0);
const unsigned delta_row = input.delta_index(dp_row);
@@ -20,9 +64,20 @@
ptr[i] = ptr[i-1] + delta_row;
for (unsigned col = 0; col < ncols; ++col)
{
- for (unsigned i = 0; i < n; ++i)
- count += *(ptr[i]++);
+ for (unsigned i = 0; i < n; ++i, ++ptr)
+ {
+ if (ptr[i])
+ ++count;
+ }
output(point2d(row, col)) = count * 255 / n / n;
}
}
}
+
+ } // end of namespace mln::world::binary_2d
+
+ } // end of namspace mln::world
+
+} // end of namespace mln
+
+#endif // ! MLN_WORLD_BINARY_2D_SUBSAMPLE_HH