* mln/world/binary_2d/subsample.hh
(world::binary_2d::subsample(const image2d<bool>&, unsigned)):
Properly initialize (and deallocate) the sliding window (array of
pointers).
Fix the size of the output image.
Have the declaration of this function match its definition.
* tests/world/binary_2d/subsample.cc: New test.
* tests/world/binary_2d/Makefile.am
(check_PROGRAMS): Add subsample.
(MOSTLYCLEANFILES): Add subsample-small.pgm.
---
milena/ChangeLog | 15 +++++++++++++++
milena/mln/world/binary_2d/subsample.hh | 9 +++++----
milena/tests/world/binary_2d/Makefile.am | 11 +++++++----
.../height.cc => world/binary_2d/subsample.cc} | 19 ++++++++++---------
4 files changed, 37 insertions(+), 17 deletions(-)
copy milena/tests/{morpho/closing/height.cc => world/binary_2d/subsample.cc} (78%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 11fa869..ae13399 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,18 @@
+2013-06-28 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Fix two bugs in mln/world/binary_2d/subsample.hh.
+
+ * mln/world/binary_2d/subsample.hh
+ (world::binary_2d::subsample(const image2d<bool>&, unsigned)):
+ Properly initialize (and deallocate) the sliding window (array of
+ pointers).
+ Fix the size of the output image.
+ Have the declaration of this function match its definition.
+ * tests/world/binary_2d/subsample.cc: New test.
+ * tests/world/binary_2d/Makefile.am
+ (check_PROGRAMS): Add subsample.
+ (MOSTLYCLEANFILES): Add subsample-small.pgm.
+
2013-06-24 Roland Levillain <roland(a)lrde.epita.fr>
Address compiler warnings about unused variables and arguments.
diff --git a/milena/mln/world/binary_2d/subsample.hh
b/milena/mln/world/binary_2d/subsample.hh
index d8d1aa3..fd8684a 100644
--- a/milena/mln/world/binary_2d/subsample.hh
+++ b/milena/mln/world/binary_2d/subsample.hh
@@ -57,7 +57,7 @@ namespace mln
/// \return A gray level image.
//
image2d<value::int_u8>
- subsample(image2d<bool>& input, unsigned n);
+ subsample(const image2d<bool>& input, unsigned n);
# ifndef MLN_INCLUDE_ONLY
@@ -80,11 +80,10 @@ namespace mln
return output;
}
- const bool** ptr;
+ const bool** ptr = new const bool*[n];
const unsigned nrows = input.nrows() / n;
const unsigned ncols = input.ncols() / n;
- image2d<int_u8> output;
- initialize(output, input);
+ image2d<int_u8> output(nrows, ncols);
const unsigned delta_row = input.delta_offset(down);
unsigned count = 0;
@@ -109,6 +108,8 @@ namespace mln
}
}
+ delete[] ptr;
+
return output;
}
diff --git a/milena/tests/world/binary_2d/Makefile.am
b/milena/tests/world/binary_2d/Makefile.am
index c741183..cb73266 100644
--- a/milena/tests/world/binary_2d/Makefile.am
+++ b/milena/tests/world/binary_2d/Makefile.am
@@ -1,4 +1,5 @@
-# Copyright (C) 2009, 2010 EPITA Research and Development Laboratory (LRDE)
+# Copyright (C) 2009, 2010, 2013 EPITA Research and Development
+# Laboratory (LRDE)
#
# This file is part of Olena.
#
@@ -17,8 +18,10 @@
include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
- enlarge
-# enlarge_hq2x
-
+ enlarge \
+ subsample
TESTS = $(check_PROGRAMS)
+
+MOSTLYCLEANFILES = \
+ subsample-small.pgm
diff --git a/milena/tests/morpho/closing/height.cc
b/milena/tests/world/binary_2d/subsample.cc
similarity index 78%
copy from milena/tests/morpho/closing/height.cc
copy to milena/tests/world/binary_2d/subsample.cc
index 6863355..f7aa4ef 100644
--- a/milena/tests/morpho/closing/height.cc
+++ b/milena/tests/world/binary_2d/subsample.cc
@@ -1,5 +1,4 @@
-// Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -24,14 +23,16 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
+/// \file
+/// Exercise mln::world::binary_2d::subsample.
+
#include <mln/core/image/image2d.hh>
#include <mln/value/int_u8.hh>
-#include <mln/core/alias/neighb2d.hh>
-#include <mln/io/pgm/load.hh>
-#include <mln/io/pgm/save.hh>
+#include <mln/world/binary_2d/subsample.hh>
-#include <mln/morpho/closing/height.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pgm/save.hh>
#include "tests/data.hh"
@@ -41,7 +42,7 @@ int main()
using namespace mln;
using value::int_u8;
- image2d<int_u8> lena;
- io::pgm::load(lena, MLN_IMG_DIR "/tiny.pgm");
- io::pgm::save(morpho::closing::height(lena, c4(), 20), "height-out.pgm");
+ image2d<bool> input = io::pbm::load(MLN_IMG_DIR "/small.pbm");
+ image2d<int_u8> output = world::binary_2d::subsample(input, 3);
+ io::pgm::save(output, "subsample-small.pgm");
}
--
1.7.10.4
Show replies by date