* green/exp/annoting/nb_color: New experimentation directory.
* green/exp/annoting/nb_color/Makefile.am: New Makefile.
* green/exp/annoting/nb_color/nb_color.cc: New experementation.
* green/exp/annoting/stddev_color: New experimentation directory.
* green/exp/annoting/stddev_color/Makefile.am: New Makefile.
* green/exp/annoting/stddev_color/stddev_color.cc: New experimentation.
---
.../nb_color}/Makefile.am | 1 +
.../green/exp/annoting/nb_color/nb_color.cc | 131 ++++++++++++++++++++
.../stddev_color}/Makefile.am | 1 +
.../annoting/stddev_color/stddev_color.cc | 73 ++++++++----
4 files changed, 184 insertions(+), 22 deletions(-)
copy milena/sandbox/green/exp/{labeling/regional_maxima =>
annoting/nb_color}/Makefile.am (99%)
create mode 100644 milena/sandbox/green/exp/annoting/nb_color/nb_color.cc
copy milena/sandbox/green/exp/{labeling/regional_maxima =>
annoting/stddev_color}/Makefile.am (99%)
copy milena/sandbox/green/{demo => exp}/annoting/stddev_color/stddev_color.cc (63%)
diff --git a/milena/sandbox/green/exp/labeling/regional_maxima/Makefile.am
b/milena/sandbox/green/exp/annoting/nb_color/Makefile.am
similarity index 99%
copy from milena/sandbox/green/exp/labeling/regional_maxima/Makefile.am
copy to milena/sandbox/green/exp/annoting/nb_color/Makefile.am
index ab76e18..8e204c6 100644
--- a/milena/sandbox/green/exp/labeling/regional_maxima/Makefile.am
+++ b/milena/sandbox/green/exp/annoting/nb_color/Makefile.am
@@ -6,6 +6,7 @@
# TOOLS #
#########
+LOADLIBES= -lboost_filesystem
INCLUDES= -I$(HOME)/svn/oln/trunk/milena/sandbox/green
#CXXFLAGS= -ggdb -O0 -Wall -W -pedantic -ansi -pipe $(INCLUDES)
#CXXFLAGS= -DNDEBUG -O1 -Wall -W -pedantic -ansi -pipe $(INCLUDES)
diff --git a/milena/sandbox/green/exp/annoting/nb_color/nb_color.cc
b/milena/sandbox/green/exp/annoting/nb_color/nb_color.cc
new file mode 100644
index 0000000..6dd9c26
--- /dev/null
+++ b/milena/sandbox/green/exp/annoting/nb_color/nb_color.cc
@@ -0,0 +1,131 @@
+// COUNTING THE IMAGE COLORS
+
+#include <iostream>
+#include <sstream>
+#include <boost/filesystem.hpp>
+
+#include <mln/img_path.hh>
+
+#include <mln/accu/math/count.hh>
+#include <mln/accu/stat/histo3d_rgb.hh>
+
+#include <mln/binarization/threshold.hh>
+
+#include <mln/core/alias/neighb3d.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/image/dmorph/image_if.hh>
+
+#include <mln/data/compute.hh>
+#include <mln/data/transform.hh>
+
+#include <mln/fun/v2v/rgb8_to_rgbn.hh>
+
+// #include <mln/morpho/opening/volume.hh>
+
+#include <mln/io/ppm/load.hh>
+
+#include <mln/pw/value.hh>
+#include <mln/pw/cst.hh>
+
+#include <mln/util/timer.hh>
+
+#include <mln/value/rgb8.hh>
+//#include <mln/value/rgb.hh>
+
+// FIXME
+// Pour la classification des images, pour gagner du temps,
+// peut être peut-on réduire toutes les images à 100x100 avec 2^5 couleurs ?
+
+// n < 8, n is the degree of quantification
+template <unsigned n>
+unsigned count_image_color(const std::string& image)
+{
+ typedef mln::value::rgb8 t_rgb8;
+ typedef mln::value::rgb<n> t_rgbn;
+ typedef mln::image2d<t_rgb8> t_image2d_rgb8;
+ typedef mln::image2d<t_rgbn> t_image2d_rgbn;
+ typedef mln::image3d<unsigned> t_histo3d;
+ typedef mln::image3d<bool> t_histo3d_bool;
+ typedef mln::fun::v2v::rgb8_to_rgbn<n> t_rgb8_to_rgbn;
+ typedef mln::accu::meta::stat::histo3d_rgb t_histo3d_fun;
+ typedef mln::accu::meta::math::count t_count_fun;
+
+ t_image2d_rgb8 input_rgb8;
+ t_image2d_rgbn input_rgbn;
+ t_image2d_rgbn output_rgbn;
+ t_histo3d histo;
+// t_histo3d opened;
+ t_histo3d_bool filtered;
+
+ mln::io::ppm::load(input_rgb8, image.c_str());
+
+ unsigned nb_pixel = input_rgb8.ncols() * input_rgb8.nrows();
+ unsigned min_volume = (unsigned)(nb_pixel * 0.0001);
+ unsigned nb_color = 0;
+
+// input_rgbn = mln::data::transform(input_rgb8, t_rgb8_to_rgbn());
+ histo = mln::data::compute(t_histo3d_fun(), input_rgb8);
+// opened = mln::morpho::opening::volume(histo, mln::c6(), min_volume);
+ filtered = mln::binarization::threshold(histo, min_volume);
+ nb_color = mln::data::compute(t_count_fun(),
+ (filtered|(mln::pw::value(filtered)!=0)).rw());
+
+ return nb_color;
+}
+
+int main()
+{
+ typedef boost::filesystem::path t_path;
+ //typedef boost::filesystem::initial_path<t_path()> t_init_path;
+ typedef boost::filesystem::directory_iterator t_iter_path;
+
+ t_path full_path[] = {t_path(ANNOTING_BILL_IMG_PATH),
+ t_path(ANNOTING_FAX_IMG_PATH),
+ t_path(ANNOTING_HANDWRITTEN_IMG_PATH),
+ t_path(ANNOTING_LOGO_IMG_PATH),
+ t_path(ANNOTING_MAP_IMG_PATH),
+ t_path(ANNOTING_PHOTO_IMG_PATH),
+ t_path(ANNOTING_SCREENSHOT_IMG_PATH),
+ t_path(ANNOTING_SLIDE_IMG_PATH),
+ t_path(ANNOTING_TYPED_IMG_PATH)};
+
+ for (int i = 0; i < 9; ++i)
+ {
+ std::cerr << "entering " << full_path[i] << std::endl;
+ std::cout << "entering " << full_path[i] << std::endl;
+
+ if (boost::filesystem::exists(full_path[i]) &&
+ boost::filesystem::is_directory(full_path[i]))
+ {
+ boost::filesystem::system_complete(full_path[i]);
+ const t_iter_path end_iter;
+ unsigned count = 0;
+ unsigned sum1 = 0;
+ unsigned sum2 = 0;
+
+ for (t_iter_path dir_iter(full_path[i]); end_iter != dir_iter; ++dir_iter)
+ {
+ unsigned val = count_image_color<8>(dir_iter->path().string());
+
+ ++count;
+ sum1 += val;
+ sum2 += val*val;
+
+ std::cout << dir_iter->path().string() << " => " <<
val << std::endl;
+ // FIXME NB COULEURS BRUTES
+ // FIXME NB DE COULEURS
+ // FIXME LISTE DES COULEURS
+ // IMPORTANCES
+ }
+
+ float mean = sum1 / count;
+ float var = ((float)sum2 / count) - (mean * mean);
+
+ std::cout << "mean : " << mean << std::endl;
+ std::cout << "var : " << var << std::endl;
+ }
+ }
+
+ return 0;
+}
diff --git a/milena/sandbox/green/exp/labeling/regional_maxima/Makefile.am
b/milena/sandbox/green/exp/annoting/stddev_color/Makefile.am
similarity index 99%
copy from milena/sandbox/green/exp/labeling/regional_maxima/Makefile.am
copy to milena/sandbox/green/exp/annoting/stddev_color/Makefile.am
index ab76e18..8e204c6 100644
--- a/milena/sandbox/green/exp/labeling/regional_maxima/Makefile.am
+++ b/milena/sandbox/green/exp/annoting/stddev_color/Makefile.am
@@ -6,6 +6,7 @@
# TOOLS #
#########
+LOADLIBES= -lboost_filesystem
INCLUDES= -I$(HOME)/svn/oln/trunk/milena/sandbox/green
#CXXFLAGS= -ggdb -O0 -Wall -W -pedantic -ansi -pipe $(INCLUDES)
#CXXFLAGS= -DNDEBUG -O1 -Wall -W -pedantic -ansi -pipe $(INCLUDES)
diff --git a/milena/sandbox/green/demo/annoting/stddev_color/stddev_color.cc
b/milena/sandbox/green/exp/annoting/stddev_color/stddev_color.cc
similarity index 63%
copy from milena/sandbox/green/demo/annoting/stddev_color/stddev_color.cc
copy to milena/sandbox/green/exp/annoting/stddev_color/stddev_color.cc
index 0782e9c..652b8a8 100644
--- a/milena/sandbox/green/demo/annoting/stddev_color/stddev_color.cc
+++ b/milena/sandbox/green/exp/annoting/stddev_color/stddev_color.cc
@@ -2,6 +2,7 @@
#include <iostream>
#include <sstream>
+#include <boost/filesystem.hpp>
#include <mln/img_path.hh>
@@ -11,9 +12,6 @@
#include <mln/core/macros.hh>
#include <mln/core/image/image1d.hh>
#include <mln/core/image/image2d.hh>
-#include <mln/core/image/image3d.hh>
-
-#include <mln/debug/println.hh>
#include <mln/data/compute.hh>
#include <mln/data/fill.hh>
@@ -22,8 +20,6 @@
#include <mln/fun/v2v/rgb8_to_int_u8.hh>
#include <mln/io/ppm/load.hh>
-#include <mln/io/pgm/save.hh>
-#include <mln/io/plot/save_image_sh.hh>
#include <mln/math/sqr.hh>
@@ -43,7 +39,7 @@ float r(short p, unsigned histo_p, short x, unsigned histo_x)
return result;
}
-unsigned stddev_color(const std::string& image)
+float stddev_color(const std::string& image)
{
typedef mln::point1d t_point1d;
typedef mln::value::rgb8 t_rgb8;
@@ -64,10 +60,6 @@ unsigned stddev_color(const std::string& image)
input_int_u8 = mln::data::transform(input_rgb8, t_rgb8_to_int_u8());
histo = mln::data::compute(t_histo1d_fun(), input_int_u8);
- mln::io::pgm::save(input_int_u8, "tmp.pgm");
- mln::io::plot::save_image_sh(histo, "histo.sh");
- mln::debug::println(histo);
-
// Find the peak of the histogram
unsigned v_max = mln::opt::at(histo, 0);
short p_max = 0;
@@ -102,23 +94,60 @@ unsigned stddev_color(const std::string& image)
stddev = (250 < p_max)? stddev_low : (5 > p_max)? stddev_up :
(stddev_low + stddev_up)/2;
- std::cout << "max_site : " << p_max << std::endl;
- std::cout << "h(max_site) : " << v_max << std::endl;
- std::cout << "stddev_up : " << stddev_up << std::endl;
- std::cout << "stddev_low : " << stddev_low << std::endl;
- std::cout << "stddev : " << stddev << std::endl;
-
- return 0;
+ return stddev;
}
-
int main()
{
-// unsigned val = stdev_color(ANNOTING_PHOTO_IMG_PATH "/photo01.ppm");
- unsigned val = stddev_color(ANNOTING_LOGO_IMG_PATH "/logo06.ppm");
+ typedef boost::filesystem::path t_path;
+ typedef boost::filesystem::directory_iterator t_iter_path;
+
+ t_path full_path[] = {t_path(ANNOTING_BILL_IMG_PATH),
+ t_path(ANNOTING_FAX_IMG_PATH),
+ t_path(ANNOTING_HANDWRITTEN_IMG_PATH),
+ t_path(ANNOTING_LOGO_IMG_PATH),
+ t_path(ANNOTING_MAP_IMG_PATH),
+ t_path(ANNOTING_PHOTO_IMG_PATH),
+ t_path(ANNOTING_SCREENSHOT_IMG_PATH),
+ t_path(ANNOTING_SLIDE_IMG_PATH),
+ t_path(ANNOTING_TYPED_IMG_PATH)};
+
+ for (int i = 0; i < 9; ++i)
+ {
+ std::cerr << "entering " << full_path[i] << std::endl;
+ std::cout << "entering " << full_path[i] << std::endl;
-// std::cout << "nb color : " << val << std::endl;
+ if (boost::filesystem::exists(full_path[i]) &&
+ boost::filesystem::is_directory(full_path[i]))
+ {
+ boost::filesystem::system_complete(full_path[i]);
+ const t_iter_path end_iter;
+ float count = 0;
+ float sum1 = 0;
+ float sum2 = 0;
+
+ for (t_iter_path dir_iter(full_path[i]); end_iter != dir_iter; ++dir_iter)
+ {
+ float val = stddev_color(dir_iter->path().string());
+
+ ++count;
+ sum1 += val;
+ sum2 += val*val;
+
+ std::cout << dir_iter->path().string() << " => " <<
val << std::endl;
+ // FIXME NB COULEURS BRUTES
+ // FIXME NB DE COULEURS
+ // FIXME LISTE DES COULEURS
+ // IMPORTANCES
+ }
+
+ float mean = sum1 / count;
+ float var = ((float)sum2 / count) - (mean * mean);
+
+ std::cout << "mean : " << mean << std::endl;
+ std::cout << "var : " << var << std::endl;
+ }
+ }
return 0;
}
-
--
1.5.6.5