URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-02 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Better tests on float01.
* mln/value/float01.hh: Fix.
* mln/value/float01_.hh: Fix.
* tests/value_float01.cc: Update.
---
mln/value/float01.hh | 2 -
mln/value/float01_.hh | 24 +++++++++++++++-
tests/value_float01.cc | 70 ++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 92 insertions(+), 4 deletions(-)
Index: trunk/milena/tests/value_float01.cc
===================================================================
--- trunk/milena/tests/value_float01.cc (revision 1220)
+++ trunk/milena/tests/value_float01.cc (revision 1221)
@@ -26,10 +26,27 @@
// Public License.
#include <iostream>
+
+#include <mln/core/image2d_b.hh>
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+
#include <mln/value/float01_8.hh>
#include <mln/value/float01_16.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/level/transform.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/core/win/rectangle2d.hh>
+#include <mln/level/median.hh>
+#include <mln/level/compare.hh>
+
+
+using namespace mln;
+using namespace mln::value;
+using mln::value::int_u8;
float fi(int x) { return 0.5; }
int ii(int x) { return 1; }
@@ -37,9 +54,35 @@
float fd(double x) { return 0.5; }
int id(double x) { return 1; }
+
+struct tofloat01 : mln::Function_v2v<tofloat01>
+{
+
+ typedef float01_<16> result;
+ result operator()(int_u8 v) const
+ {
+ result ret(double(v) / (mln_max(int_u8)));
+ // std::cout << v << "-> " << ret <<
std::endl;
+ return ret;
+ }
+};
+
+struct to8bits : mln::Function_v2v<to8bits>
+{
+
+ typedef int_u8 result;
+ result operator()(float01_<16> v) const
+ {
+ result ret = int(v.value() * 255);
+ //std::cout << v << "-> " << ret << std::endl;
+ return ret;
+ }
+};
+
int main()
{
- using namespace mln::value;
+ win::rectangle2d rect(51, 51);
+ border::thickness = 52;
float01_8 a(0.5);
float01_16 b(0.5);
@@ -74,4 +117,29 @@
std::cout << b << std::endl;
b = 1;
std::cout << b << std::endl;
+
+ {
+ std::cout << "convert" << std::endl;
+ image2d_b<int_u8>
+ lena = io::pgm::load<int_u8>("../img/lena.pgm"),
+ ref(lena.domain());
+
+ image2d_b<float01_16> out(lena.domain());
+ image2d_b<float01_16> tmp(lena.domain());
+
+ level::transform(lena, tofloat01(), tmp);
+
+ level::median(tmp, rect, out);
+ level::median(lena, rect, ref);
+
+
+ level::transform(out, to8bits(), lena);
+
+ io::pgm::save(lena, "out.pgm");
+ io::pgm::save(ref, "ref.pgm");
+ assert(lena == ref);
+ //debug::println(out);
+ }
+
+
}
Index: trunk/milena/mln/value/float01_.hh
===================================================================
--- trunk/milena/mln/value/float01_.hh (revision 1220)
+++ trunk/milena/mln/value/float01_.hh (revision 1221)
@@ -89,12 +89,32 @@
};
+ namespace internal
+ {
+
+ template <unsigned n>
+ struct convert_< float01_<n> >
+ {
+ static float01_<n> value_at_index(std::size_t i)
+ {
+ float01_<n> tmp;
+ tmp.set_ind(i);
+ return tmp;
+ }
+
+ static std::size_t index_of_value(const float01_<n>& v)
+ {
+ return v.value_ind();
+ }
+ };
+ }
+
template <unsigned n>
struct props< float01_<n> >
{
static const std::size_t card_ = metal::pow<2, n>::value;
- static const float01_<n> min() { return 0; }
- static const float01_<n> max() { return 1; }
+ static const int min() { return 0; }
+ static const int max() { return 1; }
static const unsigned nbits = n;
typedef trait::kind::data kind;
typedef float sum;
Index: trunk/milena/mln/value/float01.hh
===================================================================
--- trunk/milena/mln/value/float01.hh (revision 1220)
+++ trunk/milena/mln/value/float01.hh (revision 1221)
@@ -146,7 +146,7 @@
double float01::value() const
{
mln_invariant(nbits_ != 0);
- return val_ / internal::two_pow_n_minus_1(nbits_);
+ return double(val_) / internal::two_pow_n_minus_1(nbits_);
}
unsigned long float01::value_ind() const