last-svn-commit-8-g03c3d97 2009-12-15 Yann Jacquelet <jacquelet@lrde.epita.fr>

Introduce clipart operators described by Millet. * green/demo/annoting/nb_color: New demonstration directory. * green/demo/annoting/nb_color/Makefile.am: New Makefile. * green/demo/annoting/nb_color/nb_color.cc: New source file. * green/demo/annoting/stddev_color: New demonstration directory. * green/demo/annoting/stddev_color/Makefile.am: New Makefile. * green/demo/annoting/stddev_color/stddev_color.cc: New source file. --- milena/sandbox/ChangeLog | 12 ++ .../demo/annoting/{bic => nb_color}/Makefile.am | 0 .../green/demo/annoting/nb_color/nb_color.cc | 101 ++++++++++++++++ .../annoting/{bic => stddev_color}/Makefile.am | 0 .../demo/annoting/stddev_color/stddev_color.cc | 124 ++++++++++++++++++++ 5 files changed, 237 insertions(+), 0 deletions(-) copy milena/sandbox/green/demo/annoting/{bic => nb_color}/Makefile.am (100%) create mode 100644 milena/sandbox/green/demo/annoting/nb_color/nb_color.cc copy milena/sandbox/green/demo/annoting/{bic => stddev_color}/Makefile.am (100%) create mode 100644 milena/sandbox/green/demo/annoting/stddev_color/stddev_color.cc diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog index aed61bf..db8bd10 100644 --- a/milena/sandbox/ChangeLog +++ b/milena/sandbox/ChangeLog @@ -1,3 +1,15 @@ +2009-12-15 Yann Jacquelet <jacquelet@lrde.epita.fr> + + Introduce clipart operators described by Millet. + + * green/demo/annoting/nb_color: New demonstration directory. + * green/demo/annoting/nb_color/Makefile.am: New Makefile. + * green/demo/annoting/nb_color/nb_color.cc: New source file. + + * green/demo/annoting/stddev_color: New demonstration directory. + * green/demo/annoting/stddev_color/Makefile.am: New Makefile. + * green/demo/annoting/stddev_color/stddev_color.cc: New source file. + 2009-12-02 Yann Jacquelet <jacquelet@lrde.epita.fr> Optimize regional maxima processing for statistical counts and outputs. diff --git a/milena/sandbox/green/demo/annoting/bic/Makefile.am b/milena/sandbox/green/demo/annoting/nb_color/Makefile.am similarity index 100% copy from milena/sandbox/green/demo/annoting/bic/Makefile.am copy to milena/sandbox/green/demo/annoting/nb_color/Makefile.am diff --git a/milena/sandbox/green/demo/annoting/nb_color/nb_color.cc b/milena/sandbox/green/demo/annoting/nb_color/nb_color.cc new file mode 100644 index 0000000..9ad5666 --- /dev/null +++ b/milena/sandbox/green/demo/annoting/nb_color/nb_color.cc @@ -0,0 +1,101 @@ +// COUNTING THE IMAGE COLORS + +#include <iostream> +#include <sstream> + +#include <mln/img_path.hh> + +#include <mln/accu/math/sum.hh> +#include <mln/accu/math/count.hh> +#include <mln/accu/stat/histo3d_rgb.hh> +#include <mln/accu/stat/mean.hh> +#include <mln/accu/stat/variance.hh> + +#include <mln/algebra/vec.hh> + +#include <mln/arith/diff_abs.hh> + +#include <mln/core/macros.hh> +#include <mln/core/alias/neighb3d.hh> +#include <mln/core/image/image2d.hh> +#include <mln/core/image/image3d.hh> +#include <mln/core/image/dmorph/image_if.hh> +#include <mln/core/routine/initialize.hh> + +#include <mln/data/compute.hh> +#include <mln/data/fill.hh> +#include <mln/data/transform.hh> + +#include <mln/fun/v2v/rgb8_to_rgbn.hh> + +#include <mln/io/pgm/load.hh> +#include <mln/io/pgm/save.hh> +#include <mln/io/ppm/load.hh> +#include <mln/io/ppm/save.hh> + +#include <mln/labeling/regional_maxima.hh> +#include <mln/labeling/mean_values.hh> +#include <mln/labeling/compute.hh> + +#include <mln/literal/colors.hh> + +#include <mln/morpho/opening/volume.hh> +#include <mln/morpho/elementary/dilation.hh> + +#include <mln/opt/at.hh> + +#include <mln/pw/cst.hh> + +#include <mln/util/array.hh> +#include <mln/util/timer.hh> + +#include <mln/value/label_8.hh> +#include <mln/value/rgb8.hh> +#include <mln/value/rgb.hh> +#include <mln/value/int_u.hh> + + +// n < 8, n is the degree of quantification +template <unsigned n> +unsigned count_image_color(const std::string& image) +{ + typedef mln::value::int_u8 t_int_u8; + typedef mln::value::rgb8 t_rgb8; + typedef mln::value::rgb<n> t_rgbn; + typedef mln::image2d<t_rgb8> t_image2d_rgb8; + typedef mln::image2d<t_rgbn> t_image2d_rgbn; + typedef mln::image3d<unsigned> t_histo3d; + typedef mln::fun::v2v::rgb8_to_rgbn<n> t_rgb8_to_rgbn; + typedef mln::accu::meta::stat::histo3d_rgb t_histo3d_fun; + typedef mln::accu::meta::math::count t_count_fun; + + t_image2d_rgb8 input_rgb8; + t_image2d_rgbn input_rgbn; + t_image2d_rgbn output_rgbn; + t_histo3d histo; + t_histo3d opened; + + mln::io::ppm::load(input_rgb8, image.c_str()); + + unsigned nb_pixel = input_rgb8.ncols() * input_rgb8.nrows(); +// unsigned min_volume = (unsigned)(nb_pixel * 0.054); + unsigned nb_color = 0; + + input_rgbn = mln::data::transform(input_rgb8, t_rgb8_to_rgbn()); + histo = mln::data::compute(t_histo3d_fun(), input_rgbn); + nb_color = mln::data::compute(t_count_fun(), + (histo | (mln::pw::value(histo) != 0)).rw()); + + return nb_color; +} + + +int main() +{ + unsigned val = count_image_color<8>(ANNOTING_PHOTO_IMG_PATH "/photo01.ppm"); + + std::cout << "nb color : " << val << std::endl; + + return 0; +} + diff --git a/milena/sandbox/green/demo/annoting/bic/Makefile.am b/milena/sandbox/green/demo/annoting/stddev_color/Makefile.am similarity index 100% copy from milena/sandbox/green/demo/annoting/bic/Makefile.am copy to milena/sandbox/green/demo/annoting/stddev_color/Makefile.am diff --git a/milena/sandbox/green/demo/annoting/stddev_color/stddev_color.cc b/milena/sandbox/green/demo/annoting/stddev_color/stddev_color.cc new file mode 100644 index 0000000..0782e9c --- /dev/null +++ b/milena/sandbox/green/demo/annoting/stddev_color/stddev_color.cc @@ -0,0 +1,124 @@ +// COMPUTING THE STDEV OF THE COLORS + +#include <iostream> +#include <sstream> + +#include <mln/img_path.hh> + +#include <mln/accu/max_site.hh> +#include <mln/accu/stat/histo1d.hh> + +#include <mln/core/macros.hh> +#include <mln/core/image/image1d.hh> +#include <mln/core/image/image2d.hh> +#include <mln/core/image/image3d.hh> + +#include <mln/debug/println.hh> + +#include <mln/data/compute.hh> +#include <mln/data/fill.hh> +#include <mln/data/transform.hh> + +#include <mln/fun/v2v/rgb8_to_int_u8.hh> + +#include <mln/io/ppm/load.hh> +#include <mln/io/pgm/save.hh> +#include <mln/io/plot/save_image_sh.hh> + +#include <mln/math/sqr.hh> + +#include <mln/opt/at.hh> + +#include <mln/value/rgb8.hh> +#include <mln/value/int_u.hh> + + +// FIXME REPARER L'ACCUMULATEUR MAX_SITE +// FIXME PENSER LA VARIANCE SUR UN HISTOGRAMME NORMALISE, VOIR LES RESULTATS + +float r(short p, unsigned histo_p, short x, unsigned histo_x) +{ + float result = mln::math::sqr(((float)histo_x / histo_p) * (x-p)); + + return result; +} + +unsigned stddev_color(const std::string& image) +{ + typedef mln::point1d t_point1d; + typedef mln::value::rgb8 t_rgb8; + typedef mln::value::int_u8 t_int_u8; + typedef mln::image2d<t_rgb8> t_image2d_rgb8; + typedef mln::image2d<t_int_u8> t_image2d_int_u8; + typedef mln::image1d<unsigned> t_histo1d; + typedef mln::fun::v2v::rgb8_to_int_u8 t_rgb8_to_int_u8; + typedef mln::accu::meta::stat::histo1d t_histo1d_fun; + typedef mln::accu::max_site<t_histo1d> t_max_site_fun; + + t_image2d_rgb8 input_rgb8; + t_image2d_int_u8 input_int_u8; + t_histo1d histo; + t_point1d max_site; + + mln::io::ppm::load(input_rgb8, image.c_str()); + input_int_u8 = mln::data::transform(input_rgb8, t_rgb8_to_int_u8()); + histo = mln::data::compute(t_histo1d_fun(), input_int_u8); + + mln::io::pgm::save(input_int_u8, "tmp.pgm"); + mln::io::plot::save_image_sh(histo, "histo.sh"); + mln::debug::println(histo); + + // Find the peak of the histogram + unsigned v_max = mln::opt::at(histo, 0); + short p_max = 0; + + mln_piter_(t_histo1d) p(histo.domain()); + + for_all(p) + { + if (v_max < histo(p)) + { + v_max = histo(p); + p_max = p.ind(); + } + } + + // Compute the specific stddev + + float stddev_low = 0.0; + float stddev_up = 0.0; + float stddev = 0.0; + + if (250 > p_max) + for (short i = p_max+1; i < p_max+6; ++i) + stddev_up += r(p_max, mln::opt::at(histo,p_max), + i, mln::opt::at(histo,i)); + + if (5 < p_max) + for (short i = p_max-1; i > p_max-6; --i) + stddev_low += r(p_max, mln::opt::at(histo,p_max), + i, mln::opt::at(histo,i)); + + stddev = (250 < p_max)? stddev_low : (5 > p_max)? stddev_up : + (stddev_low + stddev_up)/2; + + std::cout << "max_site : " << p_max << std::endl; + std::cout << "h(max_site) : " << v_max << std::endl; + std::cout << "stddev_up : " << stddev_up << std::endl; + std::cout << "stddev_low : " << stddev_low << std::endl; + std::cout << "stddev : " << stddev << std::endl; + + return 0; +} + + +int main() +{ +// unsigned val = stdev_color(ANNOTING_PHOTO_IMG_PATH "/photo01.ppm"); + unsigned val = stddev_color(ANNOTING_LOGO_IMG_PATH "/logo06.ppm"); + +// std::cout << "nb color : " << val << std::endl; + + return 0; +} + -- 1.5.6.5
participants (1)
-
green