last-svn-commit-36-g431e355 Work on Millet value descriptor.

* green/exp/annotating/value: New directory. * green/exp/annotating/value/Makefile.am: New Makefile. * green/exp/annotating/value/value.cc: New source file. * green/exp/annotating/value/text-color.txt: New image class. * green/exp/annotating/value/text-img.txt: New image class. * green/exp/annotating/value/text-only.txt: New image class. --- .../annotating/{achromastism => value}/Makefile.am | 0 .../{achromastism => value}/text-color.txt | 0 .../{achromastism => value}/text-img.txt | 0 .../{achromastism => value}/text-only.txt | 0 .../exp/annotating/{hue/hue.cc => value/value.cc} | 143 ++++++++++++-------- 5 files changed, 84 insertions(+), 59 deletions(-) copy milena/sandbox/green/exp/annotating/{achromastism => value}/Makefile.am (100%) copy milena/sandbox/green/exp/annotating/{achromastism => value}/text-color.txt (100%) copy milena/sandbox/green/exp/annotating/{achromastism => value}/text-img.txt (100%) copy milena/sandbox/green/exp/annotating/{achromastism => value}/text-only.txt (100%) copy milena/sandbox/green/exp/annotating/{hue/hue.cc => value/value.cc} (68%) diff --git a/milena/sandbox/green/exp/annotating/achromastism/Makefile.am b/milena/sandbox/green/exp/annotating/value/Makefile.am similarity index 100% copy from milena/sandbox/green/exp/annotating/achromastism/Makefile.am copy to milena/sandbox/green/exp/annotating/value/Makefile.am diff --git a/milena/sandbox/green/exp/annotating/achromastism/text-color.txt b/milena/sandbox/green/exp/annotating/value/text-color.txt similarity index 100% copy from milena/sandbox/green/exp/annotating/achromastism/text-color.txt copy to milena/sandbox/green/exp/annotating/value/text-color.txt diff --git a/milena/sandbox/green/exp/annotating/achromastism/text-img.txt b/milena/sandbox/green/exp/annotating/value/text-img.txt similarity index 100% copy from milena/sandbox/green/exp/annotating/achromastism/text-img.txt copy to milena/sandbox/green/exp/annotating/value/text-img.txt diff --git a/milena/sandbox/green/exp/annotating/achromastism/text-only.txt b/milena/sandbox/green/exp/annotating/value/text-only.txt similarity index 100% copy from milena/sandbox/green/exp/annotating/achromastism/text-only.txt copy to milena/sandbox/green/exp/annotating/value/text-only.txt diff --git a/milena/sandbox/green/exp/annotating/hue/hue.cc b/milena/sandbox/green/exp/annotating/value/value.cc similarity index 68% copy from milena/sandbox/green/exp/annotating/hue/hue.cc copy to milena/sandbox/green/exp/annotating/value/value.cc index 883e1c6..9209d47 100644 --- a/milena/sandbox/green/exp/annotating/hue/hue.cc +++ b/milena/sandbox/green/exp/annotating/value/value.cc @@ -1,4 +1,4 @@ -// SATURATION TEST CF MILLET 2008 +// VALUE TEST CF MILLET 2008 #include <iostream> #include <sstream> @@ -26,7 +26,7 @@ #include <mln/geom/nsites.hh> -#include <mln/fun/v2v/rgb_to_hue_map.hh> +#include <mln/fun/v2v/rgb_to_value_map.hh> #include <mln/io/ppm/load.hh> #include <mln/io/pgm/save.hh> @@ -97,52 +97,25 @@ mln::value::rgb8 label_hue(const mln::value::int_u8 hue) { mln::value::rgb8 result; - - if (10 > hue) + if (14 > hue) result = mln::literal::red; - else if (32 > hue) + else if (29 > hue) result = mln::literal::orange; - else if (53 > hue) + else if (45 > hue) result = mln::literal::yellow; - else if (74 > hue) - result = mln::literal::green; // chartreuse - else if (96 > hue) + else if (113 > hue) result = mln::literal::green; - else if (116 > hue) - result = mln::literal::green;// turquoise, aigue-marine - else if (138 > hue) - result = mln::literal::green; // cyan - else if (159 > hue) - result = mln::literal::blue; // azur - else if (181 > hue) + else if (149 > hue) + result = mln::literal::cyan; + else if (205 > hue) result = mln::literal::blue; - else if (202 > hue) + else if (235 > hue) result = mln::literal::violet; - else if (223 > hue) + else if (242 > hue) result = mln::literal::pink; - else // if (244 > hue) + else result = mln::literal::red; - -// if (14 > hue) -// result = mln::literal::red; -// else if (29 > hue) -// result = mln::literal::orange; -// else if (45 > hue) -// result = mln::literal::yellow; -// else if (113 > hue) -// result = mln::literal::green; -// else if (149 > hue) -// result = mln::literal::cyan; -// else if (205 > hue) -// result = mln::literal::blue; -// else if (235 > hue) -// result = mln::literal::violet; -// else if (242 > hue) -// result = mln::literal::pink; -// else -// result = mln::literal::red; - return result; } @@ -212,14 +185,69 @@ unsigned mean_histo(const mln::Image<I>& histo_) return mean; } +// calcul de contribution +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; +} + +template <typename I> +float stddev3(const mln::Image<I>& histo_, unsigned peak) +{ + const I& histo = exact(histo_); + + mln_precondition(histo.is_valid()); + + // Compute stddev + + float stddev = 0.0; + + mln_piter(I) p(histo.domain()); + + for_all(p) + { + stddev += r((short)peak, mln::opt::at(histo,peak), p.ind(), histo(p)); + } + + return stddev; +} + +template <typename I> +float stddev2(const mln::Image<I>& histo_, unsigned peak, unsigned limit) +{ + const I& histo = exact(histo_); + + mln_precondition(histo.is_valid()); + + float stddev_low = 0.0; + float stddev_up = 0.0; + float ret = 0.0; + + // A transformer avec des iterators + + if (250 > peak) + stddev_up = stddev3(histo |mln::box1d(mln::point1d(peak+1), + mln::point1d(peak+limit)), peak); + + if (5 < peak) + stddev_low = stddev3(histo |mln::box1d(mln::point1d(peak-limit), + mln::point1d(peak-1)), peak); + + ret = (250 < peak)? stddev_low : (5 > peak)? stddev_up : + (stddev_low + stddev_up)/2; + + return ret; +} -float hue_test(const std::string input, - const std::string output, - const std::string tmp, - const unsigned threshold) +float value_test(const std::string input, + const std::string output, + const std::string tmp, + const unsigned threshold) { - typedef mln::fun::v2v::rgb_to_hue_map<8> t_rgb_to_hue_map; + typedef mln::fun::v2v::rgb_to_value_map<8> t_rgb_to_value_map; mln::image2d<mln::value::rgb8> input_rgb8; mln::image2d<mln::value::int_u8> map; @@ -228,23 +256,20 @@ float hue_test(const std::string input, unsigned cnt2; float prop; unsigned peak; - mln::value::rgb8 color; mln::io::ppm::load(input_rgb8, input.c_str()); - map = mln::data::transform(input_rgb8, t_rgb_to_hue_map()); + map = mln::data::transform(input_rgb8, t_rgb_to_value_map()); histo = mln::data::compute(mln::accu::meta::stat::histo1d(), map); - peak = mean_histo(histo); //peak_histo(histo); - color = label_hue(peak); - cnt1 = count_histo(histo | mln::box1d(mln::point1d(peak-threshold), - mln::point1d(peak+threshold))); - cnt2 = mln::geom::nsites(input_rgb8); - prop = ((100.0 * cnt1) / cnt2); + peak = peak_histo(histo); // mean_histo(histo); + prop = stddev2(histo, peak, limit); +// cnt1 = count_histo(histo | mln::box1d(mln::point1d(peak-threshold), +// mln::point1d(peak+threshold))); +// cnt2 = mln::geom::nsites(input_rgb8); +// prop = ((100.0 * cnt1) / cnt2); mln::io::plot::save_image_sh(histo, output.c_str()); mln::io::pgm::save(map, tmp.c_str()); - std::cout << "peak = " << peak << std::endl; - std::cout << "color = " << color << std::endl; return prop; } @@ -271,15 +296,15 @@ int main() for (t_iter_path dir_iter(full_path[i]); end_iter != dir_iter; ++dir_iter) { // concatenation de chaine - t_path directory(ANNOTATING_HUE_RET_PATH); + t_path directory(ANNOTATING_VALUE_RET_PATH); t_path leaf = dir_iter->path().leaf(); t_path output = change_extension(directory / leaf, ".sh"); t_path tmp = change_extension(directory / leaf, ".pgm"); - prop = hue_test(dir_iter->path().string(), - output.string(), - tmp.string(), - 20); + prop = value_test(dir_iter->path().string(), + output.string(), + tmp.string(), + 15); std::cout << output << " : " << prop << std::endl; std::cerr << output << " : " << prop << std::endl; -- 1.5.6.5
participants (1)
-
Yann Jacquelet