* green/mln/display/display_histo.cc: Add new vizualisations. * green/mln/display/project_histo.cc: Add new color projections. --- milena/sandbox/ChangeLog | 7 + milena/sandbox/green/mln/display/display_histo.hh | 75 ++++-- milena/sandbox/green/mln/display/project_histo.hh | 341 +++++++++++++-------- 3 files changed, 279 insertions(+), 144 deletions(-)
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog index 097ea5c..d53313f 100644 --- a/milena/sandbox/ChangeLog +++ b/milena/sandbox/ChangeLog @@ -1,5 +1,12 @@ 2010-02-10 Yann Jacquelet jacquelet@lrde.epita.fr
+ Fix bugs in the histogram visualization tools. + + * green/mln/display/display_histo.cc: Add new vizualisations. + * green/mln/display/project_histo.cc: Add new color projections. + +2010-02-10 Yann Jacquelet jacquelet@lrde.epita.fr + Fix last details in the image processing chain.
* green/tools/annotating/histo/histo.cc: Manage new inputs/outputs. diff --git a/milena/sandbox/green/mln/display/display_histo.hh b/milena/sandbox/green/mln/display/display_histo.hh index 2ba0b61..ef47182 100644 --- a/milena/sandbox/green/mln/display/display_histo.hh +++ b/milena/sandbox/green/mln/display/display_histo.hh @@ -29,12 +29,14 @@ # define MLN_DISPLAY_DISPLAY_HISTO_HH
# include <mln/accu/math/sum.hh> +# include <mln/algebra/vec.hh> # include <mln/data/stretch.hh> # include <mln/display/project_histo.hh> # include <mln/fun/v2v/log.hh> # include <mln/value/int_u8.hh> # include <mln/value/rgb8.hh> # include <mln/value/label_8.hh> +# include <mln/util/array.hh>
/// \file @@ -57,19 +59,28 @@ namespace mln image2dvalue::int_u8 display_histo3d_unsigned(const image3d<unsigned>& histo);
- image2dvalue::int_u8 - display2_histo3d_unsigned(const image3d<unsigned>& histo); + template <unsigned n> + image2d< value::int_u<n> > + display2_histo3d_unsigned(const image3d<unsigned>& histo, + const value::int_u<n> ambiguous_color);
+ template <unsigned n> image2dvalue::label_8 display2_histo3d_unsigned(const image3d<unsigned>& histo, - const image3dvalue::label_8& label); + const image3dvalue::label_8& label, + const value::label_8 ambiguous_label);
- image2dvalue::rgb8 - display3_histo3d_unsigned(const image3d<unsigned>& histo); + template <unsigned n> + image2d< value::rgb<n> > + display3_histo3d_unsigned(const image3d<unsigned>& histo, + const value::rgb<n> ambiguous_color);
- image2dvalue::rgb8 - display3_histo3d_unsigned(const image3d<unsigned>& histo, - const image3dvalue::label_8& label); + template <unsigned n> + image2d< value::rgb8 > + display3_histo3d_unsigned(const image3d<unsigned>& histo, + const image3dvalue::label_8& label, + const util::array< algebra::vec<3,float> >& pal, + const value::rgb8 ambiguous_color);
#ifndef MLN_INCLUDE_ONLY
@@ -87,7 +98,7 @@ namespace mln /// \parameter[in] histo the histogram in 3d. /// \result return a equivalent 2d image.
- + // FIXME : display_shape [in int_u8] image2dvalue::int_u8 display_histo3d_unsigned(const image3d<unsigned>& histo) { @@ -102,40 +113,62 @@ namespace mln return proj_int; }
- image2dvalue::int_u8 - display2_histo3d_unsigned(const image3d<unsigned>& histo) + // FIXME : display_color [in int_un] + template <unsigned n> + image2d< value::int_u<n> > + display2_histo3d_unsigned(const image3d<unsigned>& histo, + const value::int_u<n> ambiguous_color) { - image2dvalue::int_u8 proj = project2_histo<0>(histo); + image2d< value::int_u<n> > proj = project2_histo<n,0>(histo, + ambiguous_color);
return proj; }
+ // FIXME : display_label [in label] + template <unsigned n> image2dvalue::label_8 display2_histo3d_unsigned(const image3d<unsigned>& histo, - const image3dvalue::label_8& label) + const image3dvalue::label_8& label, + const value::label_8 ambiguous_label) { - image2dvalue::label_8 proj = project2_histo<0>(histo, label); + image2dvalue::label_8 proj = project2_histo<n,0>(histo, + label, + ambiguous_label);
return proj; }
- image2dvalue::rgb8 - display3_histo3d_unsigned(const image3d<unsigned>& histo) + // FIXME : display_color [in color] + template <unsigned n> + image2d< value::rgb<n> > + display3_histo3d_unsigned(const image3d<unsigned>& histo, + const value::rgb<n> ambiguous_color) { - image2dvalue::rgb8 proj = project3_histo<0>(histo); + image2d< value::rgb<n> > proj = project3_histo<n,0>(histo, + ambiguous_color);
return proj; }
- image2dvalue::rgb8 - display3_histo3d_unsigned(const image3d<unsigned>& histo, - const image3dvalue::label_8& label) + + // FIXME : display_label [in color] + template <unsigned n> + image2d< value::rgb8 > + display3_histo3d_unsigned(const image3d<unsigned>& histo, + const image3dvalue::label_8& label, + const util::array<algebra::vec<3,float> >& pal, + const value::rgb8 ambiguous_color) { - image2dvalue::rgb8 proj = project3_histo<0>(histo, label); + image2d< value::rgb8 > proj = project3_histo<n,0>(histo, + label, + pal, + ambiguous_color);
return proj; }
+ #endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/sandbox/green/mln/display/project_histo.hh b/milena/sandbox/green/mln/display/project_histo.hh index d842c70..30bcd6d 100644 --- a/milena/sandbox/green/mln/display/project_histo.hh +++ b/milena/sandbox/green/mln/display/project_histo.hh @@ -37,12 +37,16 @@ # include <mln/accu/image/take.hh> # include <mln/accu/image/to_result.hh>
+# include <mln/algebra/vec.hh> + # include <mln/opt/at.hh>
# include <mln/value/int_u8.hh> # include <mln/value/rgb8.hh> # include <mln/value/label_8.hh>
+# include <mln/util/array.hh> + /// \file /// /// \brief Allow the visualization of 3d histogram. @@ -60,9 +64,30 @@ namespace mln image2d<mln_result(A)> project_histo(const image3d<V>& histo);
- template <typename A, unsigned direction, typename V> + template <typename A, unsigned n, unsigned direction, typename V> image2d<mln_result(A)> - project2_histo(const image3d<V>& histo); + project2_histo(const image3d<V>& histo, + const value::int_u<n>& ambiguous_color); + + template <unsigned n, unsigned direction, typename V> + image2d<V> + project2_histo(const image3d<unsigned>& histo, + const image3d<V>& label); + + template <unsigned n, unsigned direction> + image2d< value::rgb<n> > + project3_histo(const image3d<unsigned>& histo, + const value::rgb<n> ambiguous_color); + + template <unsigned n, unsigned direction> + image2d< value::rgb8 > + project3_histo(const image3d<unsigned>& histo, + const image3dvalue::label_8& label, + const util::array<algebra::vec<3, float> >& pal, + const value::rgb8 ambiguous_color); + // FIXME ==> palette must be 1d-image not an array !! + +
# ifndef MLN_INCLUDE_ONLY
@@ -96,80 +121,96 @@ namespace mln return accu::image::to_result(histo_accu); }
- template <unsigned direction> - image2dvalue::int_u8 - project2_histo(const image3d<unsigned>& histo) + // 0 ==> blue + // 1 ==> red + // 2 ==> green + + // mln::opt::at(histo, blue, red, green) + + template <unsigned n, unsigned direction> + image2d< value::int_u<n> > + project2_histo(const image3d<unsigned>& histo, + const value::int_u<n>& ambiguous_color) { - image2dvalue::int_u8 result; + image2d< value::int_u<n> > result;
if (0 == direction) // blue { - image2dvalue::int_u8 arg_max(histo.ncols(), histo.nslices()); + image2d< value::int_u<n> > arg_max(histo.nrows(), histo.ncols());
- for (unsigned j = 0; j < histo.ncols(); ++j) - for (unsigned i = 0; i < histo.nslices(); ++i) + for (def::coord green = 0; green < (signed)histo.ncols(); ++green) + for (def::coord red = 0; red < (signed)histo.nrows(); ++red) { - unsigned max = 0; // minimum as possible - signed pos = -1; + unsigned max = 0; // minimum as possible + def::coord pos = -1;
- for (unsigned k = 0; k < histo.nrows(); ++k) + for (def::coord blue = 0; blue < (signed)histo.nslices(); ++blue) { - if (max <= opt::at(histo,i,j,k)) + if (max < opt::at(histo,blue,red,green)) { - max = opt::at(histo,i,j,k); - pos = k; + max = opt::at(histo,blue,red,green); + pos = blue; } }
- opt::at(arg_max,i,j) = pos; + if (-1 == pos) + opt::at(arg_max,red,green) = ambiguous_color; + else + opt::at(arg_max,red,green) = pos; }
result = arg_max; } else if (1 == direction) // red { - image2dvalue::int_u8 arg_max(histo.nrows(), histo.nslices()); + image2d< value::int_u<n> > arg_max(histo.ncols(), histo.nslices());
- for (unsigned j = 0; j < histo.nslices(); ++j) - for (unsigned i = 0; i < histo.nrows(); ++i) + for (def::coord blue = 0; blue < (signed)histo.nslices(); ++blue) + for (def::coord green = 0; green < (signed)histo.ncols(); ++green) { unsigned max = 0; // minimum as possible signed pos = -1;
- for (unsigned k = 0; k < histo.ncols(); ++k) + for (def::coord red = 0; red < (signed)histo.nrows(); ++red) { - if (max <= opt::at(histo,i,j,k)) + if (max < opt::at(histo,blue,red,green)) { - max = opt::at(histo,i,j,k); - pos = k; + max = opt::at(histo,blue,red,green); + pos = red; } }
- opt::at(arg_max,i,j) = pos; + if (-1 == pos) + opt::at(arg_max,green,blue) = ambiguous_color; + else + opt::at(arg_max,green,blue) = pos; }
result = arg_max; } else // 2 == direction // green { - image2dvalue::int_u8 arg_max(histo.nrows(), histo.ncols()); + image2d< value::int_u<n> > arg_max(histo.nrows(), histo.nslices());
- for (unsigned j = 0; j < histo.ncols(); ++j) - for (unsigned i = 0; i < histo.nrows(); ++i) + for (def::coord blue = 0; blue < (signed)histo.nslices(); ++blue) + for (def::coord red = 0; red < (signed)histo.nrows(); ++red) { unsigned max = 0; // minimum as possible signed pos = -1;
- for (unsigned k = 0; k < histo.nslices(); ++k) + for (def::coord green = 0; green < (signed)histo.ncols(); ++green) { - if (max <= opt::at(histo,i,j,k)) + if (max < opt::at(histo,blue,red,green)) { - max = opt::at(histo,i,j,k); - pos = k; + max = opt::at(histo,blue,red,green); + pos = green; } }
- opt::at(arg_max,i,j) = pos; + if (-1 == pos) + opt::at(arg_max,red,blue) = ambiguous_color; + else + opt::at(arg_max,red,blue) = pos; }
result = arg_max; @@ -178,81 +219,91 @@ namespace mln return result; }
- template <unsigned direction> + template <unsigned n, unsigned direction> image2dvalue::label_8 project2_histo(const image3d<unsigned>& histo, - const image3dvalue::label_8& label) + const image3dvalue::label_8& label, + const value::label_8 ambiguous_label) { image2dvalue::label_8 result;
if (0 == direction) // blue { - image2dvalue::label_8 arg_max(histo.ncols(), histo.nslices()); + image2dvalue::label_8 arg_max(histo.nrows(), histo.ncols());
- for (unsigned j = 0; j < histo.ncols(); ++j) - for (unsigned i = 0; i < histo.nslices(); ++i) + for (def::coord green = 0; green < (signed)histo.ncols(); ++green) + for (def::coord red = 0; red < (signed)histo.nrows(); ++red) { - unsigned max = 0; // minimum as possible - signed pos = -1; + unsigned max = 0; // minimum as possible + def::coord pos = -1;
- for (unsigned k = 0; k < histo.nrows(); ++k) + for (def::coord blue = 0; blue < (signed)histo.nslices(); ++blue) { - if (max <= opt::at(histo,i,j,k)) + if (max < opt::at(histo,blue,red,green)) { - max = opt::at(histo,i,j,k); - pos = k; + max = opt::at(histo,blue,red,green); + pos = blue; } }
- opt::at(arg_max,i,j) = opt::at(label,i,j,pos); + if (-1 == pos) + opt::at(arg_max,red,green) = ambiguous_label; + else + opt::at(arg_max,red,green) = opt::at(label, pos, red, green); }
result = arg_max; } else if (1 == direction) // red { - image2dvalue::label_8 arg_max(histo.nrows(), histo.nslices()); + image2dvalue::label_8 arg_max(histo.ncols(), histo.nslices());
- for (unsigned j = 0; j < histo.nslices(); ++j) - for (unsigned i = 0; i < histo.nrows(); ++i) + for (def::coord blue = 0; blue < (signed)histo.nslices(); ++blue) + for (def::coord green = 0; green < (signed)histo.ncols(); ++green) { unsigned max = 0; // minimum as possible signed pos = -1;
- for (unsigned k = 0; k < histo.ncols(); ++k) + for (def::coord red = 0; red < (signed)histo.nrows(); ++red) { - if (max <= opt::at(histo,i,j,k)) + if (max < opt::at(histo,blue,red,green)) { - max = opt::at(histo,i,j,k); - pos = k; + max = opt::at(histo,blue,red,green); + pos = red; } }
- opt::at(arg_max,i,j) = opt::at(label,pos,i,j); + if (-1 == pos) + opt::at(arg_max,green,blue) = ambiguous_label; + else + opt::at(arg_max,green,blue) = opt::at(label, blue, pos, green); }
result = arg_max; } else // 2 == direction // green { - image2dvalue::label_8 arg_max(histo.nrows(), histo.ncols()); + image2dvalue::label_8 arg_max(histo.nrows(), histo.nslices());
- for (unsigned j = 0; j < histo.ncols(); ++j) - for (unsigned i = 0; i < histo.nrows(); ++i) + for (def::coord blue = 0; blue < (signed)histo.nslices(); ++blue) + for (def::coord red = 0; red < (signed)histo.nrows(); ++red) { unsigned max = 0; // minimum as possible signed pos = -1;
- for (unsigned k = 0; k < histo.nslices(); ++k) + for (def::coord green = 0; green < (signed)histo.ncols(); ++green) { - if (max <= opt::at(histo,i,j,k)) + if (max < opt::at(histo,blue,red,green)) { - max = opt::at(histo,i,j,k); - pos = k; + max = opt::at(histo,blue,red,green); + pos = green; } }
- opt::at(arg_max,i,j) = opt::at(label,i,pos,j); + if (-1 == pos) + opt::at(arg_max,red,blue) = ambiguous_label; + else + opt::at(arg_max,red,blue) = opt::at(label, blue, red, pos); }
result = arg_max; @@ -262,83 +313,117 @@ namespace mln }
+ + // FIXME ... determine the color of each class. - template <unsigned direction> - image2dvalue::rgb8 - project3_histo(const image3d<unsigned>& histo, - const image3dvalue::label_8& label) + // FIXME la palette est supposée en 8 bits + template <unsigned n, unsigned direction> + image2d< value::rgb8 > + project3_histo(const image3d<unsigned>& histo, + const image3dvalue::label_8& label, + const util::array<algebra::vec<3,float> >& pal, + const value::rgb8 ambiguous_color) { - image2dvalue::rgb8 result; + image2d< value::rgb8 > result;
if (0 == direction) // blue { - image2dvalue::rgb8 arg_max(histo.ncols(), histo.nslices()); + image2d< value::rgb8 > arg_max(histo.nrows(), histo.ncols());
- for (unsigned j = 0; j < histo.ncols(); ++j) - for (unsigned i = 0; i < histo.nslices(); ++i) + for (def::coord green = 0; green < (signed)histo.ncols(); ++green) + for (def::coord red = 0; red < (signed)histo.nrows(); ++red) { - unsigned max = 0; // minimum as possible - signed pos = -1; + unsigned max = 0; // minimum as possible + def::coord pos = -1;
- for (unsigned k = 0; k < histo.nrows(); ++k) + for (def::coord blue = 0; blue < (signed)histo.nslices(); ++blue) { - if (max <= opt::at(histo,i,j,k)) + if (max < opt::at(histo,blue,red,green)) { - max = opt::at(histo,i,j,k); - pos = k; + max = opt::at(histo,blue,red,green); + pos = blue; } }
- opt::at(arg_max,i,j) = value::rgb8(i,j,pos); + if (-1 == pos) + opt::at(arg_max,red,green) = ambiguous_color; + else + { + value::int_u8 r = pal[opt::at(label,pos,red,green)][0]; + value::int_u8 g = pal[opt::at(label,pos,red,green)][1]; + value::int_u8 b = pal[opt::at(label,pos,red,green)][2]; + value::rgb8 color(r,g,b); + + opt::at(arg_max,red,green) = color; + } }
result = arg_max; } else if (1 == direction) // red { - image2dvalue::rgb8 arg_max(histo.nrows(), histo.nslices()); + image2d< value::rgb8 > arg_max(histo.ncols(), histo.nslices());
- for (unsigned j = 0; j < histo.nslices(); ++j) - for (unsigned i = 0; i < histo.nrows(); ++i) + for (def::coord blue = 0; blue < (signed)histo.nslices(); ++blue) + for (def::coord green = 0; green < (signed)histo.ncols(); ++green) { unsigned max = 0; // minimum as possible signed pos = -1;
- for (unsigned k = 0; k < histo.ncols(); ++k) + for (def::coord red = 0; red < (signed)histo.nrows(); ++red) { - if (max <= opt::at(histo,i,j,k)) + if (max < opt::at(histo,blue,red,green)) { - max = opt::at(histo,i,j,k); - pos = k; + max = opt::at(histo,blue,red,green); + pos = red; } }
- opt::at(arg_max,i,j) = value::rgb8(pos,i,j); + if (-1 == pos) + opt::at(arg_max,green,blue) = ambiguous_color; + else + { + value::int_u8 r = pal[opt::at(label,blue,pos,green)][0]; + value::int_u8 g = pal[opt::at(label,blue,pos,green)][1]; + value::int_u8 b = pal[opt::at(label,blue,pos,green)][2]; + value::rgb8 color(r,g,b); + + opt::at(arg_max,green,blue) = color; + } }
result = arg_max; } else // 2 == direction // green { - image2dvalue::rgb8 arg_max(histo.nrows(), histo.ncols()); + image2d< value::rgb8 > arg_max(histo.nrows(), histo.nslices());
- for (unsigned j = 0; j < histo.ncols(); ++j) - for (unsigned i = 0; i < histo.nrows(); ++i) + for (def::coord blue = 0; blue < (signed)histo.nslices(); ++blue) + for (def::coord red = 0; red < (signed)histo.nrows(); ++red) { unsigned max = 0; // minimum as possible signed pos = -1;
- for (unsigned k = 0; k < histo.nslices(); ++k) + for (def::coord green = 0; green < (signed)histo.ncols(); ++green) { - if (max <= opt::at(histo,i,j,k)) + if (max < opt::at(histo,blue,red,green)) { - max = opt::at(histo,i,j,k); - pos = k; + max = opt::at(histo,blue,red,green); + pos = green; } }
- // FIXME ... how to fix the n of rgb - opt::at(arg_max,i,j) = value::rgb8(i,pos,j); + if (-1 == pos) + opt::at(arg_max,red,blue) = ambiguous_color; + else + { + value::int_u8 r = pal[opt::at(label,blue,red,pos)][0]; + value::int_u8 g = pal[opt::at(label,blue,red,pos)][1]; + value::int_u8 b = pal[opt::at(label,blue,red,pos)][2]; + value::rgb8 color(r,g,b); + + opt::at(arg_max,red,blue) = color; + } }
result = arg_max; @@ -347,81 +432,91 @@ namespace mln return result; }
- template <unsigned direction> - image2dvalue::rgb8 - project3_histo(const image3d<unsigned>& histo) + + template <unsigned n, unsigned direction> + image2d< value::rgb<n> > + project3_histo(const image3d<unsigned>& histo, + const value::rgb<n> ambiguous_color) { - image2dvalue::rgb8 result; + image2d< value::rgb<n> > result;
if (0 == direction) // blue { - image2dvalue::rgb8 arg_max(histo.ncols(), histo.nslices()); + image2d< value::rgb<n> > arg_max(histo.nrows(), histo.ncols());
- for (unsigned j = 0; j < histo.ncols(); ++j) - for (unsigned i = 0; i < histo.nslices(); ++i) + for (def::coord green = 0; green < (signed)histo.ncols(); ++green) + for (def::coord red = 0; red < (signed)histo.nrows(); ++red) { - unsigned max = 0; // minimum as possible - signed pos = -1; + unsigned max = 0; // minimum as possible + def::coord pos = -1;
- for (unsigned k = 0; k < histo.nrows(); ++k) + for (def::coord blue = 0; blue < (signed)histo.nslices(); ++blue) { - if (max <= opt::at(histo,i,j,k)) + if (max < opt::at(histo,blue,red,green)) { - max = opt::at(histo,i,j,k); - pos = k; + max = opt::at(histo,blue,red,green); + pos = blue; } }
- opt::at(arg_max,i,j) = value::rgb8(i,j,pos); + if (-1 == pos) + opt::at(arg_max,red,green) = ambiguous_color; + else + opt::at(arg_max,red,green) = value::rgb<n>(red,green,pos); }
result = arg_max; } else if (1 == direction) // red { - image2dvalue::rgb8 arg_max(histo.nrows(), histo.nslices()); + image2d< value::rgb<n> > arg_max(histo.ncols(), histo.nslices());
- for (unsigned j = 0; j < histo.nslices(); ++j) - for (unsigned i = 0; i < histo.nrows(); ++i) + for (def::coord blue = 0; blue < (signed)histo.nslices(); ++blue) + for (def::coord green = 0; green < (signed)histo.ncols(); ++green) { unsigned max = 0; // minimum as possible signed pos = -1;
- for (unsigned k = 0; k < histo.ncols(); ++k) + for (def::coord red = 0; red < (signed)histo.nrows(); ++red) { - if (max <= opt::at(histo,i,j,k)) + if (max < opt::at(histo,blue,red,green)) { - max = opt::at(histo,i,j,k); - pos = k; + max = opt::at(histo,blue,red,green); + pos = red; } }
- opt::at(arg_max,i,j) = value::rgb8(pos,i,j); + if (-1 == pos) + opt::at(arg_max,green,blue) = ambiguous_color; + else + opt::at(arg_max,green,blue) = value::rgb<n>(pos,green,blue);; }
result = arg_max; } else // 2 == direction // green { - image2dvalue::rgb8 arg_max(histo.nrows(), histo.ncols()); + image2d< value::rgb<n> > arg_max(histo.nrows(), histo.nslices());
- for (unsigned j = 0; j < histo.ncols(); ++j) - for (unsigned i = 0; i < histo.nrows(); ++i) + for (def::coord blue = 0; blue < (signed)histo.nslices(); ++blue) + for (def::coord red = 0; red < (signed)histo.nrows(); ++red) { unsigned max = 0; // minimum as possible signed pos = -1;
- for (unsigned k = 0; k < histo.nslices(); ++k) + for (def::coord green = 0; green < (signed)histo.ncols(); ++green) { - if (max <= opt::at(histo,i,j,k)) + if (max < opt::at(histo,blue,red,green)) { - max = opt::at(histo,i,j,k); - pos = k; + max = opt::at(histo,blue,red,green); + pos = green; } }
- // FIXME ... how to fix the n of rgb - opt::at(arg_max,i,j) = value::rgb8(i,pos,j); + if (-1 == pos) + opt::at(arg_max,red,blue) = ambiguous_color; + else + opt::at(arg_max,red,blue) = value::rgb<n>(red,pos,blue); }
result = arg_max;