4472: Save work in progress for histo and hsl. Everything is updated.

* green/mln/accu/stat/histo3d_hsl.hh :Update library file. * green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc:Update unitary test. --- trunk/milena/sandbox/ChangeLog | 18 ++- .../sandbox/green/mln/accu/stat/histo3d_hsl.hh | 129 ++++++++++-------- .../tests/accu/stat/histo3d_hsl/histo3d_hsl.cc | 145 ++++++++++++-------- 3 files changed, 176 insertions(+), 116 deletions(-) diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog index 41f171a..d76c826 100644 --- a/trunk/milena/sandbox/ChangeLog +++ b/trunk/milena/sandbox/ChangeLog @@ -1,4 +1,12 @@ -2009-09-11 Yann Jacquelet <jacquelet@lrde.epita.fr> +2009-09-13 Yann Jacquelet <jacquelet@lrde.epita.fr> + + Save work in progress for histo and hsl. Everything is updated. + + * green/mln/accu/stat/histo3d_hsl.hh :Update library file. + * green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc:Update unitary test. + + +2009-09-13 Yann Jacquelet <jacquelet@lrde.epita.fr> Delete obsolete sources. @@ -16,11 +24,11 @@ Save work in progress for histo and hsl. - * green/mln/accu/stat/histo3d_hsl.hh : New library file. + * green/mln/accu/stat/histo3d_hsl.hh : New library file. - * green/tests/accu/stat/histo3d_hsl : New directory. - * green/tests/accu/stat/Makefile.am : New makefile. - * green/tests/accu/stat/histo3d_hsl.cc : New source file. + * green/tests/accu/stat/histo3d_hsl : New directory. + * green/tests/accu/stat/histo3d_hsl/Makefile.am : New makefile. + * green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc : New source file. 2009-09-11 Yann Jacquelet <jacquelet@lrde.epita.fr> diff --git a/trunk/milena/sandbox/green/mln/accu/stat/histo3d_hsl.hh b/trunk/milena/sandbox/green/mln/accu/stat/histo3d_hsl.hh index 40da72c..c8e71ac 100644 --- a/trunk/milena/sandbox/green/mln/accu/stat/histo3d_hsl.hh +++ b/trunk/milena/sandbox/green/mln/accu/stat/histo3d_hsl.hh @@ -67,7 +67,7 @@ #include <mln/core/alias/point3d.hh> #include <mln/core/alias/box3d.hh> -#include <mln/core/value/int_u.hh> +#include <mln/value/int_u.hh> #include <mln/trait/value/comp.hh> #include <mln/arith/plus.hh> @@ -78,7 +78,7 @@ #include <mln/value/ops.hh> // make hue cyclic -#include <mln/fun/p2p/flod.hh> +#include <mln/fun/p2p/fold.hh> #include <mln/core/image/dmorph/transformed_image.hh> namespace mln @@ -91,7 +91,7 @@ namespace mln { // Forward declaration - template <typename V> + template <unsigned q, typename V> struct histo3d_hsl; } // end of namespace mln::accu::stat @@ -102,8 +102,8 @@ namespace mln namespace trait { - template <typename V> - struct accumulator_< mln::accu::stat::histo3d_hsl<V> > + template <unsigned q, typename V> + struct accumulator_< mln::accu::stat::histo3d_hsl<q,V> > { typedef accumulator::has_untake::no has_untake; typedef accumulator::has_set_value::no has_set_value; @@ -111,10 +111,10 @@ namespace mln typedef accumulator::when_pix::use_v when_pix; }; - template <typename V> + template <unsigned q, typename V> struct set_precise_binary_<op::eq, - accu::stat::histo3d_hsl<V>, - accu::stat::histo3d_hsl<V> > + accu::stat::histo3d_hsl<q,V>, + accu::stat::histo3d_hsl<q,V> > { typedef bool ret; }; @@ -141,9 +141,9 @@ namespace mln /// q is the number of bins per axe because quantification info are died. /// we assume that V is a kind of hsl_<float,float,float> - template <typename q, typename V> + template <unsigned q, typename V> struct histo3d_hsl : - public mln::accu::internal::base<image3d<unsigned>, histo3d_hsl<V> > + public mln::accu::internal::base<image3d<unsigned>, histo3d_hsl<q,V> > { typedef V argument; typedef image3d<unsigned> result; @@ -179,7 +179,7 @@ namespace mln /// \brief Update the histogram with an other histogram. /// \param[in] other the other histogram. - void take(const histo3d_hsl<V>& other); + void take(const histo3d_hsl<q,V>& other); /// \} /// Accessors. @@ -199,6 +199,15 @@ namespace mln bool is_valid() const; protected: + const float min_hue; + const float max_hue; + float step_hue; + const float min_lum; + const float max_lum; + float step_lum; + const float min_sat; + const float max_sat; + float step_sat; result count_; }; @@ -208,53 +217,56 @@ namespace mln /// /// The operator compare all the bins from the two histogram. - template <typename V> - bool operator==(const histo3d_hsl<V>& histo1, - const histo3d_hsl<V>& histo2); + template <unsigned q, typename V> + bool operator==(const histo3d_hsl<q,V>& histo1, + const histo3d_hsl<q,V>& histo2); #ifndef MLN_INCLUDE_ONLY - template <typename V> + template <unsigned q, typename V> inline - histo3d_hsl<V>::histo3d_hsl() + histo3d_hsl<q,V>::histo3d_hsl() : min_hue(0.0), max_hue(360.0), + min_lum(0.0), max_lum(1.0), + min_sat(0.0), max_sat(1.0) { - trace::entering("mln::accu::stat::histo3d_hsl<V>::histo3d_hsl"); + trace::entering("mln::accu::stat::histo3d_hsl<q,V>::histo3d_hsl"); // As there is no info about preceding color space // we ask the end user to specify the quantification he's looking for. - count_.init_(box3d(point3d(mln_min(int_u<q>), - mln_min(int_u<q>), - mln_min(int_u<q>)), - point3d(mln_max(int_u<q>), - mln_max(int_u<q>), - mln_max(int_u<q>)))); + count_.init_(box3d(point3d(mln_min(value::int_u<q>), + mln_min(value::int_u<q>), + mln_min(value::int_u<q>)), + point3d(mln_max(value::int_u<q>), + mln_max(value::int_u<q>), + mln_max(value::int_u<q>)))); // Make the hue domain cyclic fun::p2p::fold<point3d,1,0,0> fold_(count_.domain()); transform_domain(count_, fold_); - // Build the interpolate ?? - // cf code igr - - trace::exiting("mln::accu::stat::histo3d_hsl<V>::histo3d_hsl"); + step_hue = (max_hue - min_hue)/q; + step_lum = (max_lum - min_lum)/q; + step_sat = (max_sat - min_sat)/q; + + trace::exiting("mln::accu::stat::histo3d_hsl<q,V>::histo3d_hsl"); } - template <typename V> + template <unsigned q, typename V> inline - void histo3d_hsl<V>::init() + void histo3d_hsl<q,V>::init() { - trace::entering("mln::accu::stat::histo3d_hsl<V>::init"); + trace::entering("mln::accu::stat::histo3d_hsl<q,V>::init"); data::fill(count_, 0); - trace::exiting("mln::accu::stat::histo3d_hsl<V>::init"); + trace::exiting("mln::accu::stat::histo3d_hsl<q,V>::init"); } - template <typename V> + template <unsigned q, typename V> inline - void histo3d_hsl<V>::take(const argument& t) + void histo3d_hsl<q,V>::take(const argument& t) { - trace::entering("mln::accu::stat::histo3d_hsl<V>::take"); + trace::entering("mln::accu::stat::histo3d_hsl<q,V>::take"); // Just convert a greyscale value (int_u8 like) to a position for an // iterator on the resulting image. @@ -264,57 +276,64 @@ namespace mln // Technical way to access i° component without kwnowing the name // mln::trait::value_<argument>::get_comp_0(t); - ++count_(point3d(t.hue(), t.sat(), t.lum())); + // is def::coord1d the type of x, y, z ?? + unsigned x = (t.hue() - min_hue)/q; + unsigned y = (t.lum() - min_lum)/q; + unsigned z = (t.sat() - min_sat)/q; + + // faire attention avec les histoires de points et leurs coordonnées + ++count_(point3d(z, x, y)); + //++count_(point3d(t.hue(), t.sat(), t.lum())); - trace::exiting("mln::accu::stat::histo3d_hsl<V>::take"); + trace::exiting("mln::accu::stat::histo3d_hsl<q,V>::take"); } - template <typename V> + template <unsigned q, typename V> inline - void histo3d_hsl<V>::take(const histo3d_hsl<V>& other) + void histo3d_hsl<q,V>::take(const histo3d_hsl<q,V>& other) { - trace::entering("mln::accu::stat::histo3d_hsl<V>::take"); + trace::entering("mln::accu::stat::histo3d_hsl<q,V>::take"); count_ += other.count_; - trace::exiting("mln::accu::stat::histo3d_hsl<V>::take"); + trace::exiting("mln::accu::stat::histo3d_hsl<q,V>::take"); } - template <typename V> + template <unsigned q, typename V> inline - typename histo3d_hsl<V>::result histo3d_hsl<V>::to_result() const + typename histo3d_hsl<q,V>::result histo3d_hsl<q,V>::to_result() const { - trace::entering("mln::accu::stat::histo3d_hsl<V>::to_result"); + trace::entering("mln::accu::stat::histo3d_hsl<q,V>::to_result"); - trace::exiting("mln::accu::stat::histo3d_hsl<V>::to_result"); + trace::exiting("mln::accu::stat::histo3d_hsl<q,V>::to_result"); return count_; } - template <typename V> + template <unsigned q, typename V> inline - histo3d_hsl<V>::operator result() const + histo3d_hsl<q,V>::operator result() const { - trace::entering("mln::accu::stat::histo3d_rgb<V>::operator result"); + trace::entering("mln::accu::stat::histo3d_rgb<q,V>::operator result"); - trace::exiting("mln::accu::stat::histo3d_rgb<V>::operator result"); + trace::exiting("mln::accu::stat::histo3d_rgb<q,V>::operator result"); return count_; } - template <typename V> + template <unsigned q, typename V> inline - bool histo3d_hsl<V>::is_valid() const + bool histo3d_hsl<q,V>::is_valid() const { - trace::entering("mln::accu::stat::histo3d_hsl<V>::is_valid"); + trace::entering("mln::accu::stat::histo3d_hsl<q,V>::is_valid"); bool result = count_.is_valid(); - trace::exiting("mln::accu::stat::histo3d_hsl<V>::is_valid"); + trace::exiting("mln::accu::stat::histo3d_hsl<q,V>::is_valid"); return result; } - template <typename V> - bool operator==(const histo3d_hsl<V>& histo1, - const histo3d_hsl<V>& histo2) + template <unsigned q, typename V> + bool operator==(const histo3d_hsl<q,V>& histo1, + const histo3d_hsl<q,V>& histo2) { trace::entering("mln::accu::stat::operator=="); diff --git a/trunk/milena/sandbox/green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc b/trunk/milena/sandbox/green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc index 6d8f0b8..27a6b64 100644 --- a/trunk/milena/sandbox/green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc +++ b/trunk/milena/sandbox/green/tests/accu/stat/histo3d_hsl/histo3d_hsl.cc @@ -57,29 +57,34 @@ #include <mln/trait/image/print.hh> #include <mln/trait/value_.hh> +#include <mln/core/concept/function.hh> + -/* template <unsigned n> void test_operator_equal() { using namespace mln::accu::stat; - typedef mln::value::rgb<n> rgbn; - mln::accu::stat::histo3d_rgb<rgbn> histo1; - mln::accu::stat::histo3d_rgb<rgbn> histo2; - rgbn val(3,3,3); + typedef mln::value::rgb<n> rgbn; + typedef mln::value::hsl_f hsl_f; + typedef mln::fun::v2v::f_rgb_to_hsl_<hsl_f> rgb_to_hsl_f; + rgb_to_hsl_f convert; + mln::accu::stat::histo3d_hsl<n,hsl_f> histo1; + mln::accu::stat::histo3d_hsl<n,hsl_f> histo2; + rgbn val_rgb(n,n,n); + hsl_f val_hsl = convert(val_rgb); histo1.init(); histo2.init(); mln_assertion(histo1 == histo2); - histo1.take(val); + histo1.take(val_hsl); /// FIXME mln_assertion(histo1 != histo2); doesn't work!! mln_assertion(!(histo1 == histo2)); - histo2.take(val); + histo2.take(val_hsl); mln_assertion(histo1 == histo2); @@ -90,8 +95,9 @@ template <unsigned n> void test_instantiation_without_argument() { typedef mln::value::rgb<n> rgbn; - typedef mln_trait_value_comp(rgbn,0) comp; - const mln::accu::stat::histo3d_rgb<rgbn> histo; + typedef mln::value::hsl_f hsl_f; + typedef mln::value::int_u<n> comp; + const mln::accu::stat::histo3d_hsl<n,hsl_f>histo; const mln::image3d<unsigned>& res = histo.to_result(); const mln::point3d& min =mln::point3d(mln_min(comp), mln_min(comp), @@ -110,11 +116,11 @@ void test_instantiation_without_argument() template <unsigned n> void test_initialization() { - typedef mln::value::int_u<n> int_un; - typedef mln::value::rgb<n> rgbn; - mln::accu::stat::histo3d_rgb<rgbn> histo; - mln::image3d<unsigned> img_res = histo.to_result(); - mln::image3d<unsigned> img_ref; + typedef mln::value::int_u<n> int_un; + typedef mln::value::hsl_f hsl_f; + mln::accu::stat::histo3d_hsl<n, hsl_f> histo; + mln::image3d<unsigned> img_res = histo.to_result(); + mln::image3d<unsigned> img_ref; mln::initialize(img_ref, img_res); mln::data::fill(img_ref, 0); @@ -131,11 +137,11 @@ void test_initialization() template <unsigned n> void test_take_argument() { - typedef mln::value::int_u<n> int_un; - typedef mln::value::rgb<n> rgbn; - mln::accu::stat::histo3d_rgb<rgbn> histo1; - mln::accu::stat::histo3d_rgb<rgbn> histo2; - rgbn val(3,3,3); + typedef mln::value::int_u<n> int_un; + typedef mln::value::hsl_f hsl_f; + mln::accu::stat::histo3d_hsl<n,hsl_f> histo1; + mln::accu::stat::histo3d_hsl<n,hsl_f> histo2; + hsl_f val(0.0,0.0,0.0); histo1.init(); histo2.init(); @@ -148,7 +154,7 @@ void test_take_argument() const unsigned ref = mln::data::compute(mln::accu::math::sum<int_un>(), img2); mln_assertion(ref == res-1); - mln_assertion(1 == img1(mln::point3d(val.red(), val.green(), val.blue()))); + mln_assertion(1 == img1(mln::point3d(0, 0, 0))); std::cout << "(" << n << " bits) histo.take(argument) : ok" << std::endl; } @@ -156,11 +162,11 @@ void test_take_argument() template <unsigned n> void test_take_other() { - typedef mln::value::rgb<n> rgbn; - mln::accu::stat::histo3d_rgb<rgbn> histo1; - mln::accu::stat::histo3d_rgb<rgbn> histo2; - mln::accu::stat::histo3d_rgb<rgbn> histo3; - rgbn val(3,3,3); + typedef mln::value::hsl_f hsl_f; + mln::accu::stat::histo3d_hsl<n,hsl_f> histo1; + mln::accu::stat::histo3d_hsl<n,hsl_f> histo2; + mln::accu::stat::histo3d_hsl<n,hsl_f> histo3; + hsl_f val(0.0,0.0,0.0); histo1.init(); histo2.init(); @@ -269,31 +275,65 @@ mln::algebra::mat<3,3,float> var_histo2(const mln::image3d<unsigned>& img) return result; } +struct hslf_2_vec3f : public mln::Function_v2v< hslf_2_vec3f > +{ + typedef mln::algebra::vec<3,float> result; + result operator()(const mln::value::hsl_f& hsl) const; +}; + +mln::algebra::vec<3,float> +hslf_2_vec3f::operator()(const mln::value::hsl_f& hsl) const +{ + return mln::make::vec(hsl.hue(), hsl.lum(), hsl.sat()); +} + + +template <typename A, typename I, typename F> +mln_result(A) +compute(mln::Accumulator<A>& a_, + const mln::Image<I>& input_, + const mln::Function_v2v<F>& fn_) +{ + A& a = exact(a_); + const I& input = exact(input_); + const F& fn = exact(fn_); + + mln_piter(I) p(input.domain()); + for_all(p) + a.take(fn(input(p))); + + return a.result(); +} + + template <unsigned n> void test_integration() { - typedef mln::value::rgb8 rgb8; - typedef mln::value::rgb<n> rgbn; - typedef mln::algebra::vec<3,float> vec3f; - typedef mln::algebra::mat<3,3,float> mat3f; - typedef mln::accu::math::count<rgbn> count; - typedef mln::accu::math::sum<rgbn,vec3f> sum; - typedef mln::accu::stat::mean<rgbn,vec3f,vec3f> mean; - typedef mln::accu::stat::var<vec3f> var; + typedef mln::value::rgb8 rgb8; + typedef mln::value::rgb<n> rgbn; + typedef mln::value::hsl_f hsl_f; + typedef mln::algebra::vec<3,float> vec3f; + typedef mln::algebra::mat<3,3,float> mat3f; + typedef mln::accu::math::count<hsl_f> count; + typedef mln::accu::math::sum<hsl_f,vec3f> sum; + typedef mln::accu::stat::mean<hsl_f,vec3f,vec3f> mean; + typedef mln::accu::stat::var<vec3f> var; mln::image2d<rgb8> img_fst; - mln::image2d<rgbn> img_ref; + mln::image2d<rgbn> img_sec; + mln::image2d<hsl_f> img_ref; mln::image3d<unsigned> img_res; mln::io::ppm::load(img_fst, OLENA_IMG_PATH"/lena.ppm"); - img_ref = mln::data::transform(img_fst, mln::fun::v2v::rgb8_to_rgbn<n>()); + img_sec = mln::data::transform(img_fst, mln::fun::v2v::rgb8_to_rgbn<n>()); + img_ref = mln::data::transform(img_sec,mln::fun::v2v::f_rgb_to_hsl_<hsl_f>()); - const double count_ref = mln::data::compute(count(), img_ref); - const vec3f sum_ref = mln::data::compute(sum(), img_ref); - const vec3f mean_ref = mln::data::compute(mean(), img_ref); - const mat3f var_ref = mln::data::compute(var(), img_ref); + const double count_ref = compute(count(), img_ref, hslf_2_vec3f()); + // const vec3f sum_ref = mln::data::compute(sum(), img_ref); + const vec3f mean_ref = compute(mean(), img_ref, hslf_2_vec3f()); + const mat3f var_ref = compute(var(), img_ref, hslf_2_vec3f()); - img_res = mln::data::compute(mln::accu::stat::histo3d_rgb<rgbn>(), img_ref); + img_res = mln::data::compute(mln::accu::stat::histo3d_hsl<n,hsl_f>(),img_ref); const double count_res = count_histo(img_res); @@ -310,7 +350,7 @@ void test_integration() mln_assertion(count_ref == count_res); - + /* mln_assertion(0.0001 > abs(mean_ref[0] - mean_res[0])); mln_assertion(0.0001 > abs(mean_ref[1] - mean_res[1])); mln_assertion(0.0001 > abs(mean_ref[2] - mean_res[2])); @@ -327,12 +367,10 @@ void test_integration() mln_assertion(0.0001 > abs(var_ref(2,2) - var_res(2,2))); mln_assertion(0.0001 > abs(var_ref(2,1) - var_res(2,1))); mln_assertion(0.0001 > abs(var_ref(1,2) - var_res(1,2))); - + */ std::cout << "(" << n << " bits) test integration : ok" << std::endl; } -*/ - void test() { typedef mln::value::rgb8 rgb8; @@ -358,18 +396,13 @@ void test() int main() { - /* - test_operator_equal<8>(); - test_instantiation_without_argument<8>(); - test_initialization<8>(); - test_take_argument<8>(); - test_take_other<8>(); - test_integration<8>(); - */ - - // p2p/fold+transform_domain for hcv - - test(); + test_operator_equal<3>(); + test_instantiation_without_argument<3>(); + test_initialization<3>(); + test_take_argument<3>(); + test_take_other<3>(); + test_integration<3>(); + return 0; } -- 1.5.6.5
participants (1)
-
Yann Jacquelet