
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2008-03-03 Caroline Vigouroux <vigour_c@epita.fr> loading image and convertion in new color mode test. * color/is_HSI.cc: test conversion. * color/my_hsi.hh: correct a bug. * color/rgb_to_hsi.hh: correct a bug. * color/rgb_to_xyz.hh: correct a bug. * color/tests.cc: test conversion. * load.cc: New loader. * tests.cc: New tests. --- color/is_HSI.cc | 13 +++++++ color/my_hsi.hh | 94 ++++++++++++++++++++++++++-------------------------- color/rgb_to_hsi.hh | 66 +++++++++++++++++++++++++++++------- color/rgb_to_xyz.hh | 3 - color/tests.cc | 3 + load.cc | 38 +++++++++++++++++++++ tests.cc | 31 +++++++++++++++++ 7 files changed, 186 insertions(+), 62 deletions(-) Index: trunk/milena/sandbox/vigouroux/load.cc =================================================================== --- trunk/milena/sandbox/vigouroux/load.cc (revision 0) +++ trunk/milena/sandbox/vigouroux/load.cc (revision 1760) @@ -0,0 +1,38 @@ +#include <mln/core/image2d.hh> +#include <mln/value/int_u8.hh> +#include <mln/display/save_and_show.hh> +#include <mln/value/rgb.hh> +#include <mln/value/rgb8.hh> + +#include <mln/io/ppm/load.hh> +#include <mln/io/ppm/save.hh> +#include <mln/math/round.hh> +#include <mln/level/transform.hh> + +#include <mln/core/w_window2d_float.hh> +#include <mln/border/thickness.hh> +#include <mln/linear/convolve.hh> + +# include <mln/display/save.hh> +# include <mln/display/show.hh> + +int main() +{ + using namespace mln; + using value::int_u8; + image2d<mln::value::rgb8> lena; + io::ppm::load(lena, "../../img/lena.ppm"); +// image2d<mln::value::hsi_3x8> inter(lena.domain()); + image2d<mln::value::rgb8> out(lena.domain()); + const image2d<mln::value::rgb8> input = exact(lena); + +// mln_piter(image2d<mln::value::rgb8>) p(input.domain()); +// for_all(p) +// { +// inter(p) = fun::v2v::f_rgb_to_hsi_3x8(p); + +// } + + display::save_and_show (lena, "display", 1); +} + Index: trunk/milena/sandbox/vigouroux/tests.cc =================================================================== --- trunk/milena/sandbox/vigouroux/tests.cc (revision 0) +++ trunk/milena/sandbox/vigouroux/tests.cc (revision 1760) @@ -0,0 +1,31 @@ +#include <mln/core/image_if_value.hh> +#include <mln/core/inplace.hh> +#include <mln/core/w_window2d_int.hh> +#include <mln/display/show.hh> +#include <mln/io/ppm/save.hh> +#include <mln/display/save_and_show.hh> +#include <mln/level/fill.hh> + +#include "rgb_to_yuv.hh" +#include "my_yuv.hh" + +#include "rgb_to_xyz.hh" +#include "my_xyz.hh" + +#include "rgb_to_cmy.hh" +#include "my_cmy.hh" + +#include "rgb_to_hsi.hh" +#include "my_hsi.hh" + +int main() +{ + using namespace mln; + + struct value::yuv<8> yuv(4, 4, 4); + std::cout << yuv.y() << std::endl; + std::cout << yuv.u() << std::endl; + std::cout << yuv.v() << std::endl; + + return (0); +} Index: trunk/milena/sandbox/vigouroux/color/rgb_to_xyz.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/rgb_to_xyz.hh (revision 1759) +++ trunk/milena/sandbox/vigouroux/color/rgb_to_xyz.hh (revision 1760) @@ -25,7 +25,7 @@ xyz.z(0.010 * rgb.green() + 0.990 * rgb.blue()); return (xyz); -_ } + } }; struct f_xyz_to_rgb @@ -33,7 +33,6 @@ struct value::rgb<8> doit(const struct value::xyz<8> xyz) const { - struct value::rgb<8> rgb; int r; int g; int b; Index: trunk/milena/sandbox/vigouroux/color/tests.cc =================================================================== --- trunk/milena/sandbox/vigouroux/color/tests.cc (revision 1759) +++ trunk/milena/sandbox/vigouroux/color/tests.cc (revision 1760) @@ -9,6 +9,9 @@ #include "rgb_to_yuv.hh" #include "my_yuv.hh" +#include "rgb_to_xyz.hh" +#include "my_xyz.hh" + #include "rgb_to_cmy.hh" #include "my_cmy.hh" Index: trunk/milena/sandbox/vigouroux/color/my_hsi.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1759) +++ trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1760) @@ -21,14 +21,14 @@ { }; - template <typename F> - class hsi_ : public HSI< hsi_<F> > + template <typename H, typename S, typename I> + class hsi_ : public HSI< hsi_<H,S,I> > { public: - typedef F h_type; - typedef F s_type; - typedef F i_type; + typedef H h_type; + typedef S s_type; + typedef I i_type; /// Constructor without argument. hsi_() @@ -36,50 +36,50 @@ } /// Constructor from component values. - hsi_(const F& h, const F& s, const F& i) - : h_(h), - s_(s), - i_(i) + hsi_(const H& hue, const S& sat, const I& i) + : hue_(hue), + sat_(sat), + int_(i) { } - /// Read-only access to the h component. - const F& h() const + /// Read-only access to the hue component. + const H& hue() const { - return this->h_; + return this->hue_; } - const F& s() const + const S& sat() const { - return this->s_; + return this->sat_; } - const F& i() const + const I& i() const { - return this->i_; + return this->int_; } - /// Read-write access to the h component. - F& h() + /// Read-write access to the hue component. + H& hue() { - return this->h_; + return this->hue_; } - F& s() + S& sat() { - return this->s_; + return this->sat_; } - F& i() + I& i() { - return this->i_; + return this->int_; } private: - F h_; - F s_; - F i_; + H hue_; + S sat_; + I int_; }; - typedef hsi_<float01_8> hsi_3x8; + typedef hsi_<float, float, float> hsi_3x8; - typedef hsi_<double> hsi_d; + typedef hsi_<double, double, double> hsi_d; @@ -91,32 +91,32 @@ hsi<n>(); /// Constructor from component values. - hsi<n>(int h, int s, int i); + hsi<n>(double hue, double sat, double i); /// Access to component values. - double h() const { return this->h_; } - double s() const { return this->s_; } - double i() const { return this->i_; } + double hue() const { return this->hue_; } + double sat() const { return this->sat_; } + double i() const { return this->int_; } /// Set component values. - void h(double h) + void hue(double hue) { - this->h_ = h; + this->hue_ = hue; } - void s(double s) + void sat(double sat) { - this->s_ = s; + this->sat_ = sat; } void i(double i) { mln_precondition(i >= 0); - this->i_ = i; + this->int_ = i; } private: - double h_; - double s_; - double i_; + double hue_; + double sat_; + double int_; }; @@ -125,19 +125,19 @@ template <unsigned n> inline hsi<n>::hsi() - :h_(0), s_(0), i_(0) + :hue_(0), sat_(0), int_(0) { } template <unsigned n> inline - hsi<n>::hsi(int h, int s, int i) + hsi<n>::hsi(double h, double sat, double i) { - mln_precondition(h >= 0); - mln_precondition(s >= 0); - mln_precondition(i >= 0); - this->h_ = h; - this->s_ = s; + mln_invariant(h >= 0); + mln_invariant(sat >= 0); + mln_invariant(i >= 0); + this->hue_ = h; + this->sat_ = sat; this->i_ = i; } Index: trunk/milena/sandbox/vigouroux/color/is_HSI.cc =================================================================== --- trunk/milena/sandbox/vigouroux/color/is_HSI.cc (revision 1759) +++ trunk/milena/sandbox/vigouroux/color/is_HSI.cc (revision 1760) @@ -16,5 +16,18 @@ std::cout << mlc_is_a(rgb8, HSI)::value << std::endl; rgb8 c(255, 10, 1); + rgb8 other(10, 20, 30); + + // Essai en 0 255 + hsi_3x8 c_hsi = fun::v2v::f_rgb_to_hsi_3x8(c); + rgb8 c2 = fun::v2v::f_hsi_to_rgb_3x8(c_hsi); + std::cout << "c = " << c << std::endl; + std::cout << "c2 = " << c2 << std::endl; + + hsi_3x8 c_cool = fun::v2v::f_rgb_to_hsi_3x8(other); + rgb8 coucou = fun::v2v::f_hsi_to_rgb_3x8(c_cool); + + std::cout << "c = " << other << std::endl; + std::cout << "c2 = " << coucou << std::endl; } Index: trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh =================================================================== --- trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1759) +++ trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1760) @@ -1,3 +1,4 @@ + #include <cmath> #include <mln/core/image_if_value.hh> @@ -49,11 +50,11 @@ std::cout << "FIXME: " << tmp << std::endl; } - hsi.h() = atan2(beta, alpha) / 3.1415 * 180.0; - if (hsi.h() < 0) - hsi.h() = hsi.h() + 360.0; - mln_invariant(hsi.h() >= 0); - hsi.s() = std::sqrt(alpha * alpha + beta * beta); + hsi.hue() = atan2(beta, alpha) / 3.1415 * 180.0; + if (hsi.hue() < 0) + hsi.hue() = hsi.hue() + 360.0; + mln_invariant(hsi.hue() >= 0); + hsi.sat() = std::sqrt(alpha * alpha + beta * beta); hsi.i() = sqrt3_3 * rgb.red() + sqrt3_3 * rgb.green() + sqrt3_3 * rgb.blue(); return hsi; @@ -66,6 +67,45 @@ // end of NEW + // NEW2 + + template <typename T_rgb> + struct f_hsi_to_rgb_ : public Function_v2v< f_hsi_to_rgb_<T_rgb> > + { + typedef T_rgb result; + + template <typename T_hsi> + T_rgb operator()(const T_hsi& hsi) const + { + int r; + int g; + int b; + + static const double sqrt3_3 = sqrt(3) / 3; + static const double inv_sqrt6 = 1 / sqrt(6); + static const double inv_sqrt2 = 1 / sqrt(2); + + double h = hsi.hue() / 180.0 * 3.1415; + double alpha = hsi.sat() * cos(h); + double beta = hsi.sat() * sin(h); + + r = int(sqrt3_3 * hsi.i() + 2 * inv_sqrt6 * beta); + g = int(sqrt3_3 * hsi.i() + inv_sqrt2 * alpha - inv_sqrt6 * beta); + b = int(sqrt3_3 * hsi.i() - inv_sqrt2 * alpha - inv_sqrt6 * beta); + + T_rgb rgb(r, g, b); + + return rgb; + } + }; + + typedef f_hsi_to_rgb_<value::rgb8> f_hsi_to_rgb_3x8_t; + + f_hsi_to_rgb_3x8_t f_hsi_to_rgb_3x8; + + // end of NEW2 + + } // end of namespace fun::v2v } // end of namespace fun @@ -88,11 +128,11 @@ double alpha = inv_sqrt2 * rgb.green() - inv_sqrt2 * rgb.blue(); double beta = 2 * inv_sqrt6 * rgb.red() - inv_sqrt6 * rgb.green() - inv_sqrt6 * rgb.blue(); - hsi.h(atan2(beta, alpha) / 3.1415 * 180.0); - if (hsi.h() < 0) - hsi.h(hsi.h() + 360.0); - mln_precondition(hsi.h() >= 0); - hsi.s(sqrt(alpha * alpha + beta * beta)); + hsi.hue(atan2(beta, alpha) / 3.1415 * 180.0); + if (hsi.hue() < 0) + hsi.hue(hsi.hue() + 360.0); + mln_precondition(hsi.hue() >= 0); + hsi.sat(sqrt(alpha * alpha + beta * beta)); hsi.i(sqrt3_3 * rgb.red() + sqrt3_3 * rgb.green() + sqrt3_3 * rgb.blue()); return hsi; @@ -113,9 +153,9 @@ double inv_sqrt6 = 1 / sqrt(6); double inv_sqrt2 = 1 / sqrt(2); - double h = hsi.h() / 180.0 * 3.1415; - double alpha = hsi.s() * cos(h); - double beta = hsi.s() * sin(h); + double h = hsi.hue() / 180.0 * 3.1415; + double alpha = hsi.sat() * cos(h); + double beta = hsi.sat() * sin(h); r = int(sqrt3_3 * hsi.i() + 2 * inv_sqrt6 * beta); g = int(sqrt3_3 * hsi.i() + inv_sqrt2 * alpha - inv_sqrt6 * beta);