* green/mln/display/project_histo.hh (project2_histo): New functions
that keep the max of the histogram or the class associate to it while
projecting along a direction.
* green/mln/display/project_histo.hh (project3_histo): New functions
that keep the color of the class associate to the histogram maximum
while projecting along a direction.
* green/mln/display/display_histo.hh: New interface functions for
project2_histo and project3_histo.
---
milena/sandbox/ChangeLog | 13 +
milena/sandbox/green/mln/display/display_histo.hh | 50 +++
milena/sandbox/green/mln/display/project_histo.hh | 344 +++++++++++++++++++++
3 files changed, 407 insertions(+), 0 deletions(-)
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index de56c51..f56ea7a 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -77,6 +77,19 @@
2010-01-05 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+ Extend the histogram visualization tools for new projection concept.
+
+ * green/mln/display/project_histo.hh (project2_histo): New functions
+ that keep the max of the histogram or the class associate to it while
+ projecting along a direction.
+ * green/mln/display/project_histo.hh (project3_histo): New functions
+ that keep the color of the class associate to the histogram maximum
+ while projecting along a direction.
+ * green/mln/display/display_histo.hh: New interface functions for
+ project2_histo and project3_histo.
+
+2010-01-05 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
Build translation table between number of pixels and percentage of
pixels in image for the scribo database.
diff --git a/milena/sandbox/green/mln/display/display_histo.hh
b/milena/sandbox/green/mln/display/display_histo.hh
index 1fd5da4..2ba0b61 100644
--- a/milena/sandbox/green/mln/display/display_histo.hh
+++ b/milena/sandbox/green/mln/display/display_histo.hh
@@ -33,6 +33,8 @@
# 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>
/// \file
@@ -55,6 +57,20 @@ namespace mln
image2d<value::int_u8>
display_histo3d_unsigned(const image3d<unsigned>& histo);
+ image2d<value::int_u8>
+ display2_histo3d_unsigned(const image3d<unsigned>& histo);
+
+ image2d<value::label_8>
+ display2_histo3d_unsigned(const image3d<unsigned>& histo,
+ const image3d<value::label_8>& label);
+
+ image2d<value::rgb8>
+ display3_histo3d_unsigned(const image3d<unsigned>& histo);
+
+ image2d<value::rgb8>
+ display3_histo3d_unsigned(const image3d<unsigned>& histo,
+ const image3d<value::label_8>& label);
+
#ifndef MLN_INCLUDE_ONLY
/// \brief Allow the visualization of a 3d histogram by projection.
@@ -86,6 +102,40 @@ namespace mln
return proj_int;
}
+ image2d<value::int_u8>
+ display2_histo3d_unsigned(const image3d<unsigned>& histo)
+ {
+ image2d<value::int_u8> proj = project2_histo<0>(histo);
+
+ return proj;
+ }
+
+ image2d<value::label_8>
+ display2_histo3d_unsigned(const image3d<unsigned>& histo,
+ const image3d<value::label_8>& label)
+ {
+ image2d<value::label_8> proj = project2_histo<0>(histo, label);
+
+ return proj;
+ }
+
+ image2d<value::rgb8>
+ display3_histo3d_unsigned(const image3d<unsigned>& histo)
+ {
+ image2d<value::rgb8> proj = project3_histo<0>(histo);
+
+ return proj;
+ }
+
+ image2d<value::rgb8>
+ display3_histo3d_unsigned(const image3d<unsigned>& histo,
+ const image3d<value::label_8>& label)
+ {
+ image2d<value::rgb8> proj = project3_histo<0>(histo, label);
+
+ 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 f0e6858..d842c70 100644
--- a/milena/sandbox/green/mln/display/project_histo.hh
+++ b/milena/sandbox/green/mln/display/project_histo.hh
@@ -37,6 +37,12 @@
# include <mln/accu/image/take.hh>
# include <mln/accu/image/to_result.hh>
+# include <mln/opt/at.hh>
+
+# include <mln/value/int_u8.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/value/label_8.hh>
+
/// \file
///
/// \brief Allow the visualization of 3d histogram.
@@ -54,6 +60,10 @@ namespace mln
image2d<mln_result(A)>
project_histo(const image3d<V>& histo);
+ template <typename A, unsigned direction, typename V>
+ image2d<mln_result(A)>
+ project2_histo(const image3d<V>& histo);
+
# ifndef MLN_INCLUDE_ONLY
/// \brief Allow the visualization of 3d histogram.
@@ -86,6 +96,340 @@ namespace mln
return accu::image::to_result(histo_accu);
}
+ template <unsigned direction>
+ image2d<value::int_u8>
+ project2_histo(const image3d<unsigned>& histo)
+ {
+ image2d<value::int_u8> result;
+
+ if (0 == direction) // blue
+ {
+ image2d<value::int_u8> arg_max(histo.ncols(), histo.nslices());
+
+ for (unsigned j = 0; j < histo.ncols(); ++j)
+ for (unsigned i = 0; i < histo.nslices(); ++i)
+ {
+ unsigned max = 0; // minimum as possible
+ signed pos = -1;
+
+ for (unsigned k = 0; k < histo.nrows(); ++k)
+ {
+ if (max <= opt::at(histo,i,j,k))
+ {
+ max = opt::at(histo,i,j,k);
+ pos = k;
+ }
+ }
+
+ opt::at(arg_max,i,j) = pos;
+ }
+
+ result = arg_max;
+ }
+ else if (1 == direction) // red
+ {
+ image2d<value::int_u8> arg_max(histo.nrows(), histo.nslices());
+
+ for (unsigned j = 0; j < histo.nslices(); ++j)
+ for (unsigned i = 0; i < histo.nrows(); ++i)
+ {
+ unsigned max = 0; // minimum as possible
+ signed pos = -1;
+
+ for (unsigned k = 0; k < histo.ncols(); ++k)
+ {
+ if (max <= opt::at(histo,i,j,k))
+ {
+ max = opt::at(histo,i,j,k);
+ pos = k;
+ }
+ }
+
+ opt::at(arg_max,i,j) = pos;
+ }
+
+ result = arg_max;
+ }
+ else // 2 == direction // green
+ {
+ image2d<value::int_u8> arg_max(histo.nrows(), histo.ncols());
+
+ for (unsigned j = 0; j < histo.ncols(); ++j)
+ for (unsigned i = 0; i < histo.nrows(); ++i)
+ {
+ unsigned max = 0; // minimum as possible
+ signed pos = -1;
+
+ for (unsigned k = 0; k < histo.nslices(); ++k)
+ {
+ if (max <= opt::at(histo,i,j,k))
+ {
+ max = opt::at(histo,i,j,k);
+ pos = k;
+ }
+ }
+
+ opt::at(arg_max,i,j) = pos;
+ }
+
+ result = arg_max;
+ }
+
+ return result;
+ }
+
+ template <unsigned direction>
+ image2d<value::label_8>
+ project2_histo(const image3d<unsigned>& histo,
+ const image3d<value::label_8>& label)
+ {
+ image2d<value::label_8> result;
+
+ if (0 == direction) // blue
+ {
+ image2d<value::label_8> arg_max(histo.ncols(), histo.nslices());
+
+ for (unsigned j = 0; j < histo.ncols(); ++j)
+ for (unsigned i = 0; i < histo.nslices(); ++i)
+ {
+ unsigned max = 0; // minimum as possible
+ signed pos = -1;
+
+ for (unsigned k = 0; k < histo.nrows(); ++k)
+ {
+ if (max <= opt::at(histo,i,j,k))
+ {
+ max = opt::at(histo,i,j,k);
+ pos = k;
+ }
+ }
+
+ opt::at(arg_max,i,j) = opt::at(label,i,j,pos);
+ }
+
+ result = arg_max;
+ }
+ else if (1 == direction) // red
+ {
+ image2d<value::label_8> arg_max(histo.nrows(), histo.nslices());
+
+ for (unsigned j = 0; j < histo.nslices(); ++j)
+ for (unsigned i = 0; i < histo.nrows(); ++i)
+ {
+ unsigned max = 0; // minimum as possible
+ signed pos = -1;
+
+ for (unsigned k = 0; k < histo.ncols(); ++k)
+ {
+ if (max <= opt::at(histo,i,j,k))
+ {
+ max = opt::at(histo,i,j,k);
+ pos = k;
+ }
+ }
+
+ opt::at(arg_max,i,j) = opt::at(label,pos,i,j);
+ }
+
+ result = arg_max;
+ }
+ else // 2 == direction // green
+ {
+ image2d<value::label_8> arg_max(histo.nrows(), histo.ncols());
+
+ for (unsigned j = 0; j < histo.ncols(); ++j)
+ for (unsigned i = 0; i < histo.nrows(); ++i)
+ {
+ unsigned max = 0; // minimum as possible
+ signed pos = -1;
+
+ for (unsigned k = 0; k < histo.nslices(); ++k)
+ {
+ if (max <= opt::at(histo,i,j,k))
+ {
+ max = opt::at(histo,i,j,k);
+ pos = k;
+ }
+ }
+
+ opt::at(arg_max,i,j) = opt::at(label,i,pos,j);
+ }
+
+ result = arg_max;
+ }
+
+ return result;
+ }
+
+
+ // FIXME ... determine the color of each class.
+ template <unsigned direction>
+ image2d<value::rgb8>
+ project3_histo(const image3d<unsigned>& histo,
+ const image3d<value::label_8>& label)
+ {
+ image2d<value::rgb8> result;
+
+ if (0 == direction) // blue
+ {
+ image2d<value::rgb8> arg_max(histo.ncols(), histo.nslices());
+
+ for (unsigned j = 0; j < histo.ncols(); ++j)
+ for (unsigned i = 0; i < histo.nslices(); ++i)
+ {
+ unsigned max = 0; // minimum as possible
+ signed pos = -1;
+
+ for (unsigned k = 0; k < histo.nrows(); ++k)
+ {
+ if (max <= opt::at(histo,i,j,k))
+ {
+ max = opt::at(histo,i,j,k);
+ pos = k;
+ }
+ }
+
+ opt::at(arg_max,i,j) = value::rgb8(i,j,pos);
+ }
+
+ result = arg_max;
+ }
+ else if (1 == direction) // red
+ {
+ image2d<value::rgb8> arg_max(histo.nrows(), histo.nslices());
+
+ for (unsigned j = 0; j < histo.nslices(); ++j)
+ for (unsigned i = 0; i < histo.nrows(); ++i)
+ {
+ unsigned max = 0; // minimum as possible
+ signed pos = -1;
+
+ for (unsigned k = 0; k < histo.ncols(); ++k)
+ {
+ if (max <= opt::at(histo,i,j,k))
+ {
+ max = opt::at(histo,i,j,k);
+ pos = k;
+ }
+ }
+
+ opt::at(arg_max,i,j) = value::rgb8(pos,i,j);
+ }
+
+ result = arg_max;
+ }
+ else // 2 == direction // green
+ {
+ image2d<value::rgb8> arg_max(histo.nrows(), histo.ncols());
+
+ for (unsigned j = 0; j < histo.ncols(); ++j)
+ for (unsigned i = 0; i < histo.nrows(); ++i)
+ {
+ unsigned max = 0; // minimum as possible
+ signed pos = -1;
+
+ for (unsigned k = 0; k < histo.nslices(); ++k)
+ {
+ if (max <= opt::at(histo,i,j,k))
+ {
+ max = opt::at(histo,i,j,k);
+ pos = k;
+ }
+ }
+
+ // FIXME ... how to fix the n of rgb
+ opt::at(arg_max,i,j) = value::rgb8(i,pos,j);
+ }
+
+ result = arg_max;
+ }
+
+ return result;
+ }
+
+ template <unsigned direction>
+ image2d<value::rgb8>
+ project3_histo(const image3d<unsigned>& histo)
+ {
+ image2d<value::rgb8> result;
+
+ if (0 == direction) // blue
+ {
+ image2d<value::rgb8> arg_max(histo.ncols(), histo.nslices());
+
+ for (unsigned j = 0; j < histo.ncols(); ++j)
+ for (unsigned i = 0; i < histo.nslices(); ++i)
+ {
+ unsigned max = 0; // minimum as possible
+ signed pos = -1;
+
+ for (unsigned k = 0; k < histo.nrows(); ++k)
+ {
+ if (max <= opt::at(histo,i,j,k))
+ {
+ max = opt::at(histo,i,j,k);
+ pos = k;
+ }
+ }
+
+ opt::at(arg_max,i,j) = value::rgb8(i,j,pos);
+ }
+
+ result = arg_max;
+ }
+ else if (1 == direction) // red
+ {
+ image2d<value::rgb8> arg_max(histo.nrows(), histo.nslices());
+
+ for (unsigned j = 0; j < histo.nslices(); ++j)
+ for (unsigned i = 0; i < histo.nrows(); ++i)
+ {
+ unsigned max = 0; // minimum as possible
+ signed pos = -1;
+
+ for (unsigned k = 0; k < histo.ncols(); ++k)
+ {
+ if (max <= opt::at(histo,i,j,k))
+ {
+ max = opt::at(histo,i,j,k);
+ pos = k;
+ }
+ }
+
+ opt::at(arg_max,i,j) = value::rgb8(pos,i,j);
+ }
+
+ result = arg_max;
+ }
+ else // 2 == direction // green
+ {
+ image2d<value::rgb8> arg_max(histo.nrows(), histo.ncols());
+
+ for (unsigned j = 0; j < histo.ncols(); ++j)
+ for (unsigned i = 0; i < histo.nrows(); ++i)
+ {
+ unsigned max = 0; // minimum as possible
+ signed pos = -1;
+
+ for (unsigned k = 0; k < histo.nslices(); ++k)
+ {
+ if (max <= opt::at(histo,i,j,k))
+ {
+ max = opt::at(histo,i,j,k);
+ pos = k;
+ }
+ }
+
+ // FIXME ... how to fix the n of rgb
+ opt::at(arg_max,i,j) = value::rgb8(i,pos,j);
+ }
+
+ result = arg_max;
+ }
+
+ return result;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
--
1.5.6.5