1791: Update test on rgb/hsi conversion.

https://svn.lrde.epita.fr/svn/oln/trunk Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Update test on rgb/hsi conversion. * milena/doc/tutorial/image_types.txt: Augment. * milena/mln/value/rgb.hh (red_t, green_t, blue_t): New. * milena/sandbox/vigouroux/moyenne.cc: Update. doc/tutorial/image_types.txt | 80 ++++++++++++++++++++++++++++++++++++++++--- mln/value/rgb.hh | 4 ++ sandbox/vigouroux/moyenne.cc | 55 +++++++++++++---------------- 3 files changed, 106 insertions(+), 33 deletions(-) Index: milena/doc/tutorial/image_types.txt --- milena/doc/tutorial/image_types.txt (revision 1790) +++ milena/doc/tutorial/image_types.txt (working copy) @@ -236,23 +236,95 @@ ** methods -*** values +*** about the image variable +**** has_data + +sig is: bool has_data() const -// FIXME: ? better name is is_allocated Nota bene: is_initialized means "has relevant data"! +is "is_allocated" / "is_ready" a better name? + +Nota bene: "is_initialized" is consistent with the "initialize" +routine; yet, it means "has relevant data", which is not really +what it meant! + +**** name_it(string) + +Later... + +*** about definition domain + +**** domain const pset& domain() const + +**** has & owns_ + bool has(const psite& p) const bool owns_(const psite& p) const -const box_<point>& bbox() const -std::size_t npoints() const +Major question: is ima.has(p) equivalent to ima.domain().has(p)? or +(if it is equivalent) do we feature a specific method has_extended()? + +Remember that in the case of a window, we want to write: + +for_all(p) + for_all(q) + if (ima.has(q)) + .. + +so that there is a decoupling between a window and an image. More +precisely a site q of a window centered at p can lay outside the +definition domain, thus we need the "has" test. Such a decoupling is +great since we can reuse some window or neighborhood definition over a +domain which is compatible but restricted. This is also true for a +graph on which some window (resp. neighborhood) is defined and can be +applied over a sub-graph. + +The owns_ method is weird because it is only internal. + +**** suggestion + +"has(p)" means that there is a value for p. The set of sites p that +verify "has(p) = true" is the "extended domain." Some image types +features such an extension; some other do not. + +We always have: + ima.domain().has(p) => ima.has(p) + +If the image ima does not extend the definition domain, we have: + ima.domain().has(p) <=> ima.has(p) + +A site p is in the extended domain iff: + ima.has(p) and not ima.domain().has(p). + +*** about data access rvalue operator()(const psite& p) const lvalue operator()(const psite& p) +*** about destination space + const vset& destination() const // was: values() +*** obsolete methods + +**** bbox + +const box_<point>& bbox() const + +too ambiguous because we want a bounding box: +- either precise or approximative (larger) +- on a grid (if possible) +- on the space (if sites are located) + +remember that some image have sites that are not localized (and then a +bbox, if it exists, can only be a index range for instance) + +**** npoints + +std::size_t npoints() const +is useless since the user can write ima.domain().nsites() * properties Index: milena/mln/value/rgb.hh --- milena/mln/value/rgb.hh (revision 1790) +++ milena/mln/value/rgb.hh (working copy) @@ -162,6 +162,10 @@ { public: + typedef int_u<n> red_t; + typedef int_u<n> green_t; + typedef int_u<n> blue_t; + /// \{ Acces to red/green/blue component. int_u<n> red() const { return this->v_[0]; } int_u<n>& red() { return this->v_[0]; } Index: milena/sandbox/vigouroux/moyenne.cc --- milena/sandbox/vigouroux/moyenne.cc (revision 1790) +++ milena/sandbox/vigouroux/moyenne.cc (working copy) @@ -1,7 +1,9 @@ #include "color/my_hsi.hh" #include "color/rgb_to_hsi.hh" -#include <mln/display/save_and_show.hh> -#include <mln/value/rgb.hh> + +#include <cmath> + +#include <mln/core/image2d.hh> #include <mln/value/rgb8.hh> #include <mln/io/ppm/load.hh> @@ -9,43 +11,43 @@ #include <mln/math/round.hh> #include <mln/level/transform.hh> -#include <mln/core/image2d.hh> -#include <cmath> -#include <iostream> -template <typename I, typename O> -float rms (const I& ima, O& out) +template <typename I1, typename I2> +float rms(const mln::Image<I1>& ima1_, const mln::Image<I2>& ima2_) { - mln::value::rgb8 c1; - mln::value::rgb8 c2; - float distred = 0; - float distgreen = 0; - float distblue = 0; - float sum = 0; - float nb = 0; - float moy = 0; + const I1& ima1 = exact(ima1_); + const I2& ima2 = exact(ima2_); + + mln_precondition(ima1.has_data() && ima2.has_data()); + + double sum = 0, nb = 0; - mln_piter(I) p(out.domain()); + mln_piter(I1) p(ima1.domain()); for_all(p) { - c1 = ima(p); - c2 = out(p); - distred = c2.red() - c1.red(); - distgreen = c2.green() - c1.green(); + mln_value(I1) c1 = ima1(p); + mln_value(I2) c2 = ima2(p); + double + distred = c2.red() - c1.red(), + distgreen = c2.green() - c1.green(), distblue = c2.blue() - c1.blue(); ++nb; sum += distred * distred + distblue * distblue + distgreen * distgreen; } - moy = std::sqrt(sum / nb); - return (moy); + + if (nb = 0) + return 0; + + return std::sqrt(sum / nb); } + int main() { using namespace mln; - using value::int_u8; + image2d<value::rgb8> lena; io::ppm::load(lena, "../../img/lena.ppm"); @@ -55,12 +57,7 @@ image2d<value::rgb8> lena_rgb = level::transform(lena_hsi, fun::v2v::f_hsi_to_rgb_3x8); - - float err = rms(lena, lena_rgb); - + double err = rms(lena, lena_rgb); std::cout << "err: " << err << std::endl; - - display::save_and_show (lena_rgb, "display", 50); - return (0); }
participants (1)
-
Thierry Geraud