r4172: Add mln/ and tests/ directory for testing before integration into Milena

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-06-19 Fabien Freling <fabien.freling@lrde.epita.fr> Add mln/ and tests/ directory for testing before integration into Milena. * fabien/bin/pnms2dump.cc: Small update. * fabien/igr/Makefile: Add targets. * fabien/igr/check_edges.sh: Small update. * fabien/igr/clo_vol.cc: Small update. * fabien/igr/crop.cc: Small update. * fabien/igr/dist_edges.cc: Small update. * fabien/igr/filter.cc: Small update. * fabien/igr/grad.cc: Small update. * fabien/igr/maj.cc: New filter for US images. * fabien/igr/point_filtering/main.cc: Small update (demo for IGR). * fabien/igr/wst.cc: Small update. * fabien/igr/wst_edges.cc: Small update. * fabien/mln/debug/int2rgb.hh: Convert int value into rgb value (useful for visualization of int_u12 values). * fabien/mln/display/display_region.hh: New visualization routine for watershed regions. * fabien/mln/world/inter_pixel/display_region.hh: Fix values filling. * fabien/tests/display/Makefile: New target. * fabien/tests/display/display_region.cc: New test for display_region() routine. * fabien/tests/world/inter_pixel/Makefile: New target. * fabien/tests/world/inter_pixel/display_region.cc: New test for display_region() routine in inter_pixel world. --- bin/pnms2dump.cc | 1 igr/Makefile | 3 + igr/check_edges.sh | 35 ++++++----- igr/clo_vol.cc | 13 ++-- igr/crop.cc | 10 ++- igr/dist_edges.cc | 4 + igr/filter.cc | 82 --------------------------- igr/grad.cc | 21 +++---- igr/maj.cc | 60 ++++++++++++++++++++ igr/point_filtering/main.cc | 12 ++-- igr/wst.cc | 19 +++--- igr/wst_edges.cc | 8 -- mln/debug/int2rgb.hh | 36 ++++++++++++ mln/display/display_region.hh | 90 ++++++++++++++++++++++++++++++ mln/world/inter_pixel/display_region.hh | 33 +++++++++-- tests/display/Makefile | 7 ++ tests/display/display_region.cc | 64 +++++++++++++++++++++ tests/world/inter_pixel/Makefile | 7 ++ tests/world/inter_pixel/display_region.cc | 59 +++++++++++++++++++ 19 files changed, 420 insertions(+), 144 deletions(-) Index: trunk/milena/sandbox/fabien/igr/clo_vol.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/clo_vol.cc (revision 4171) +++ trunk/milena/sandbox/fabien/igr/clo_vol.cc (revision 4172) @@ -35,8 +35,9 @@ using namespace mln; using value::int_u8; using value::int_u12; + typedef int_u8 input_type; - if (argc != 4) + if (argc != 5) { std::cout << "Usage: " << argv[0] << " input.dump dim lambda output.dump" << std::endl; @@ -53,20 +54,20 @@ if (dim == 2) { - image2d<int_u12> input; + image2d<input_type> input; io::dump::load(input, argv[1]); - image2d<int_u12> clo = morpho::closing::volume(input, c4(), closure_lambda); - io::dump::save(clo, "clo_vol.dump"); + image2d<input_type> clo = morpho::closing::volume(input, c4(), closure_lambda); + io::dump::save(clo, argv[4]); } else { - typedef image3d<int_u12> I; + typedef image3d<input_type> I; I input; io::dump::load(input, argv[1]); I clo = morpho::closing::volume(input, c6(), closure_lambda); - io::dump::save(clo, "clo_vol.dump"); + io::dump::save(clo, argv[4]); } return 0; Index: trunk/milena/sandbox/fabien/igr/crop.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/crop.cc (revision 4171) +++ trunk/milena/sandbox/fabien/igr/crop.cc (revision 4172) @@ -8,8 +8,9 @@ #include <mln/core/alias/window3d.hh> #include <mln/io/dicom/load.hh> -#include <mln/io/dump/save.hh> +#include <mln/io/dump/all.hh> +#include <mln/value/int_u8.hh> #include <mln/value/int_u12.hh> @@ -33,12 +34,15 @@ int main(int argc, char* argv[]) { using namespace mln; + using value::int_u8; using value::int_u12; + typedef int_u12 input_type; + if (argc != 9) usage(argv); - image3d<int_u12> vol; + image3d<input_type> vol; io::dicom::load(vol, argv[1]); std::cout << "Input bbox: " << vol.bbox() << std::endl; @@ -55,7 +59,7 @@ box3d b = make::box3d(s_min, r_min, c_min, s_max, r_max, c_max); std::cout << "Output bbox: " << b << std::endl; - image3d<int_u12> ima(b); + image3d<input_type> ima(b); data::fill(ima, vol); io::dump::save(ima, argv[8]); } Index: trunk/milena/sandbox/fabien/igr/check_edges.sh =================================================================== --- trunk/milena/sandbox/fabien/igr/check_edges.sh (revision 4171) +++ trunk/milena/sandbox/fabien/igr/check_edges.sh (revision 4172) @@ -3,17 +3,19 @@ process () { - ./dist_edges $1 -1 $2 dist${2}.dump + echo "Distance ${2}" + + ./dist_edges $1 -1 $2 ${4}_dist${2}.dump if [ $? -gt 0 ]; then echo "error: dist_edges failed" exit fi - nbasins=`./wst_edges dist${2}.dump $3` + nbasins=`./wst_edges ${4}_dist${2}.dump $3` if [ $? -gt 0 ]; then echo "error: wst_edges failed" exit fi - ./mean_median_label dist${2}.dump watershed.dump $nbasins + ./mean_median_label ${4}_dist${2}.dump watershed.dump $nbasins if [ $? -gt 0 ]; then echo "error: mean_median_label failed" echo "nbasins: $nbasins" @@ -26,13 +28,13 @@ #convert dist_mean.pgm dist_mean${2}.png #convert dev.pgm dev${2}.png - mv dist.pgm dist${2}.pgm - mv watershed.ppm watershed${2}.pgm - mv means.pgm means${2}.pgm - mv dist_mean.pgm dist_mean${2}.pgm - mv dev.pgm dev${2}.pgm + mv dist.pgm ${4}_dist${2}.pgm + mv watershed.ppm ${4}_watershed${2}.pgm + mv means.pgm ${4}_means${2}.pgm + mv dist_mean.pgm ${4}_dist_mean${2}.pgm + mv dev.pgm ${4}_dev${2}.pgm - cp watershed.dump watershed${2}.dump + cp watershed.dump ${4}_watershed${2}.dump # Cleanup. #rm *.pgm *.ppm @@ -40,11 +42,14 @@ batch_process () { - process $1 1 $2 - process $1 2 $2 - process $1 3 $2 - process $1 4 $2 - process $1 5 $2 + process $1 1 $2 $3 + process $1 2 $2 $3 + process $1 3 $2 $3 + process $1 4 $2 $3 + process $1 5 $2 $3 } -batch_process $1 $2 +# $1 = input.dump +# $2 = closing lambda +# $3 = name +batch_process $1 500 $3 Index: trunk/milena/sandbox/fabien/igr/wst.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/wst.cc (revision 4171) +++ trunk/milena/sandbox/fabien/igr/wst.cc (revision 4172) @@ -11,8 +11,8 @@ #include <mln/value/int_u8.hh> #include <mln/value/int_u12.hh> +#include <mln/value/label_8.hh> #include <mln/value/label_16.hh> -#include <mln/value/label_32.hh> #include <mln/morpho/watershed/flooding.hh> @@ -30,13 +30,14 @@ using namespace mln; using value::int_u8; using value::int_u12; + using value::label_8; using value::label_16; - using value::label_32; - typedef label_16 L; + typedef label_8 L; + typedef int_u8 V; - if (argc != 3) + if (argc != 4) { - std::cout << "Usage: " << argv[0] << " <ima.dcm> <dimensions>" + std::cout << "Usage: " << argv[0] << " input.dump dim output.dump" << std::endl; return 1; } @@ -52,17 +53,17 @@ if (dim == 2) { - image2d<int_u12> input; + image2d<V> input; io::dump::load(input, argv[1]); image2d<L> wshed = morpho::watershed::flooding(input, c4(), nbasins); - io::dump::save(wshed, "wst.dump"); + io::dump::save(wshed, argv[3]); } else { - image3d<int_u12> input; + image3d<V> input; io::dump::load(input, argv[1]); image3d<L> wshed = morpho::watershed::flooding(input, c6(), nbasins); - io::dump::save(wshed, "wst.dump"); + io::dump::save(wshed, argv[3]); } std::cout << nbasins << std::endl; Index: trunk/milena/sandbox/fabien/igr/wst_edges.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/wst_edges.cc (revision 4171) +++ trunk/milena/sandbox/fabien/igr/wst_edges.cc (revision 4172) @@ -40,7 +40,7 @@ #include <mln/math/diff_abs.hh> #include <mln/morpho/dilation.hh> #include <mln/morpho/erosion.hh> -#include <mln/morpho/closing/sum.hh> +#include <mln/morpho/closing/volume.hh> #include <mln/morpho/watershed/flooding.hh> #include <mln/pw/all.hh> #include <mln/util/array.hh> @@ -110,7 +110,6 @@ unsigned lambda = atoi(argv[2]); - // Initialization. typedef int_u12 input_type; image2d<input_type> input; @@ -118,7 +117,7 @@ // Closing. - mln_VAR(d_clo, morpho::closing::sum(input | world::inter_pixel::is_separator(), world::inter_pixel::e2e(), lambda)); + mln_VAR(d_clo, morpho::closing::volume(input | world::inter_pixel::is_separator(), world::inter_pixel::e2e(), lambda)); io_save_edges_int_u12(d_clo, 0, "d_clo.pgm"); @@ -142,8 +141,5 @@ io::dump::save(w_all, "watershed.dump"); io::ppm::save(debug::int2rgb(w_all), "watershed.ppm"); - io::ppm::save(world::inter_pixel::display_region(data::stretch(int_u8(), input), w_all, literal::red), "regions.ppm"); - - return 0; } Index: trunk/milena/sandbox/fabien/igr/Makefile =================================================================== --- trunk/milena/sandbox/fabien/igr/Makefile (revision 4171) +++ trunk/milena/sandbox/fabien/igr/Makefile (revision 4172) @@ -24,6 +24,9 @@ wst: wst.cc ${CXX} -I../../../ ${CXXFLAGS} $^ -o wst +maj: maj.cc + ${CXX} -I../../../ ${CXXFLAGS} $^ -o maj + graph: graph.cc ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o graph Index: trunk/milena/sandbox/fabien/igr/maj.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/maj.cc (revision 0) +++ trunk/milena/sandbox/fabien/igr/maj.cc (revision 4172) @@ -0,0 +1,60 @@ +#include <iostream> +#include <mln/core/image/image2d.hh> +#include <mln/core/image/image3d.hh> + +#include <mln/core/alias/neighb2d.hh> +#include <mln/core/alias/window2d.hh> +#include <mln/core/alias/neighb3d.hh> +#include <mln/core/alias/window3d.hh> + +#include <mln/io/dump/all.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/int_u12.hh> +#include <mln/value/label_8.hh> +#include <mln/value/label_16.hh> + +#include <mln/morpho/watershed/flooding.hh> + +#include <mln/accu/transform.hh> +#include <mln/accu/maj_h.hh> + +#include <mln/win/sphere3d.hh> + + + +/////////////////// +// // +// Main Function // +// // +/////////////////// + + +int main(int argc, char *argv[]) +{ + using namespace mln; + using value::int_u8; + using value::int_u12; + using value::label_8; + using value::label_16; + typedef label_8 L; + typedef int_u8 V; + + if (argc != 3) + { + std::cout << "Usage: " << argv[0] << " wst.dump output.dump" + << std::endl; + return 1; + } + + L nbasins; + + image3d<L> wst; + io::dump::load(wst, argv[1]); + accu::maj_h<L> maj; + image3d<L> output = accu::transform(wst, maj, win::sphere3d(7)); + + io::dump::save(output, argv[2]); + + return 0; +} Index: trunk/milena/sandbox/fabien/igr/point_filtering/main.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/point_filtering/main.cc (revision 4171) +++ trunk/milena/sandbox/fabien/igr/point_filtering/main.cc (revision 4172) @@ -41,8 +41,8 @@ win::segment1d seg15(15); win::segment1d seg21(21); - image1d<float> opening_ima = morpho::opening::structural(ima, seg21); - image1d<float> closing_ima = morpho::closing::structural(ima, seg21); + image1d<float> opening_ima = morpho::opening::structural(ima, seg15); + image1d<float> closing_ima = morpho::closing::structural(ima, seg15); image1d<accu::stat::mean<float> > result; @@ -55,8 +55,8 @@ io::plot::save(ima_morpho, "morpho.plot"); // Morpho (again). - opening_ima = morpho::opening::structural(ima_morpho, seg13); - closing_ima = morpho::closing::structural(ima_morpho, seg13); + opening_ima = morpho::opening::structural(ima_morpho, seg11); + closing_ima = morpho::closing::structural(ima_morpho, seg11); initialize(result, ima_morpho); @@ -67,8 +67,8 @@ io::plot::save(ima_morpho2, "morpho2.plot"); // Morpho (the return of the revenge). - opening_ima = morpho::opening::structural(ima_morpho2, seg5); - closing_ima = morpho::closing::structural(ima_morpho2, seg5); + opening_ima = morpho::opening::structural(ima_morpho2, seg7); + closing_ima = morpho::closing::structural(ima_morpho2, seg7); initialize(result, ima_morpho2); Index: trunk/milena/sandbox/fabien/igr/dist_edges.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/dist_edges.cc (revision 4171) +++ trunk/milena/sandbox/fabien/igr/dist_edges.cc (revision 4172) @@ -203,8 +203,10 @@ res += (double) math::diff_abs(v1[i], v2[i]); res = res / v1.nelements(); + if (res > 0.5) + return 4095u; //res = 1 - res; - res = (res * 4095) + 0.49; + res = (1.999999 * res * 4095) + 0.49; return (int) res; } Index: trunk/milena/sandbox/fabien/igr/grad.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/grad.cc (revision 4171) +++ trunk/milena/sandbox/fabien/igr/grad.cc (revision 4172) @@ -10,7 +10,7 @@ //#include <mln/io/dicom/load.hh> #include <mln/io/dump/all.hh> -//#include <mln/value/int_u8.hh> +#include <mln/value/int_u8.hh> #include <mln/value/int_u12.hh> #include <mln/morpho/elementary/gradient.hh> @@ -27,12 +27,13 @@ int main(int argc, char *argv[]) { using namespace mln; - //using value::int_u8; + using value::int_u8; using value::int_u12; + typedef int_u8 input_type; - if (argc != 3) + if (argc != 4) { - std::cout << "Usage: " << argv[0] << " <ima.dcm> <dimensions>" + std::cout << "Usage: " << argv[0] << " ima.dcm dim output.dump" << std::endl; return 1; } @@ -46,17 +47,17 @@ if (dim == 2) { - image2d<int_u12> dcm2; + image2d<input_type> dcm2; io::dump::load(dcm2, argv[1]); - image2d<int_u12> grad2 = morpho::elementary::gradient(dcm2, c4()); - io::dump::save(grad2, "grad.dump"); + image2d<input_type> grad2 = morpho::elementary::gradient(dcm2, c4()); + io::dump::save(grad2, argv[3]); } else { - image3d<int_u12> dcm3; + image3d<input_type> dcm3; io::dump::load(dcm3, argv[1]); - image3d<int_u12> grad3 = morpho::elementary::gradient(dcm3, c6()); - io::dump::save(grad3, "grad.dump"); + image3d<input_type> grad3 = morpho::elementary::gradient(dcm3, c6()); + io::dump::save(grad3, argv[3]); } return 0; Index: trunk/milena/sandbox/fabien/igr/filter.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/filter.cc (revision 4171) +++ trunk/milena/sandbox/fabien/igr/filter.cc (revision 4172) @@ -93,88 +93,6 @@ -// Distance function. -//------------------- - -struct dist_t : Function_vv2v<dist_t> -{ - typedef int_u12 result; - - template <typename V> - int_u12 operator()(util::array<V> v1, util::array<V> v2) const - { - float res = 0.f; - - for (unsigned i = 0; i < v1.nelements(); ++i) - res += std::min(v1[i], v2[i]); - - image1d<V> tmp_ima; - image1d<V> tmp_ima2; - accu::math::sum<V> accu_sum; - - convert::from_to(v1, tmp_ima); - float sum_v1 = data::compute(accu_sum, tmp_ima); - - convert::from_to(v2, tmp_ima2); - float sum_v2 = data::compute(accu_sum, tmp_ima2); - - if (sum_v1 == 0 && sum_v2 == 0) - return 1; - - res /= std::max(sum_v1, sum_v2); - res = 1 - res; - res = res * 4095; - if (res > 4095) - return 4095; - - return (int) res; - } -} dist; - - -struct dist_morpho_t : Function_vv2v<dist_morpho_t> -{ - typedef int_u12 result; - - template <typename V> - int_u12 operator()(util::array<V> v1, util::array<V> v2) const - { - float res = 0.f; - - accu::math::sum<V> accu_sum; - - image1d<V> tmp_ima; - convert::from_to(v1, tmp_ima); - image1d<float> morpho_ima = mean_image(tmp_ima, 15); - morpho_ima = mean_image(morpho_ima, 11); - morpho_ima = mean_image(morpho_ima, 7); - float sum_v1 = data::compute(accu_sum, morpho_ima); - - image1d<V> tmp_ima2; - convert::from_to(v2, tmp_ima2); - image1d<float> morpho_ima2 = mean_image(tmp_ima2, 15); - morpho_ima2 = mean_image(tmp_ima2, 11); - morpho_ima2 = mean_image(tmp_ima2, 7); - float sum_v2 = data::compute(accu_sum, morpho_ima2); - - mln_piter(image1d<float>) p(morpho_ima.domain()); - for_all(p) - res += std::min(morpho_ima(p), morpho_ima2(p)); - - if (sum_v1 == 0 && sum_v2 == 0) - return 1; - - res /= std::max(sum_v1, sum_v2); - res = 1 - res; - res = res * 4095; - if (res > 4095) - return 4095; - - return res; - } -} dist_morpho; - - Index: trunk/milena/sandbox/fabien/tests/display/display_region.cc =================================================================== --- trunk/milena/sandbox/fabien/tests/display/display_region.cc (revision 0) +++ trunk/milena/sandbox/fabien/tests/display/display_region.cc (revision 4172) @@ -0,0 +1,64 @@ +#include <mln/core/image/image2d.hh> +#include <mln/core/alias/neighb2d.hh> +#include <mln/core/image/image3d.hh> +#include <mln/core/image/dmorph/image_if.hh> +#include <mln/core/image/dmorph/slice_image.hh> +#include <mln/core/routine/duplicate.hh> + +#include <mln/io/dump/all.hh> +#include <mln/io/ppm/save.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/int_u12.hh> +#include <mln/value/label_8.hh> +#include <mln/value/label_16.hh> +#include <mln/value/rgb8.hh> + +#include <mln/convert/from_to.hh> +#include <mln/data/fill.hh> +#include <mln/data/paste.hh> +#include <mln/data/stretch.hh> +#include <mln/pw/all.hh> +#include <mln/literal/colors.hh> + + +using namespace mln; +using value::int_u8; +using value::int_u12; +using value::label_8; +using value::label_16; +using value::rgb8; + + + +int usage(const char* bin) +{ + std::cout << "Usage: " << bin << " input.dump wst.dump output.dump" << std::endl; + return 1; +} + +int main(int argc, char* argv[]) +{ + if (argc != 4) + return usage(argv[0]); + + + // Initialization. + typedef int_u8 V; + typedef label_8 L; + image3d<V> input; + io::dump::load(input, argv[1]); + image3d<L> wst; + io::dump::load(wst, argv[2]); + image3d<rgb8> output; + initialize(output, input); + + mln_piter_(image3d<V>) p(input.domain()); + for_all(p) + convert::from_to(input(p), output(p)); + data::fill((output | pw::value(wst) == pw::cst(0)).rw(), literal::red); + + io::dump::save(output, argv[3]); + + return 0; +} Index: trunk/milena/sandbox/fabien/tests/display/Makefile =================================================================== --- trunk/milena/sandbox/fabien/tests/display/Makefile (revision 0) +++ trunk/milena/sandbox/fabien/tests/display/Makefile (revision 4172) @@ -0,0 +1,7 @@ +include ../../igr/Makefile.rules + +display_region: display_region.cc + ${CXX} -I../../ -I../../../../ ${CXXFLAGS} display_region.cc -o display_region + +clean: + rm -rf *.dump *.p?m *.plot *.log *.csv *.dSYM Index: trunk/milena/sandbox/fabien/tests/world/inter_pixel/display_region.cc =================================================================== --- trunk/milena/sandbox/fabien/tests/world/inter_pixel/display_region.cc (revision 0) +++ trunk/milena/sandbox/fabien/tests/world/inter_pixel/display_region.cc (revision 4172) @@ -0,0 +1,59 @@ +#include <mln/core/image/image2d.hh> +#include <mln/core/alias/neighb2d.hh> +#include <mln/core/image/image3d.hh> +#include <mln/core/image/dmorph/slice_image.hh> +#include <mln/core/routine/duplicate.hh> + +#include <mln/io/dump/all.hh> +#include <mln/io/ppm/save.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/int_u12.hh> +#include <mln/value/label_8.hh> +#include <mln/value/label_16.hh> +#include <mln/value/rgb8.hh> + +#include <mln/data/stretch.hh> +#include <mln/literal/colors.hh> + +#include <mln/world/inter_pixel/display_region.hh> + + +using namespace mln; +using value::int_u8; +using value::int_u12; +using value::label_8; +using value::label_16; +using value::rgb8; + + + + + +int usage(const char* bin) +{ + std::cout << "Usage: " << bin << " input.dump wst.dump" << std::endl; + return 1; +} + +int main(int argc, char* argv[]) +{ + if (argc != 3) + return usage(argv[0]); + + + // Initialization. + typedef int_u12 V; + typedef label_16 L; + image3d<V> input; + io::dump::load(input, argv[1]); + image2d<L> wst; + io::dump::load(wst, argv[2]); + + image2d<V> source = duplicate(slice(input, 10)); + + io::ppm::save(world::inter_pixel::display_region(data::stretch(int_u8(), source), wst, literal::red), "regions.ppm"); + + + return 0; +} Index: trunk/milena/sandbox/fabien/tests/world/inter_pixel/Makefile =================================================================== --- trunk/milena/sandbox/fabien/tests/world/inter_pixel/Makefile (revision 0) +++ trunk/milena/sandbox/fabien/tests/world/inter_pixel/Makefile (revision 4172) @@ -0,0 +1,7 @@ +include ../../../igr/Makefile.rules + +display_region: display_region.cc + ${CXX} -I../../../ -I../../../../../ ${CXXFLAGS} display_region.cc -o display_region + +clean: + rm -rf *.dump *.p?m *.plot *.log *.csv *.dSYM Index: trunk/milena/sandbox/fabien/mln/display/display_region.hh =================================================================== --- trunk/milena/sandbox/fabien/mln/display/display_region.hh (revision 0) +++ trunk/milena/sandbox/fabien/mln/display/display_region.hh (revision 4172) @@ -0,0 +1,90 @@ +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef MLN_DISPLAY_DISPLAY_REGION_HH +# define MLN_DISPLAY_DISPLAY_REGION_HH + +/// \file +/// +/// FIXME + +#include <mln/core/concept/image.hh> +#include <mln/core/image/dmorph/image_if.hh> + +#include <mln/value/rgb8.hh> + +#include <mln/convert/from_to.hh> +#include <mln/data/fill.hh> +#include <mln/data/paste.hh> +#include <mln/pw/all.hh> + + +namespace mln +{ + + namespace display + { + + /// \brief FIXME + /// + template<typename I, typename L> + inline + mln_ch_value(I, value::rgb8) + display_region(const Image<I>& ima, const Image<L>& wst, const value::rgb8 color); + + +#ifndef MLN_INCLUDE_ONLY + + template<typename I, typename L> + inline + mln_ch_value(I, value::rgb8) + display_region(const Image<I>& ima_, const Image<L>& wst_, const value::rgb8 color) + { + trace::entering("display::display_region"); + // TODO: We should check that wst.bbox() == input.bbox() + + const I& ima = exact(ima_); + const L& wst = exact(wst_); + + mln_ch_value(I, value::rgb8) output; + initialize(output, ima); + + mln_piter(I) p(ima.domain()); + for_all(p) + convert::from_to(ima(p), output(p)); + data::fill((output | pw::value(wst) == pw::cst(0)).rw(), color); + + trace::exiting("display::display_region"); + return output; + } + +# endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace mln::display + +} // end of namespace mln + +#endif // ! MLN_DISPLAY_DISPLAY_REGION_HH Index: trunk/milena/sandbox/fabien/mln/debug/int2rgb.hh =================================================================== --- trunk/milena/sandbox/fabien/mln/debug/int2rgb.hh (revision 0) +++ trunk/milena/sandbox/fabien/mln/debug/int2rgb.hh (revision 4172) @@ -0,0 +1,36 @@ +#include <mln/core/image/image2d.hh> +#include <mln/value/rgb8.hh> + + +namespace mln +{ + + namespace debug + { + + using value::rgb8; + + template <typename V> + image2d<rgb8> + int2rgb(const image2d<V>& input) + { + image2d<rgb8> output; + initialize(output, input); + + mln_piter(image2d<V>) p(input.domain()); + for_all(p) + { + unsigned value = input(p); + output(p).blue() = value % 256; + value /= 256; + output(p).green() = value % 256; + value /= 256; + output(p).red() = value % 256; + } + + return output; + } + +} // end of namespace mln::debug + +} // end of namespace mln Index: trunk/milena/sandbox/fabien/mln/world/inter_pixel/display_region.hh =================================================================== --- trunk/milena/sandbox/fabien/mln/world/inter_pixel/display_region.hh (revision 4171) +++ trunk/milena/sandbox/fabien/mln/world/inter_pixel/display_region.hh (revision 4172) @@ -33,16 +33,18 @@ # include <mln/core/concept/image.hh> # include <mln/core/image/image2d.hh> +# include <mln/core/alias/neighb2d.hh> # include <mln/core/image/dmorph/image_if.hh> # include <mln/core/routine/extend.hh> # include <mln/convert/from_to.hh> # include <mln/data/paste.hh> # include <mln/world/inter_pixel/is_pixel.hh> # include <mln/world/inter_pixel/is_separator.hh> +# include <mln/world/inter_pixel/is_zero_face.hh> # include <mln/opt/at.hh> # include <mln/value/rgb8.hh> -# include <mln/world/inter_pixel/is_zero_face.hh> +#include <mln/literal/colors.hh> //DEBUG namespace mln @@ -54,12 +56,14 @@ namespace inter_pixel { - /// \brief FIXME + /// \brief Create an image which is a copy of the input image (but + /// twice the size) with highlighted watershed lines. /// /// \param[in] input The input image providing pixels values. /// \param[in] wst The labeling image providing the watershed lines. /// \param[in] edge_color The color (in rgb8) for the watershed line. - /// \return FIXME + /// \return A copy of the input image (but twice the size) with + /// highlighted watershed lines. /// /// \pre \p input has to be an 8 bits image. /// \pre \p wst has to be an unmorphed image. @@ -78,6 +82,7 @@ mln_ch_value(I, value::rgb8) display_region(const Image<I>& input_, const Image<L>& wst_, value::rgb8 edge_color) { + trace::entering("world::inter_pixel::display_region"); // TODO: We should check that wst.bbox () == 2 * input.bbox() - 1. // TODO: We must check that dim(I) == dim(L). //mln_precondition((2 * input.bbox()) == wst.bbox()); @@ -114,8 +119,21 @@ typedef image_if<output_t, is_zero_face> zero_face_t; zero_face_t zero = output | is_zero_face(); mln_piter(zero_face_t) q(zero.domain()); + mln_niter(neighb2d) n(c4(), q); for_all(q) { + bool has_wst = false; + for_all(n) + { + if (!has_wst && wst(n) == 0) + { + has_wst = true; + output(q) = edge_color; + } + } + + if (!has_wst) + { unsigned row = q.row(); unsigned col = q.col(); output(q) = (opt::at(output, row + 1, col) + @@ -123,16 +141,19 @@ opt::at(output, row - 1, col) + opt::at(output, row, col - 1)) / 4; } + } // Watershed lines. - data::fill((output | pw::value(wst) == pw::cst(0)).rw(), edge_color); - //FIXME: Fill intersections. + for_all(p) + if (wst(p) == 0) + output(p) = edge_color; + trace::exiting("world::inter_pixel::display_region"); return output; + } # endif // ! MLN_INCLUDE_ONLY - } } // end of namespace mln::world::inter_pixel Index: trunk/milena/sandbox/fabien/bin/pnms2dump.cc =================================================================== --- trunk/milena/sandbox/fabien/bin/pnms2dump.cc (revision 4171) +++ trunk/milena/sandbox/fabien/bin/pnms2dump.cc (revision 4172) @@ -54,6 +54,7 @@ io::pgm::load(ima, argv[i]); arr.append(ima); } + std::cout << "nbr elements: " << arr.nelements() << std::endl; image3d<int_u8> vol = make::image3d(arr); io::dump::save(vol, argv[1]); }
participants (1)
-
Fabien Freling