r3680: Add functions to plot labels

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-04-16 Fabien Freling <fabien.freling@lrde.epita.fr> Add functions to plot labels. * fabien/bin/Makefile: Update with Makefile.rules * fabien/bin/dumpi12_to_pgm.cc: Update. * fabien/igr/Makefile.rules: Update. * fabien/igr/Makefile: Update. * fabien/igr/all_labels2gif.sh: Create animated gif for labels. * fabien/igr/crop.cc: Crop tool. * fabien/igr/fun_labels.cc: Plot labels. * fabien/igr/fun_labels.sh: IGR current processing chain. * fabien/igr/grad.cc: Update. * fabien/igr/label2gif.cc: Create animated gif for label. * fabien/igr/mean_slices.cc: Create mean image. * fabien/igr/space_smooth/linear.cc: Update. * fabien/igr/space_smooth/morpho.cc: Update. * fabien/igr/time_smooth/linear.cc: Update. * fabien/igr/wst.cc: Update. --- TODO | 6 + bin/Makefile | 18 ---- bin/dumpi12_to_pgm.cc | 9 +- igr/Makefile | 13 ++- igr/Makefile.rules | 2 igr/all_labels2gif.sh | 35 ++++++++ igr/crop.cc | 58 ++++++++++++++ igr/fun_labels.cc | 182 +++++++++++++++++++++++++++++++++------------ igr/fun_labels.sh | 71 ++++++++++++++++- igr/grad.cc | 12 +- igr/label2gif.cc | 102 +++++++++++++++++++++++++ igr/mean_slices.cc | 88 +++++++++++++++++++++ igr/space_smooth/linear.cc | 8 - igr/space_smooth/morpho.cc | 24 +++-- igr/time_smooth/linear.cc | 6 - igr/wst.cc | 2 16 files changed, 537 insertions(+), 99 deletions(-) Index: trunk/milena/sandbox/fabien/igr/crop.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/crop.cc (revision 0) +++ trunk/milena/sandbox/fabien/igr/crop.cc (revision 3680) @@ -0,0 +1,58 @@ +#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/dicom/load.hh> +#include <mln/io/dump/save.hh> + +#include <mln/value/int_u12.hh> + + + + +/////////////////// +// // +// Main Function // +// // +/////////////////// + + +void usage(char* argv[]) +{ + std::cerr << "usage: " << argv[0] << " input.dcm s_min r_min c_min s_max r_max c_max output.dump" << std::endl; + abort(); +} + + + +int main(int argc, char* argv[]) +{ + using namespace mln; + using value::int_u12; + + if (argc != 9) + usage(argv); + + image3d<int_u12> vol; + io::dicom::load(vol, argv[1]); + + int + s_min = atoi(argv[2]), + r_min = atoi(argv[3]), + c_min = atoi(argv[4]), + + s_max = atoi(argv[5]), + r_max = atoi(argv[6]), + c_max = atoi(argv[7]); + + box3d b = make::box3d(s_min, r_min, c_min, s_max, r_max, c_max); + + image3d<int_u12> ima(b); + data::fill(ima, vol); + io::dump::save(ima, argv[8]); +} Index: trunk/milena/sandbox/fabien/igr/fun_labels.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/fun_labels.cc (revision 3679) +++ trunk/milena/sandbox/fabien/igr/fun_labels.cc (revision 3680) @@ -5,6 +5,8 @@ #include <mln/core/image/image_if.hh> #include <mln/core/image/slice_image.hh> #include <mln/core/routine/duplicate.hh> +#include <mln/core/routine/extend.hh> +#include <mln/core/var.hh> #include <mln/core/alias/neighb2d.hh> #include <mln/core/alias/window2d.hh> @@ -12,19 +14,24 @@ #include <mln/core/alias/window3d.hh> #include <mln/geom/nslis.hh> +#include <mln/geom/bbox.hh> #include <mln/io/dump/all.hh> -#include <mln/io/dicom/load.hh> +//#include <mln/io/dicom/load.hh> +#include <mln/io/pgm/save.hh> #include <mln/io/plot/save.hh> #include <mln/value/int_u8.hh> #include <mln/value/int_u12.hh> #include <mln/value/label_16.hh> -#include <mln/value/label_32.hh> #include <mln/accu/mean.hh> #include <mln/accu/median_h.hh> +#include <mln/data/fill.hh> #include <mln/level/compute.hh> +#include <mln/level/stretch.hh> +#include <mln/make/box3d.hh> +#include <mln/morpho/elementary/dilation.hh> #include <mln/pw/all.hh> #include <mln/util/array.hh> #include <mln/util/set.hh> @@ -35,67 +42,149 @@ using value::int_u8; using value::int_u12; using value::label_16; -using value::label_32; +//////////////// +// // +// Plot label // +// // +//////////////// + template <typename I, typename L, typename V> inline void plot_label(I ima, L ima_labels, V lbl) { - I ima_spe = duplicate(ima | pw::value(ima_labels) == pw::cst(lbl)); + mln_VAR(vol_label, ima | pw::value(ima_labels) == pw::cst(lbl)); util::array<float> arr; - for (int i = 0; i < ima_spe.domain().pmin().sli(); ++i) + int sli_min = geom::bbox(vol_label).pmin().sli(); + int sli_max = geom::bbox(vol_label).pmax().sli(); + + for (int i = geom::bbox(ima).pmin().sli(); i < sli_min; ++i) arr.append(0.0); - for (int sli = ima_spe.domain().pmin().sli(); sli <= ima_spe.domain().pmax().sli(); ++sli) - { - image2d<int_u12> tmp_slice = duplicate(slice(ima_spe, sli)); + + int min_row = geom::bbox(vol_label).pmin().row(); + int min_col = geom::bbox(vol_label).pmin().col(); + int max_row = geom::bbox(vol_label).pmax().row(); + int max_col = geom::bbox(vol_label).pmax().col(); + for (int sli = sli_min; sli <= sli_max; ++sli) + { + box3d slice = make::box3d(sli, min_row, min_col, + sli, max_row, max_col); + mln_VAR(slice_label, vol_label | slice); accu::mean<int_u12> accu_mean; - float mean = level::compute(accu_mean, tmp_slice); + float mean = level::compute(accu_mean, slice_label); arr.append(mean); } - for (int i = ima_spe.domain().pmax().sli() + 1; i <= ima.domain().pmax().sli(); ++i) + + for (int i = sli_max + 1; i <= geom::bbox(ima).pmax().sli(); ++i) arr.append(0.0); + std::ostringstream slabel; - slabel << "label_" << lbl << ".plot"; + slabel << "label_"; + if (lbl < 100) + slabel << "0"; + if (lbl < 10) + slabel << "0"; + // FIXME: insert label location + slabel << lbl << ".plot"; io::plot::save(arr, slabel.str()); } +template <typename I, typename L> +inline +void plot_all_labels(I ima, L ima_labels, unsigned nlabels) +{ + util::array<util::array<float> > arrays(nlabels); + accu::mean<int_u12> accu_mean; + + label_16 l = 0; + int max_slice = ima.domain().pmax().sli(); + for (int sli = ima.domain().pmin().sli(); sli < max_slice; ++sli) + { + for (unsigned l = 0; l < nlabels; ++l) + { + image2d<int_u12> ima_slice = duplicate(slice(ima, sli)); + image2d<label_16> lbl_slice = duplicate(slice(ima_labels, sli)); + float mean = level::compute(accu_mean, ima_slice | pw::value(lbl_slice) == pw::cst(l)); + arrays[l].append(mean); + } + } + + for (unsigned l = 0; l < nlabels; ++l) + { + std::ostringstream slabel; + slabel << "label_"; + if (l < 100) + slabel << "0"; + if (l < 10) + slabel << "0"; + // FIXME: insert label location + slabel << l << ".plot"; + io::plot::save(arrays[l], slabel.str()); + } +} + + +//////////////// +// // +// Plot point // +// // +//////////////// + +template <typename L> +inline +void save_label_plot(int count, const char* desc, L prev_lbl, util::array<float> arr, int start) +{ + std::ostringstream slabel; + if (count < 10) + slabel << desc << "_0" << count << "_label_" << prev_lbl << ".plot"; + else + slabel << desc << "_" << count << "_label_" << prev_lbl << ".plot"; + io::plot::save(arr, slabel.str(), start); +} template <typename I, typename L> inline void plot_point(I ima, L ima_labels, point2d point, const char* desc) { util::array<float> arr; - label_32 prev_lbl; + label_16 prev_lbl; int start = 0; int count = 1; + for (unsigned sli = 0; sli < geom::nslis(ima); ++sli) { image2d<int_u12> ima_slice = duplicate(slice(ima, sli)); - image2d<label_32> lbl_slice = duplicate(slice(ima_labels, sli)); + image2d<label_16> lbl_slice = duplicate(slice(ima_labels, sli)); if (sli == 0) prev_lbl = lbl_slice(point); if (lbl_slice(point) != prev_lbl) { - std::ostringstream slabel; - slabel << desc << "_" << count << "_label_" << prev_lbl << ".plot"; - count++; - io::plot::save(arr, slabel.str(), start); + save_label_plot(count, desc, prev_lbl, arr, start); + ++count; arr.clear(); start = sli + 1; } - // Taking the mean value of the region. - accu::mean<int_u12> accu_mean; - float mean = level::compute(accu_mean, ima_slice | pw::value(lbl_slice) == pw::cst(lbl_slice(point))); - arr.append(mean); + // Taking the median value of the region. + accu::median_h<int_u12> accu_med; + int_u12 median = level::compute(accu_med, ima_slice | pw::value(lbl_slice) == pw::cst(lbl_slice(point))); + arr.append(median); prev_lbl = lbl_slice(point); + + // Saving a image of the selected label in the current slice for debug. + data::fill((ima_slice | pw::value(lbl_slice) == pw::cst(prev_lbl)).rw(), 1750); + std::ostringstream str_ima; + str_ima << "debug_" << desc << "_"; + if (sli < 100) + str_ima << "0"; + if (sli < 10) + str_ima << "0"; + str_ima << sli << ".pgm"; + io::pgm::save(level::stretch(int_u8(), ima_slice), str_ima.str()); } + if (!arr.is_empty()) - { - std::ostringstream slabel; - slabel << desc << "_" << count << "_label_" << prev_lbl << ".plot"; - io::plot::save(arr, slabel.str(), start); - } + save_label_plot(count, desc, prev_lbl, arr, start); } @@ -108,41 +197,39 @@ int main(int argc, char *argv[]) { - typedef label_32 L; + typedef label_16 L; - if (argc != 5) + if (argc != 4) { - std::cout << "Usage: " << argv[0] << " <ima.dump> <dimensions> <ima.dcm> <nbasins>" + std::cout << "Usage: " << argv[0] << " <ima.dump> <source.dump> <nbasins>" << std::endl; return 1; } - unsigned dim = atoi(argv[2]); - if (dim != 2 && dim != 3) - { - std::cout << "<dimensions> invalid" << std::endl; - return 1; - } - - L nlabels = atoi(argv[4]); + L nlabels = atoi(argv[3]); - if (dim == 2) - { - // FIXME - } - else - { point2d p_tumeur(156, 114); point2d p_air(34, 94); point2d p_poumon(122, 115); image3d<L> ima_labels; io::dump::load(ima_labels, argv[1]); image3d<int_u12> ima; - io::dicom::load(ima, argv[3]); + io::dump::load(ima, argv[2]); + mln_VAR(dilate, morpho::elementary::dilation(extend(ima_labels | (pw::value(ima_labels) == 0u), ima_labels), c6())); + data::fill((ima_labels | (pw::value(ima_labels) == 0u)).rw(), dilate); + + //plot_all_labels(ima, ima_labels, nlabels); + + L l = 0; + for (unsigned i = 0; i < nlabels; ++i, l = i) + plot_label(ima, ima_labels, l); + + io::dump::save(ima_labels, "labels.dump"); + + //plot_point(ima, ima_labels, p_tumeur, "tumeur"); + //plot_point(ima, ima_labels, p_air, "air"); + //plot_point(ima, ima_labels, p_poumon, "poumon"); - plot_point(ima, ima_labels, p_tumeur, "tumeur"); - plot_point(ima, ima_labels, p_air, "air"); - plot_point(ima, ima_labels, p_poumon, "poumon"); /*util::set<L> lbl_set; for (int sli = 0; sli < geom::nslis(ima_labels); ++sli) { @@ -157,7 +244,6 @@ { plot_label(ima, ima_labels, siter.element()); }*/ - } return 0; } Index: trunk/milena/sandbox/fabien/igr/wst.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/wst.cc (revision 3679) +++ trunk/milena/sandbox/fabien/igr/wst.cc (revision 3680) @@ -32,7 +32,7 @@ using value::int_u12; using value::label_16; using value::label_32; - typedef label_32 L; + typedef label_16 L; if (argc != 3) { Index: trunk/milena/sandbox/fabien/igr/label2gif.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/label2gif.cc (revision 0) +++ trunk/milena/sandbox/fabien/igr/label2gif.cc (revision 3680) @@ -0,0 +1,102 @@ +#include <iostream> +#include <sstream> +#include <mln/core/image/image2d.hh> +#include <mln/core/image/image3d.hh> +#include <mln/core/image/image_if.hh> +#include <mln/core/image/slice_image.hh> +#include <mln/core/routine/duplicate.hh> +#include <mln/core/routine/extend.hh> +#include <mln/core/var.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/geom/nslis.hh> +#include <mln/geom/bbox.hh> + +#include <mln/io/dump/all.hh> +#include <mln/io/pgm/save.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/int_u12.hh> +#include <mln/value/label_16.hh> +#include <mln/value/label_32.hh> + +#include <mln/accu/mean.hh> +#include <mln/accu/median_h.hh> +#include <mln/data/fill.hh> +#include <mln/level/compute.hh> +#include <mln/level/stretch.hh> +#include <mln/make/box3d.hh> +#include <mln/morpho/elementary/dilation.hh> +#include <mln/pw/all.hh> +#include <mln/util/array.hh> +#include <mln/util/set.hh> + +using namespace mln; +using value::int_u8; +using value::int_u12; +using value::label_16; + + + +template <typename I, typename L> +inline +void label2gif(I ima, L ima_labels, label_16 label) +{ + util::array<float> arr; + + for (unsigned sli = 0; sli < geom::nslis(ima); ++sli) + { + image2d<int_u12> ima_slice = duplicate(slice(ima, sli)); + image2d<label_16> lbl_slice = duplicate(slice(ima_labels, sli)); + + // Saving a image of the selected label in the current slice for debug. + data::fill((ima_slice | pw::value(lbl_slice) == pw::cst(label)).rw(), 1750); + std::ostringstream str_ima; + str_ima << "debug_label_" << label << "_"; + + if (sli < 100) + str_ima << "0"; + if (sli < 10) + str_ima << "0"; + + str_ima << sli << ".pgm"; + io::pgm::save(level::stretch(int_u8(), ima_slice), str_ima.str()); + } +} + + +/////////////////// +// // +// Main Function // +// // +/////////////////// + + +int main(int argc, char *argv[]) +{ + typedef label_16 L; + + if (argc != 5) + { + std::cout << "Usage: " << argv[0] << " <labels.dump> <source.dump> <nbasins> <label>" + << std::endl; + return 1; + } + + unsigned nlabels = atoi(argv[3]); + L label = atoi(argv[4]); + + image3d<L> ima_labels; + io::dump::load(ima_labels, argv[1]); + image3d<int_u12> ima; + io::dump::load(ima, argv[2]); + + label2gif(ima, ima_labels, label); + + return 0; +} + Index: trunk/milena/sandbox/fabien/igr/Makefile =================================================================== --- trunk/milena/sandbox/fabien/igr/Makefile (revision 3679) +++ trunk/milena/sandbox/fabien/igr/Makefile (revision 3680) @@ -16,7 +16,7 @@ ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o nbasins_finder grad: grad.cc - ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o grad + ${CXX} -I../../../ ${CXXFLAGS} $^ -o grad clo_vol: clo_vol.cc ${CXX} -I../../../ ${CXXFLAGS} $^ -o clo_vol @@ -43,7 +43,16 @@ ${CXX} -I../../../ ${DICOM} ${MAGICK} ${CXXFLAGS} -lm $^ -o first_slice_dicom fun_labels: fun_labels.cc - ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o fun_labels + ${CXX} -I../../../ ${CXXFLAGS} $^ -o fun_labels + +mean_slices: mean_slices.cc + ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o mean_slices + +crop: crop.cc + ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o crop + +label2gif: label2gif.cc + ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o label2gif clean: rm -rf *.dump *.p?m *.plot *.log *.csv *.dSYM Index: trunk/milena/sandbox/fabien/igr/fun_labels.sh =================================================================== --- trunk/milena/sandbox/fabien/igr/fun_labels.sh (revision 3679) +++ trunk/milena/sandbox/fabien/igr/fun_labels.sh (revision 3680) @@ -1,20 +1,83 @@ #!/bin/zsh +reconstruct_plot () +{ + rm -f ${1}_${2}.plot + for i in ${1}_*_label*; do + cat $i >> ${1}_${2}.plot + done +} + +rename_label_plots () +{ + for i in label_*.plot; do + mv $i ${1}_$i + done +} + +create_anim () +{ + echo " Creating ${1} animation..." + for i in debug_${1}_*.pgm; do + j=${i:r}.png + convert $i $j + rm $i + sips -r 90 $j -o $j > /dev/null 2> /dev/null + sips -f horizontal $j -o $j > /dev/null 2> /dev/null + done + convert -delay 10 -loop 0 debug_${1}_*.png debug_${1}_${2}.gif + rm debug_${1}_*.png +} + +create_label_anim () +{ + echo " Creating ${1} animation..." + for i in debug_${1}_*.pgm; do + j=${i:r}.png + convert $i $j + rm $i + sips -r 90 $j -o $j > /dev/null 2> /dev/null + sips -f horizontal $j -o $j > /dev/null 2> /dev/null + done + convert -delay 10 -loop 0 debug_${1}_*.png debug_${1}_${2}.gif + rm debug_${1}_*.png +} + process_file () { echo "Processing $3..." input=$1 dim=$2 - ./grad $input $dim + ./crop $input 0 50 90 149 230 170 crop.dump + ./grad crop.dump $dim for lambda_closing in 5000; do echo " for lambda_closing = ${lambda_closing}"; ./clo_vol grad.dump $dim ${lambda_closing} nbasins=`./wst clo_vol.dump $dim` echo " nbasins = $nbasins" -#../bin/dumpl32_to_colorize wst.dump $dim $nbasins colorize_${3}_${lambda_closing}.ppm - ./fun_labels wst.dump $dim $input $nbasins + +#./mean_slices wst.dump $input +#../bin/dumpi12_to_png mean_slices.dump $dim mean_slices_${3}_${lambda_closing}.png +#../bin/dumpi12_to_pgm mean_slices.dump $dim mean_slices_${3}_${lambda_closing}.pgm + + ./fun_labels wst.dump crop.dump $nbasins + rename_label_plots ${lambda_closing} + + ./all_labels2gif.sh ima.dump labels.dump $nbasins ${lambda_closing} + + mv *.gif results/plots/ + mv *.plot results/plots/ + +#reconstruct_plot tumeur ${lambda_closing} +#create_anim tumeur ${lambda_closing} +#reconstruct_plot air ${lambda_closing} +#create_anim air ${lambda_closing} +#reconstruct_plot poumon ${lambda_closing} +#create_anim poumon ${lambda_closing} + done } -process_file "/Users/HiSoKa/Work/IGR/souris18/irm/IM_0052.dcm" 3 "52" +# 3D (2D + t) images only +process_file "/Users/HiSoKa/Work/IGR/souris18/irm/IM_0052.dcm" 3 52 Index: trunk/milena/sandbox/fabien/igr/space_smooth/morpho.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/space_smooth/morpho.cc (revision 3679) +++ trunk/milena/sandbox/fabien/igr/space_smooth/morpho.cc (revision 3680) @@ -1,5 +1,5 @@ #include <mln/core/image/image1d.hh> -#include <mln/core/alias/neighb1d.hh> +#include <mln/core/alias/neighb2d.hh> #include <mln/core/image/image2d.hh> #include <mln/core/image/image3d.hh> #include <mln/core/image/image_if.hh> @@ -61,14 +61,11 @@ // // //////////// util::array<image2d<int_u12> > ima_morpho; - mln_piter_(image2d<int_u12>) p(ima_morpho.domain()); - for_all(p) + for (unsigned i = 0; i < arr_ima.nelements(); ++i) { - image1d<int_u12> tmp_ima; - convert::from_to(ima_arr(p), tmp_ima); - tmp_ima = morpho::closing::area(tmp_ima, c2(), 3); - tmp_ima = morpho::opening::area(tmp_ima, c2(), 3); - ima_morpho(p) = tmp_ima; + image2d<int_u12> tmp_ima = morpho::closing::area(arr_ima[i], c4(), 3); + tmp_ima = morpho::opening::area(tmp_ima, c4(), 3); + ima_morpho.append(tmp_ima); } ///////////// @@ -87,10 +84,15 @@ mln_site_(image2d<bool>) pend(vmax); draw::line(ima_color, pbeg, pend, literal::red); io::magick::save(ima_color, "test.png");*/ + image2d<util::array<float> > ima_result(input.nrows(), input.ncols()); + mln_piter_(image2d<util::array<float> >) p(ima_morpho[0].domain()); + for_all(p) + for (int i = 0; i < ima_morpho.nelements(); ++i) + ima_result(p).append(ima_morpho[i](p)); - io::plot::save(ima_morpho(point2d(160, 120)), "morpho_tumeur.plot"); - io::plot::save(ima_morpho(point2d(34, 94)), "morpho_air.plot"); - io::plot::save(ima_morpho(point2d(122, 115)), "morpho_poumon.plot"); + io::plot::save(ima_result(point2d(156, 114)), "morpho_tumeur.plot"); + io::plot::save(ima_result(point2d(34, 94)), "morpho_air.plot"); + io::plot::save(ima_result(point2d(122, 115)), "morpho_poumon.plot"); return 0; } Index: trunk/milena/sandbox/fabien/igr/space_smooth/linear.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/space_smooth/linear.cc (revision 3679) +++ trunk/milena/sandbox/fabien/igr/space_smooth/linear.cc (revision 3680) @@ -48,9 +48,9 @@ // Linear convolution // // // //////////////////////// - float ws[] = { 0, 1/8.f, 0, - 1/8.f, 1/2.f, 1/8.f, - 0, 1/8.f, 0 }; + float ws[] = { 0.f, 0.125, 0.f, + 0.125, 0.5, 0.125, + 0.f, 0.125, 0.f }; util::array<image2d<float> > ima_linear; for (unsigned i = 0; i < arr_ima.nelements(); ++i) @@ -67,7 +67,7 @@ for (int i = 0; i < ima_linear.nelements(); ++i) ima_result(p).append(ima_linear[i](p)); - io::plot::save(ima_result(point2d(160, 120)), "linear_tumeur.plot"); + io::plot::save(ima_result(point2d(156, 114)), "linear_tumeur.plot"); io::plot::save(ima_result(point2d(34, 94)), "linear_air.plot"); io::plot::save(ima_result(point2d(122, 115)), "linear_poumon.plot"); Index: trunk/milena/sandbox/fabien/igr/time_smooth/linear.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/time_smooth/linear.cc (revision 3679) +++ trunk/milena/sandbox/fabien/igr/time_smooth/linear.cc (revision 3680) @@ -66,11 +66,11 @@ // Outputs // // // ///////////// - //io::plot::save(ima_arr(point2d(160, 120)), "ref_tumeur.plot"); + io::plot::save(ima_arr(point2d(156, 114)), "ref_tumeur.plot"); io::plot::save(ima_linear(point2d(156, 114)), "linear_tumeur.plot"); - //io::plot::save(ima_arr(point2d(34, 94)), "ref_air.plot"); + io::plot::save(ima_arr(point2d(34, 94)), "ref_air.plot"); io::plot::save(ima_linear(point2d(34, 94)), "linear_air.plot"); - //io::plot::save(ima_arr(point2d(122, 115)), "ref_poumon.plot"); + io::plot::save(ima_arr(point2d(122, 115)), "ref_poumon.plot"); io::plot::save(ima_linear(point2d(122, 115)), "linear_poumon.plot"); return 0; Index: trunk/milena/sandbox/fabien/igr/grad.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/grad.cc (revision 3679) +++ trunk/milena/sandbox/fabien/igr/grad.cc (revision 3680) @@ -7,10 +7,10 @@ #include <mln/core/alias/neighb3d.hh> #include <mln/core/alias/window3d.hh> -#include <mln/io/dicom/load.hh> -#include <mln/io/dump/save.hh> +//#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,7 +27,7 @@ int main(int argc, char *argv[]) { using namespace mln; - using value::int_u8; + //using value::int_u8; using value::int_u12; if (argc != 3) @@ -47,14 +47,14 @@ if (dim == 2) { image2d<int_u12> dcm2; - io::dicom::load(dcm2, argv[1]); + io::dump::load(dcm2, argv[1]); image2d<int_u12> grad2 = morpho::elementary::gradient(dcm2, c4()); io::dump::save(grad2, "grad.dump"); } else { image3d<int_u12> dcm3; - io::dicom::load(dcm3, argv[1]); + io::dump::load(dcm3, argv[1]); image3d<int_u12> grad3 = morpho::elementary::gradient(dcm3, c6()); io::dump::save(grad3, "grad.dump"); } Index: trunk/milena/sandbox/fabien/igr/Makefile.rules =================================================================== --- trunk/milena/sandbox/fabien/igr/Makefile.rules (revision 3679) +++ trunk/milena/sandbox/fabien/igr/Makefile.rules (revision 3680) @@ -1,5 +1,5 @@ CXX = llvm-g++ -CXXFLAGS = -DNDEBUG -O4 +CXXFLAGS = -Wall -Wextra -DNDEBUG -O4 DICOM_INC = -I/usr/local/include/gdcm-2.0 DICOM_LIBS = -lgdcmCommon -lgdcmDICT -lgdcmDSED -lgdcmIOD -lgdcmMSFF -lgdcmexpat -lgdcmjpeg12 -lgdcmjpeg16 -lgdcmjpeg8 -lgdcmopenjpeg -lgdcmuuid -lgdcmzlib \ Index: trunk/milena/sandbox/fabien/igr/mean_slices.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/mean_slices.cc (revision 0) +++ trunk/milena/sandbox/fabien/igr/mean_slices.cc (revision 3680) @@ -0,0 +1,88 @@ +#include <iostream> +#include <sstream> +#include <mln/core/image/image2d.hh> +#include <mln/core/image/image3d.hh> +#include <mln/core/image/image_if.hh> +#include <mln/core/image/slice_image.hh> +#include <mln/core/routine/duplicate.hh> +#include <mln/core/routine/extend.hh> +#include <mln/core/var.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/geom/nslis.hh> + +#include <mln/io/dump/all.hh> +#include <mln/io/dicom/load.hh> + +#include <mln/value/int_u8.hh> +#include <mln/value/int_u12.hh> +#include <mln/value/label_16.hh> +#include <mln/value/label_32.hh> + +#include <mln/accu/mean.hh> +#include <mln/accu/median_h.hh> +#include <mln/labeling/relabel.hh> +#include <mln/labeling/mean_values.hh> +#include <mln/level/compute.hh> +#include <mln/make/image3d.hh> +#include <mln/morpho/elementary/dilation.hh> +#include <mln/pw/all.hh> +#include <mln/util/array.hh> +#include <mln/util/set.hh> + + + +using namespace mln; +using value::int_u8; +using value::int_u12; +using value::label_16; +using value::label_32; + + + +/////////////////// +// // +// Main Function // +// // +/////////////////// + + +int main(int argc, char *argv[]) +{ + typedef label_32 L; + + if (argc != 3) + { + std::cout << "Usage: " << argv[0] << " <ima.dump> <ima.dcm>" + << std::endl; + return 1; + } + + L nlabels = 0; + + image3d<L> ima_labels; + io::dump::load(ima_labels, argv[1]); + image3d<int_u12> ima; + io::dicom::load(ima, argv[2]); + util::array<image2d<int_u12> > arr; + mln_VAR(dilate, morpho::elementary::dilation(extend(ima_labels | (pw::value(ima_labels) == 0u), ima_labels), c6())); + data::fill((ima_labels | (pw::value(ima_labels) == 0u)).rw(), dilate); + + for (unsigned i = 0; i < ima.nslices(); ++i) + { + image2d<int_u12> sli = duplicate(slice(ima, i)); + image2d<L> sli_labels = duplicate(slice(ima_labels, i)); + image2d<L> labels = labeling::relabel(sli_labels, nlabels); + mln_VAR(mean_slice, labeling::mean_values(sli, labels, nlabels)); + arr.append(mean_slice); + } + + image3d<int_u12> vol = make::image3d(arr); + io::dump::save(vol, "mean_slices.dump"); + + return 0; +} Index: trunk/milena/sandbox/fabien/igr/all_labels2gif.sh =================================================================== --- trunk/milena/sandbox/fabien/igr/all_labels2gif.sh (revision 0) +++ trunk/milena/sandbox/fabien/igr/all_labels2gif.sh (revision 3680) @@ -0,0 +1,35 @@ +#!/bin/zsh + + +create_label_anim () +{ + echo " Creating label ${4} animation..." + ./label2gif $2 $1 $3 $4 + for i in debug_label_${4}_*.pgm; do + j=${i:r}.png + convert $i $j +#rm $i + sips -r 90 $j -o $j > /dev/null 2> /dev/null + sips -f horizontal $j -o $j > /dev/null 2> /dev/null + done + echo $4 $5 + convert -delay 10 -loop 0 debug_label_${4}_*.png debug_label_${4}_${5}.gif +#rm debug_label_${4}_*.png +} + +create_all_labels () +{ + count=0; + while [ $count -lt $3 ]; do + create_label_anim $1 $2 $3 $count $4 + count=$(($count + 1)) + done +} + +usage () +{ + echo "./all_labels2gif.sh ima ima_labels nlabels closing" +} + +#create_all_labels $1 $2 $3 $4 +create_label_anim $1 $2 $3 0 $4 Property changes on: trunk/milena/sandbox/fabien/igr/all_labels2gif.sh ___________________________________________________________________ Name: svn:executable + * Index: trunk/milena/sandbox/fabien/TODO =================================================================== --- trunk/milena/sandbox/fabien/TODO (revision 3679) +++ trunk/milena/sandbox/fabien/TODO (revision 3680) @@ -44,3 +44,9 @@ [X] Fast projected histogram [ ] Triple histogram [X] Create plot for each kind of point with each method +[ ] Fix mean slices values +[X] Compatibility Windows +[X] Fix spatial smooth +[ ] Crop volume 52 +[ ] Plot all labels (3, 4 labels for tumeur) +[ ] Prepare data for IGR Index: trunk/milena/sandbox/fabien/bin/dumpi12_to_pgm.cc =================================================================== --- trunk/milena/sandbox/fabien/bin/dumpi12_to_pgm.cc (revision 3679) +++ trunk/milena/sandbox/fabien/bin/dumpi12_to_pgm.cc (revision 3680) @@ -4,7 +4,6 @@ #include <mln/value/int_u8.hh> #include <mln/value/int_u12.hh> -#include <mln/value/label_32.hh> #include <mln/io/dump/load.hh> #include <mln/io/pgm/save.hh> @@ -25,7 +24,6 @@ using namespace mln; using value::int_u8; using value::int_u12; - using value::label_32; using value::rgb8; if (argc != 4) @@ -48,7 +46,12 @@ } else { - // FIXME + image3d<int_u12> ima3d; + io::dump::load(ima3d, argv[1]); + image3d<int_u8> ima_pgm = level::stretch(int_u8(), ima3d); + + image2d<int_u8> ima_result = debug::slices_2d(ima_pgm, 1.f, 0); + io::pgm::save(ima_result, argv[3]); } return 0; Index: trunk/milena/sandbox/fabien/bin/Makefile =================================================================== --- trunk/milena/sandbox/fabien/bin/Makefile (revision 3679) +++ trunk/milena/sandbox/fabien/bin/Makefile (revision 3680) @@ -1,18 +1,4 @@ -GDCM_SRC_DIR = /Users/HiSoKa/Downloads/gdcm-2.0.10 -GDCM_BIN_DIR = /Users/HiSoKa/Downloads/gdcmbin - -DICOM_INC = -I${GDCM_SRC_DIR}/Source/Common/ \ - -I${GDCM_BIN_DIR}/Source/Common/ \ - -I${GDCM_SRC_DIR}/Source/DataDictionary/ \ - -I${GDCM_SRC_DIR}/Source/MediaStorageAndFileFormat/ \ - -I${GDCM_SRC_DIR}/Source/DataStructureAndEncodingDefinition/ - -# "-framework CoreFoundation" is a Mac OS X specific flag -DICOM_LIB = -L${GDCM_BIN_DIR}/bin \ - -lgdcmCommon -lgdcmDICT -lgdcmDSED -lgdcmIOD -lgdcmMSFF -lgdcmexpat -lgdcmjpeg12 -lgdcmjpeg16 -lgdcmjpeg8 -lgdcmopenjpeg -lgdcmuuid -lgdcmzlib \ - -framework CoreFoundation - -CXXFLAGS = -DNDEBUG -O1 +include ../igr/Makefile.rules all: mask dump @@ -20,7 +6,7 @@ g++ -I../../../ ${DICOM_INC} ${DICOM_LIB} ${CXXFLAGS} $^ -o dicom_mask dump: dicom2dump.cc - g++ -I../../../ ${DICOM_INC} ${DICOM_LIB} ${CXXFLAGS} $^ -o dicom2dump + ${CXX} -I../../../ ${CXXFLAGS} ${DICOM} $^ -o dicom2dump pgm: dicom2pgm.cc g++ -I../../../ ${DICOM_INC} ${DICOM_LIB} ${CXXFLAGS} $^ -o dicom2pgm
participants (1)
-
Fabien Freling