r3682: Add normalization, broken

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-04-17 Fabien Freling <fabien.freling@lrde.epita.fr> Add normalization, broken. * fabien/igr/Makefile: Update with norm target. * fabien/igr/all_labels2gif.sh: Update. * fabien/igr/fun_labels.cc: Update. * fabien/igr/fun_labels.sh: Update. * fabien/igr/norm.cc: Normalize plot. * fabien/igr/time_max.cc: Update. --- Makefile | 3 + all_labels2gif.sh | 10 ++--- fun_labels.cc | 8 ++-- fun_labels.sh | 11 +++-- norm.cc | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ time_max.cc | 4 ++ 6 files changed, 123 insertions(+), 15 deletions(-) Index: trunk/milena/sandbox/fabien/igr/time_max.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/time_max.cc (revision 3681) +++ trunk/milena/sandbox/fabien/igr/time_max.cc (revision 3682) @@ -73,22 +73,26 @@ unsigned dim3 = arr_ima.nelements(); + ///////////// // // // Lissage // // // ///////////// + util::array<image2d<double> > arr_smooth; arr_smooth.append(arr_ima[0] * 1.0); for (unsigned k = 1; k < dim3 - 1; ++k) arr_smooth.append(arr_ima[k] * 0.5 + arr_ima[k - 1] * 0.25 + arr_ima[k + 1] * 0.25); arr_smooth.append(arr_ima[dim3 - 1] * 1.0); + /////////////////////////////////// // // // Calcul image max et temps max // // // /////////////////////////////////// + image2d<float> ima_c; initialize(ima_c, arr_smooth[0]); data::fill(ima_c, 0.0); Index: trunk/milena/sandbox/fabien/igr/fun_labels.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/fun_labels.cc (revision 3681) +++ trunk/milena/sandbox/fabien/igr/fun_labels.cc (revision 3682) @@ -52,7 +52,7 @@ template <typename I, typename L, typename V> inline -void plot_label(I ima, L ima_labels, V lbl) +void plot_label(Image<I>& ima, Image<L>& ima_labels, V lbl) { mln_VAR(vol_label, ima | pw::value(ima_labels) == pw::cst(lbl)); util::array<float> arr; @@ -92,7 +92,7 @@ template <typename I, typename L> inline -void plot_all_labels(I ima, L ima_labels, unsigned nlabels) +void plot_all_labels(Image<I>& ima, Image<L>& ima_labels, unsigned nlabels) { util::array<util::array<float> > arrays(nlabels); accu::mean<int_u12> accu_mean; @@ -145,7 +145,7 @@ template <typename I, typename L> inline -void plot_point(I ima, L ima_labels, point2d point, const char* desc) +void plot_point(Image<I>& ima, Image<L>& ima_labels, point2d point, const char* desc) { util::array<float> arr; label_16 prev_lbl; @@ -213,7 +213,7 @@ point2d p_poumon(122, 115); image3d<L> ima_labels; io::dump::load(ima_labels, argv[1]); - image3d<int_u12> ima; + image3d<float> ima; 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); Index: trunk/milena/sandbox/fabien/igr/norm.cc =================================================================== --- trunk/milena/sandbox/fabien/igr/norm.cc (revision 0) +++ trunk/milena/sandbox/fabien/igr/norm.cc (revision 3682) @@ -0,0 +1,102 @@ +#include <iostream> +#include <mln/core/image/image2d.hh> +#include <mln/core/image/image3d.hh> +#include <mln/core/image/slice_image.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_u12.hh> + +#include <mln/accu/image/all.hh> +#include <mln/accu/mean.hh> +#include <mln/arith/all.hh> +#include <mln/data/paste.hh> + +// DEBUG +/*#include <mln/accu/min.hh> +#include <mln/accu/max.hh> +#include <mln/level/compute.hh>*/ + +using namespace mln; +using value::int_u12; + + + +template <typename I> +inline +image2d<float> mean_slices(Image<I>& ima, int first, int last) +{ + image2d<accu::mean<float> > result; + + initialize(result, slice(ima, first)); + + accu::image::init(result); + for (int i = first; i <= last; ++i) + accu::image::take(result, slice(ima, i)); + + return accu::image::to_result(result); +} + +template <typename I> +inline +image3d<float> normalize(Image<I>& ima, int first, int last) +{ + + int min_sli = geom::bbox(ima).pmin().sli(); + int max_sli = geom::bbox(ima).pmax().sli(); + + mln_precondition(first >= min_sli && first <= max_sli); + mln_precondition(last >= min_sli && last <= max_sli); + + image3d<float> ima_f; + initialize(ima_f, ima); + data::fill(ima_f, ima); + + image2d<float> ima_ini = mean_slices(ima_f, first, last); + + image3d<float> ima_result; + initialize(ima_result, ima_f); + + for (int i = min_sli; i <= max_sli; ++i) + data::paste((slice(ima_f, i) - ima_ini), slice(ima_result, i).rw()); + + // DEBUG + /*accu::min<float> accu_min; + accu::max<float> accu_max; + float min = level::compute(accu_min, ima_ini); + float max = level::compute(accu_max, ima_ini); + std::cout << "min = " << min << std::endl; + std::cout << "max = " << max << std::endl;*/ + + return ima_result; +} + + +/////////////////// +// // +// Main Function // +// // +/////////////////// + + +int main(int argc, char *argv[]) +{ + if (argc != 3) + { + std::cout << "Usage: " << argv[0] << " ima.dump output.dump" + << std::endl; + return 1; + } + + image3d<int_u12> ima; + io::dump::load(ima, argv[1]); + image3d<float> norm = normalize(ima, 1, 8); + io::dump::save(norm, argv[2]); + + return 0; +} Index: trunk/milena/sandbox/fabien/igr/Makefile =================================================================== --- trunk/milena/sandbox/fabien/igr/Makefile (revision 3681) +++ trunk/milena/sandbox/fabien/igr/Makefile (revision 3682) @@ -54,6 +54,9 @@ label2gif: label2gif.cc ${CXX} -I../../../ ${DICOM} ${CXXFLAGS} $^ -o label2gif +norm: norm.cc + ${CXX} -I../../../ ${CXXFLAGS} $^ -o norm + clean: rm -rf *.dump *.p?m *.plot *.log *.csv *.dSYM rm seg2d seg3d wsd2d wsd3d nbasins_finder grad clo_vol wst graph med thres matlab time_max first_slice_dicom Index: trunk/milena/sandbox/fabien/igr/fun_labels.sh =================================================================== --- trunk/milena/sandbox/fabien/igr/fun_labels.sh (revision 3681) +++ trunk/milena/sandbox/fabien/igr/fun_labels.sh (revision 3682) @@ -51,7 +51,7 @@ ./crop $input 0 50 90 149 230 170 crop.dump ./grad crop.dump $dim - for lambda_closing in 5000; do + for lambda_closing in 10000; do echo " for lambda_closing = ${lambda_closing}"; ./clo_vol grad.dump $dim ${lambda_closing} nbasins=`./wst clo_vol.dump $dim` @@ -61,13 +61,14 @@ #../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 + ./norm crop.dump norm.dump + ./fun_labels wst.dump norm.dump $nbasins rename_label_plots ${lambda_closing} - ./all_labels2gif.sh ima.dump labels.dump $nbasins ${lambda_closing} +#./all_labels2gif.sh crop.dump labels.dump $nbasins ${lambda_closing} - mv *.gif results/plots/ - mv *.plot results/plots/ +#mv *.gif results/ +#mv *.plot results/plots/ #reconstruct_plot tumeur ${lambda_closing} #create_anim tumeur ${lambda_closing} Index: trunk/milena/sandbox/fabien/igr/all_labels2gif.sh =================================================================== --- trunk/milena/sandbox/fabien/igr/all_labels2gif.sh (revision 3681) +++ trunk/milena/sandbox/fabien/igr/all_labels2gif.sh (revision 3682) @@ -8,13 +8,12 @@ for i in debug_label_${4}_*.pgm; do j=${i:r}.png convert $i $j -#rm $i + 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 + convert -delay 10 -loop 0 debug_label_${4}_*.png debug_${5}_label_${4}.gif + rm debug_label_${4}_*.png } create_all_labels () @@ -31,5 +30,4 @@ echo "./all_labels2gif.sh ima ima_labels nlabels closing" } -#create_all_labels $1 $2 $3 $4 -create_label_anim $1 $2 $3 0 $4 +create_all_labels $1 $2 $3 $4
participants (1)
-
Fabien Freling