
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> New exe source files dedicated to color images. * theo/exec/color_labeling_mean.cc: New. * theo/exec/color_internal_gradient.cc: New. * theo/color/filter_rgb_pixels.cc: Rename as... * theo/color/filter_meandist_rgb_pixels.cc: ...this. * folio/test/histo/classify_with_histo_rgb.cc (main): Use dilation to get rid of watershed line. Add 3rd arg to set output file and fix usage. * folio/mln/histo/classify_with_histo_rgb.hh: Remove blank line. folio/mln/histo/classify_with_histo_rgb.hh | 1 folio/test/histo/classify_with_histo_rgb.cc | 16 +-- theo/exec/color_internal_gradient.cc | 148 ++++++++++++++++++++++++++++ theo/exec/color_labeling_mean.cc | 49 +++++++++ 4 files changed, 206 insertions(+), 8 deletions(-) Index: theo/exec/color_labeling_mean.cc --- theo/exec/color_labeling_mean.cc (revision 0) +++ theo/exec/color_labeling_mean.cc (revision 0) @@ -0,0 +1,49 @@ +#include <mln/core/image/image2d.hh> + +#include <mln/estim/min_max.hh> +#include <mln/labeling/compute.hh> +#include <mln/accu/mean.hh> +#include <mln/level/transform.hh> + +#include <mln/value/label_8.hh> + +#include <mln/io/pgm/load.hh> +#include <mln/io/ppm/load.hh> +#include <mln/io/ppm/save.hh> + + + + + +int main(int argc, char* argv[]) +{ + using namespace mln; + using value::int_u8; + using value::label_8; + using value::rgb8; + + image2d<int_u8> lab; + io::pgm::load(lab, argv[1]); + + int_u8 min, nlabels; + estim::min_max(lab, min, nlabels); + + std::cout << min << ' ' << nlabels << std::endl; + + image2d<rgb8> ima; + io::ppm::load(ima, argv[2]); + + accu::mean<rgb8> m_; + typedef algebra::vec<3,float> V; + util::array<V> m = labeling::compute(m_, ima, lab, nlabels); + + util::array<rgb8> c(nlabels + 1); + for (unsigned l = 0; l <= nlabels; ++l) + { + c[l].red() = m[l][0]; + c[l].green() = m[l][1]; + c[l].blue() = m[l][2]; + } + + io::ppm::save(level::transform(lab, c), argv[3]); +} Index: theo/exec/color_internal_gradient.cc --- theo/exec/color_internal_gradient.cc (revision 0) +++ theo/exec/color_internal_gradient.cc (revision 0) @@ -0,0 +1,148 @@ +#include "filetype.hh" + +#include <mln/core/alias/neighb2d.hh> +#include <mln/morpho/elementary/gradient_internal.hh> +#include <mln/math/diff_abs.hh> + +#include <mln/accu/image/init.hh> +#include <mln/accu/image/take.hh> +#include <mln/accu/image/to_result.hh> + +#include <mln/accu/max.hh> + + + +namespace mln +{ + + value::int_u8 + dist(const value::rgb8& c1, + const value::rgb8& c2) + { + unsigned d = 0; + d += math::diff_abs(c1.red(), c2.red()); + d += math::diff_abs(c1.green(), c2.green()); + d += math::diff_abs(c1.blue(), c2.blue()); + if (d > 255) + d = 255; + return d; + } + + template <typename N> + image2d<value::int_u8> + color_gradient(const image2d<value::rgb8>& input, + const N& nbh) + { + using value::int_u8; + image2d<int_u8> output(input.domain()); + + mln_piter(box2d) p(input.domain()); + mln_niter(N) n(nbh, p); + for_all(p) + { + int_u8 d = 0u; + for_all(n) if (input.domain().has(n)) + { + int_u8 d_ = dist(input(p), input(n)); + if (d_ > d) + d = d_; + } + output(p) = d; + } + + return output; + } + + + + template <typename I> + image2d<value::int_u8> + get_red(const I& input) + { + typedef image2d<value::int_u8> J; + J output(input.domain()); + + mln_pixter(const I) p_in(input); + mln_pixter(J) p_out(output); + for_all_2(p_in, p_out) + p_out.val() = p_in.val().red(); + return output; + } + + template <typename I> + image2d<value::int_u8> + get_green(const I& input) + { + typedef image2d<value::int_u8> J; + J output(input.domain()); + + mln_pixter(const I) p_in(input); + mln_pixter(J) p_out(output); + for_all_2(p_in, p_out) + p_out.val() = p_in.val().green(); + return output; + } + + template <typename I> + image2d<value::int_u8> + get_blue(const I& input) + { + typedef image2d<value::int_u8> J; + J output(input.domain()); + + mln_pixter(const I) p_in(input); + mln_pixter(J) p_out(output); + for_all_2(p_in, p_out) + p_out.val() = p_in.val().blue(); + return output; + } + + +} // mln + + +void usage(char* argv[]) +{ + std::cerr << "usage: " << argv[0] << " input.ppm output.pgm" << std::endl + << " Color gradient." << std::endl; + std::abort(); +} + + + +int main(int argc, char* argv[]) +{ + using namespace mln; + using value::rgb8; + using value::int_u8; + + if (argc != 3) + usage(argv); + + trace::entering("main"); + + image2d<rgb8> ima; + io::ppm::load(ima, argv[1]); + + typedef accu::max<int_u8> A; + image2d<A> grad(ima.domain()); + + using morpho::elementary::gradient_internal; + + accu::image::init(grad); + + accu::image::take(grad, + gradient_internal(get_red(ima), + c4())); + accu::image::take(grad, + gradient_internal(get_green(ima), + c4())); + accu::image::take(grad, + gradient_internal(get_blue(ima), + c4())); + + io::pgm::save(accu::image::to_result(grad), + argv[2]); + + trace::exiting("main"); +} Property changes on: theo/color/filter_meandist_rgb_pixels.cc ___________________________________________________________________ Added: svn:mergeinfo Index: folio/test/histo/classify_with_histo_rgb.cc --- folio/test/histo/classify_with_histo_rgb.cc (revision 3676) +++ folio/test/histo/classify_with_histo_rgb.cc (working copy) @@ -15,9 +15,11 @@ #include <mln/arith/revert.hh> #include <mln/core/alias/neighb3d.hh> -#include <mln/morpho/closing/volume.hh> #include <mln/value/label_8.hh> + +#include <mln/morpho/closing/volume.hh> #include <mln/morpho/watershed/flooding.hh> +#include <mln/morpho/elementary/dilation.hh> #include "../../mln/histo/compute_histo_rgb.hh" #include "../../mln/histo/classify_with_histo_rgb.hh" @@ -42,10 +44,10 @@ using namespace mln; // check arguments - if (argc < 3) + if (argc != 4) { std::cerr << "Usage:" << std::endl - << " ./a.out ../../../../lena.ppm 51" << std::endl + << " ./a.out ../../../../lena.ppm 51 out.pgm" << std::endl << std::endl << "BTW, the number is the closure's lambda." << std::endl; exit(1); @@ -79,11 +81,11 @@ image3d<value::label_8> labels = morpho::watershed::flooding(closed, c6(), nbasin); std::cout << "found " << nbasin << " labels" << std::endl; + labels = morpho::elementary::dilation(labels, c18()); + std::cout << " => computing output labelized image..." << std::endl; image2d<value::label_8> out = histo::classify_with_histo_rgb(ima, labels); - std::cout << " => saving out.ppm..." << std::endl; - io::pgm::save(out, "out.ppm"); - - return 0; + std::cout << " => saving " << argv[3] << "..." << std::endl; + io::pgm::save(out, argv[3]); } Index: folio/mln/histo/classify_with_histo_rgb.hh --- folio/mln/histo/classify_with_histo_rgb.hh (revision 3676) +++ folio/mln/histo/classify_with_histo_rgb.hh (working copy) @@ -26,7 +26,6 @@ { // get 3d point in regions image. point3d p3 = point3d(ref(p).red(), ref(p).green(), ref(p).blue()); - out(p) = regions(p3); // copy the label in out's pixel. }