last-svn-commit-40-gb0279f5 Import files from milena/sandbox/green.

* mln/accu/stat/histo1d.hh: New header file. * mln/accu/stat/histo2d.hh: New header file. * mln/accu/stat/histo3d_hsl.hh: New header file. * mln/accu/stat/histo3d_rgb.hh: New header file. * mln/clustering/k_mean.hh: New header file. * mln/clustering/kmean1d.hh: New header file. * mln/clustering/kmean2d.hh: New header file. * mln/clustering/kmean3d.hh: New header file. * mln/clustering/kmean_rgb.hh: New header file. * mln/display/display_histo.hh: New header file. * mln/display/project_histo.hh: New header file. * mln/fun/p2b/achromatic.hh: New header file. * mln/fun/p2b/component_equals.hh: New header file. * mln/fun/v2v/achromatism.hh: New header file. * mln/fun/v2v/hue_concentration.hh: New header file. * mln/fun/v2v/int_u16_to_int_u14.hh: New header file. * mln/fun/v2v/int_u16_to_int_u14.hh: New header file. * mln/fun/v2v/log.hh: New header file. * mln/fun/v2v/rg_to_rgb.hh: New header file. * mln/fun/v2v/rgb8_to_int_u8: New header file. * mln/fun/v2v/rgb_to_achromastism_map.hh: New header file. * mln/fun/v2v/rgb_to_hsv.hh: New header file. * mln/fun/v2v/rgb_to_hue_map.hh: New header file. * mln/fun/v2v/rgb_to_saturation_map.hh: New header file. * mln/fun/v2v/rgb_to_value_map.hh: New header file. * mln/img_path.hh: New header file. * mln/io/plot/save_image_sh.hh: New header file. * mln/math/cell.hh: New header file. * mln/math/floor.hh: New header file. * tests/accu/stat/histo1d/Makefile.am: New makefile. * tests/accu/stat/histo1d/histo1d.cc: New source. * tests/accu/stat/histo2d/Makefile.am: New makefile. * tests/accu/stat/histo2d/histo2d.cc: New source. --- scribo/sandbox/green/ChangeLog | 47 + scribo/sandbox/green/README | 223 ++++- scribo/sandbox/green/mln/accu/stat/histo1d.hh | 340 +++++++ scribo/sandbox/green/mln/accu/stat/histo2d.hh | 358 +++++++ .../sandbox/green/mln/accu/stat/histo3d_hsl.hh | 0 .../sandbox/green/mln/accu/stat/histo3d_rgb.hh | 0 .../sandbox/green/mln/clustering/k_mean.hh | 0 .../sandbox/green/mln/clustering/kmean1d.hh | 0 .../sandbox/green/mln/clustering/kmean2d.hh | 0 .../sandbox/green/mln/clustering/kmean3d.hh | 0 .../sandbox/green/mln/clustering/kmean_rgb.hh | 0 .../sandbox/green/mln/display/display_histo.hh | 0 .../sandbox/green/mln/display/project_histo.hh | 0 .../sandbox/green/mln/fun/p2b/achromatic.hh | 0 .../sandbox/green/mln/fun/p2b/component_equals.hh | 0 .../sandbox/green/mln/fun/v2v/achromatism.hh | 0 .../sandbox/green/mln/fun/v2v/hue_concentration.hh | 0 .../green/mln/fun/v2v/int_u16_to_int_u14.hh | 0 .../sandbox/green/mln/fun/v2v/log.hh | 0 .../sandbox/green/mln/fun/v2v/rg_to_rgb.hh | 0 .../sandbox/green/mln/fun/v2v/rgb8_to_int_u8.hh | 0 .../sandbox/green/mln/fun/v2v/rgb8_to_rgbn.hh | 0 .../green/mln/fun/v2v/rgb_to_achromatism_map.hh | 0 .../sandbox/green/mln/fun/v2v/rgb_to_hsv.hh | 0 .../sandbox/green/mln/fun/v2v/rgb_to_hue_map.hh | 0 scribo/sandbox/green/mln/fun/v2v/rgb_to_rg.hh | 111 ++ .../green/mln/fun/v2v/rgb_to_saturation_map.hh | 0 .../sandbox/green/mln/fun/v2v/rgb_to_value_map.hh | 0 {milena => scribo}/sandbox/green/mln/img_path.hh | 0 scribo/sandbox/green/mln/io/plot/save_image_sh.hh | 1056 ++++++++++++++++++++ {milena => scribo}/sandbox/green/mln/math/ceil.hh | 0 {milena => scribo}/sandbox/green/mln/math/floor.hh | 0 {milena => scribo}/sandbox/green/mln/value/hsv.hh | 0 scribo/sandbox/green/mln/value/rg.hh | 175 ++++ .../green/tests/accu/stat/histo1d/Makefile.am | 153 +++ .../green/tests/accu/stat/histo1d/histo1d.cc | 21 + .../green/use/accu/stat/histo1d/Makefile.am | 153 +++ .../sandbox/green/use/accu/stat/histo1d/histo1d.cc | 24 + .../green/use/accu/stat/histo2d/Makefile.am | 153 +++ .../sandbox/green/use/accu/stat/histo2d/histo2d.cc | 33 + 40 files changed, 2829 insertions(+), 18 deletions(-) create mode 100644 scribo/sandbox/green/mln/accu/stat/histo1d.hh create mode 100644 scribo/sandbox/green/mln/accu/stat/histo2d.hh copy {milena => scribo}/sandbox/green/mln/accu/stat/histo3d_hsl.hh (100%) copy {milena => scribo}/sandbox/green/mln/accu/stat/histo3d_rgb.hh (100%) copy {milena => scribo}/sandbox/green/mln/clustering/k_mean.hh (100%) copy {milena => scribo}/sandbox/green/mln/clustering/kmean1d.hh (100%) copy {milena => scribo}/sandbox/green/mln/clustering/kmean2d.hh (100%) copy {milena => scribo}/sandbox/green/mln/clustering/kmean3d.hh (100%) copy {milena => scribo}/sandbox/green/mln/clustering/kmean_rgb.hh (100%) copy {milena => scribo}/sandbox/green/mln/display/display_histo.hh (100%) copy {milena => scribo}/sandbox/green/mln/display/project_histo.hh (100%) copy {milena => scribo}/sandbox/green/mln/fun/p2b/achromatic.hh (100%) copy {milena => scribo}/sandbox/green/mln/fun/p2b/component_equals.hh (100%) copy {milena => scribo}/sandbox/green/mln/fun/v2v/achromatism.hh (100%) copy {milena => scribo}/sandbox/green/mln/fun/v2v/hue_concentration.hh (100%) copy {milena => scribo}/sandbox/green/mln/fun/v2v/int_u16_to_int_u14.hh (100%) copy {milena => scribo}/sandbox/green/mln/fun/v2v/log.hh (100%) copy {milena => scribo}/sandbox/green/mln/fun/v2v/rg_to_rgb.hh (100%) copy {milena => scribo}/sandbox/green/mln/fun/v2v/rgb8_to_int_u8.hh (100%) copy {milena => scribo}/sandbox/green/mln/fun/v2v/rgb8_to_rgbn.hh (100%) copy {milena => scribo}/sandbox/green/mln/fun/v2v/rgb_to_achromatism_map.hh (100%) copy {milena => scribo}/sandbox/green/mln/fun/v2v/rgb_to_hsv.hh (100%) copy {milena => scribo}/sandbox/green/mln/fun/v2v/rgb_to_hue_map.hh (100%) create mode 100644 scribo/sandbox/green/mln/fun/v2v/rgb_to_rg.hh copy {milena => scribo}/sandbox/green/mln/fun/v2v/rgb_to_saturation_map.hh (100%) copy {milena => scribo}/sandbox/green/mln/fun/v2v/rgb_to_value_map.hh (100%) copy {milena => scribo}/sandbox/green/mln/img_path.hh (100%) create mode 100644 scribo/sandbox/green/mln/io/plot/save_image_sh.hh copy {milena => scribo}/sandbox/green/mln/math/ceil.hh (100%) copy {milena => scribo}/sandbox/green/mln/math/floor.hh (100%) copy {milena => scribo}/sandbox/green/mln/value/hsv.hh (100%) create mode 100644 scribo/sandbox/green/mln/value/rg.hh create mode 100644 scribo/sandbox/green/tests/accu/stat/histo1d/Makefile.am create mode 100644 scribo/sandbox/green/tests/accu/stat/histo1d/histo1d.cc create mode 100644 scribo/sandbox/green/use/accu/stat/histo1d/Makefile.am create mode 100644 scribo/sandbox/green/use/accu/stat/histo1d/histo1d.cc create mode 100644 scribo/sandbox/green/use/accu/stat/histo2d/Makefile.am create mode 100644 scribo/sandbox/green/use/accu/stat/histo2d/histo2d.cc diff --git a/scribo/sandbox/green/ChangeLog b/scribo/sandbox/green/ChangeLog index ed399c5..6a3c8fa 100644 --- a/scribo/sandbox/green/ChangeLog +++ b/scribo/sandbox/green/ChangeLog @@ -1,3 +1,50 @@ +2010-06-24 Yann Jacquelet <jacquelet@lrde.epita.fr> + + Import files from milena/sandbox/green. + + * mln/accu/stat/histo1d.hh: New header file. + * mln/accu/stat/histo2d.hh: New header file. + * mln/accu/stat/histo3d_hsl.hh: New header file. + * mln/accu/stat/histo3d_rgb.hh: New header file. + * mln/clustering/k_mean.hh: New header file. + * mln/clustering/kmean1d.hh: New header file. + * mln/clustering/kmean2d.hh: New header file. + * mln/clustering/kmean3d.hh: New header file. + * mln/clustering/kmean_rgb.hh: New header file. + * mln/display/display_histo.hh: New header file. + * mln/display/project_histo.hh: New header file. + * mln/fun/p2b/achromatic.hh: New header file. + * mln/fun/p2b/component_equals.hh: New header file. + * mln/fun/v2v/achromatism.hh: New header file. + * mln/fun/v2v/hue_concentration.hh: New header file. + * mln/fun/v2v/int_u16_to_int_u14.hh: New header file. + * mln/fun/v2v/int_u16_to_int_u14.hh: New header file. + * mln/fun/v2v/log.hh: New header file. + * mln/fun/v2v/rg_to_rgb.hh: New header file. + * mln/fun/v2v/rgb8_to_int_u8: New header file. + * mln/fun/v2v/rgb_to_achromastism_map.hh: New header file. + * mln/fun/v2v/rgb_to_hsv.hh: New header file. + * mln/fun/v2v/rgb_to_hue_map.hh: New header file. + * mln/fun/v2v/rgb_to_saturation_map.hh: New header file. + * mln/fun/v2v/rgb_to_value_map.hh: New header file. + * mln/img_path.hh: New header file. + * mln/io/plot/save_image_sh.hh: New header file. + * mln/math/cell.hh: New header file. + * mln/math/floor.hh: New header file. + * tests/accu/stat/histo1d/Makefile.am: New makefile. + * tests/accu/stat/histo1d/histo1d.cc: New source. + * tests/accu/stat/histo2d/Makefile.am: New makefile. + * tests/accu/stat/histo2d/histo2d.cc: New source. + +2010-06-21 Yann Jacquelet <jacquelet@lrde.epita.fr> + + Save histogram library. + + * mln/accu/histo/histo1d.hh: New header file. + * mln/accu/histo/histo2d.hh: New header file. + * mln/accu/histo/histo3d_rgb.hh: New header file. + * mln/accu/histo/histo3d_hsl.hh: New header file. + 2010-06-21 Yann Jacquelet <jacquelet@lrde.epita.fr> Simple integration test. diff --git a/scribo/sandbox/green/README b/scribo/sandbox/green/README index 4eb71b7..3efe50d 100644 --- a/scribo/sandbox/green/README +++ b/scribo/sandbox/green/README @@ -1,32 +1,219 @@ -Le travail est classé dans deux répertoires ok et ko. -Le répertoire ok correspond aux sources qui ont été reprises et retestées. -Le répertoire ko correspond aux sources qui ont été juste transférées. +I ARBORESCENCE +-------------- -La première brique logicielle importante sur laquelle s'appuie mes travaux est -la création d'histogrammes sous forme d'image. +bench ==> Comparaison d'algorithmes d'un point de vue temps d'exécution. +bug ==> Bug rencontrés dans milena et archivés sous forme de programme. +build ==> Répertoire d'exécution, non sauvé dans git. +demo ==> Première version d'un algorithme pour voir son comportement. +doc ==> Documentation tex ou code minimal pour de petits exemples. +exp ==> Version avancée des algorithmes pour traitées les bases de données. +mln ==> Partie mise en librairie milena des différents travaux. +tests ==> Tests unitaires sur certains algorithmes. +tools ==> Découpage de certains algorithmes pour mieux les tester séparément. +use ==> Test de compilation, code minimal pour compiler un élément. +II COMPILATION +-------------- -CREATION DES HISTOGRAMMES -------------------------- +L'unité minimale de code choisie est le répertoire. +Donc aller dans le répertoire qui nous interesse, +par exemple, green/demo/annotating/hsv et lancé le make -ko/mln/accu/stat/histo1d.hh: histogramme image valeur scalaire. -ko/mln/accu/stat/histo2d.hh: histogramme image valeur vectorielle 2d. -ko/mln/accu/stat/histo3d_hsl.hh: histogramme image valeur vectorielle 3d (HSL). -ko/mln/accu/stat/histo3d_rgb.hh: histogramme image valeur vectorielle 3d (RGB). +#:~/git/olena/scribo/sandbox/green$cd demo/annotating/hsv +#:~/git/olena/scribo/sandbox/green/demo/annotating/hsv$ make -f Makefile.am +Cette opération créé dans build le répertoire de compilation +green/build/demo/annotating/hsv. Dans ce répertoire aura été copié un +Makefile et tous les fichiers qui ne sont pas des sources. Par +exemple, des fichiers de calibration comme gaussian.sh (pour vérifier +la mire du filtre de gaussienne) ou de la documentation à la sauvette +sous forme de fichiers textes jetés à la va vite dans le répertoire +pour ne pas perdre l'information recherchée. En l'occurence, ici, il +n'y a rien à copier. Rendons-nous dans le répertoire de compilation et lançons +le makefile. +#:~/git/olena/scribo/sandbox/green/demo/annotating/hsv$ +cd ../../../build/demo/annotating/hsv +#:~/git/olena/scribo/sandbox/green/build/demo/annotating/hsv$ make clean all -ok/mln/accu/histo/histo1d.hh: histogramme image valeur scalaire entière. -ok/mln/accu/histo/histo2d.hh: histogramme image valeur vectorielle 2d entière. -ok/mln/accu/histo/histo3d.hh: histogramme image valeur vectorielle 3d entière. +L'exécutable est généré par le makefile, il porte le nom du +répertoire. Si il y a besoin de mettre à jour le makefile, le faire +dans le répertoire des sources en éditant Makefile.am, puis en +régénérant le Makefile dans le répertoire d'exécution par la commande +make -f Makefile.am depuis le répertoire source. -SAUVEGARDE DES HISTOGRAMMES ---------------------------- +III MAKEFILE +------------ +Les makefiles utilisés sont tous les mêmes avec quelques variables +dont le contenu change dans leur partie en-tête. +Pour chaque répertoire, le makefile doit savoir si le chemin courant +est un répertoire de compilation ou un répertoire de source. Pour les +identifier, il a recours à un pattern qui malheureusemnt fait +intervenir le nom de la branche de développement (bench,demo,bug,exp ...). +SOURCE_PATTERN= green/demo +BUILD__PATTERN= green/build/demo -VISUALISATION DES HISTOGRAMMES ------------------------------- \ No newline at end of file +Si un makefile ne fonctionne pas, il faut vérifier ceci en premier +lieu. Ici, le makefile doit être situé dans la branche démo. + +Autre élément à savoir, la compilation nécessite d'inclure la +librairie milena, ainsi que les développements propres en vu de leur +intégration futur dans milena, ceci est fait par un jeu d'INCLUDES1 +et INCLUDES2. + +INCLUDES1= -I$(HOME)/git/olena/scribo/sandbox/green +INCLUDES2= -I$(HOME)/git/olena/milena +INCLUDES= $(INCLUDES1) $(INCLUDES2) + +Suivant l'allure du compte où l'on exécute les makefiles, il faut +revoir le chemin pour trouver des deux répertoires. + +Enfin, les options de compilations ne sont pas toujours les mêmes. Les +trois lignes possibles sont toutes présentes et seule celle qui est +utilisée n'est pas commentée. Typiquement, dans la branche de +développement démo où les perfomances ne sont pas le problème, on +compilera avec tout le matériel pour utiliser gdb et sans +optimisation. A l'inverse, dans la branche d'expérimentation, où le +code a déjà été testé, on cherche à aller vite car on exécute ce code +sur de nombreuses images. Dans cette optique, pas de débugage, pas de +traçage, optimisation conséquente. + +CXXFLAGS= -ggdb -O0 -Wall -W -pedantic -ansi -pipe $(INCLUDES) +#CXXFLAGS= -DNDEBUG -O1 -Wall -W -pedantic -ansi -pipe $(INCLUDES) +#CXXFLAGS= -DNDEBUG -O3 -Wall -W -pedantic -ansi -pipe $(INCLUDES) + +Une dernière dernière information, dans le cadre des développements +exp, et tools, on utilise la librairie boost soit pour la +virtualisation du filesystem, soit pour le formatage des fichiers text +(réalisation de colonnes, mettre des entiers sur un certain nombre de +caractères). Une ligne de chargement des librairies peut apparaitre donc. + +LOADLIBES= -lboost_filesystem + +On retrouvera les includes suivantes dans les sources: + +#include <boost/format.hpp> +#include <boost/filesystem.hpp> + + +IV CHEMINS DES IMAGES +--------------------- + +Toutes les images ont toujours été locales sur mon ordinateur. La +politique a toujours été d'utiliser un fichier img_path pour coder les +chemins des images. Les chemins étant plutôt long, j'ai toujours eu +tendance à faire en sorte qu'ils soient compilés en dur (sauf pour la +partie développement tools qui est vraiment voué à donner des +exécutables indépendants et génériques). Le fichier mln/img_path.hh +code la position de toutes les images dans mon arborescence. Il faudra +donc veiller à changer tous les chemins pour les adapter au compte +dans lequel on voudra reprendre le code. Dans le code, les références +aux positions des images sont faites via des macros. + +Toutes les images sont située dans git/img. En règle générale, je ne +traite que des images au format .pgm, .pbm et .ppm. Il m'arrive +fréquemment de dumper des images au format .sh (gnuplot shell +image). Pour la branche tools, nous avons utilisé les dumps de milena +comme format de transfert d'un utilitaire à un autre. Les images sont +classées suivant leur provenance. Nous avons tout d'abord la base +OLENA (copie des images de tests milena), la base INIM (très peu +utilisée voire jamais), la base ICDAR (très utilisée, surtout dans +exp), la base AFP (très utilisée dans exp) et les bases ANNOTATING1 et +ANNOTATING2 (pas très utilisées ni l'une, ni l'autre). + +La plus part du temps, sauver les résultats dans le répertoire +d'exécution courant est largement suffisant. Parfois, il est +nécessaire de sauvegarder de grosses quantités d'informations et de +les classer comme dans la branche de développement exp. C'est pour +cela, qu'un certain nombre de macros définissent des endroits pour +sauvegarder les résultats lors d'expérimentation de grande ampleur sur +toute la base ICDAR ou AFP. + + +V GNUPLOT SCRIPT SHELL IMAGE FORMAT +----------------------------------- + +J'abrège le nom du format par gnuplot shell format. En fait, c'est un +format d'image particulier qui a besoin de gnuplot pour être lu. Il +est donc compatible avec aucun viewer si ce n'est gnuplot, mais a la +caractéristique d'afficher tous les points de manière visible. Par +ailleurs, comme il s'agit d'un script gnuplot il permet d'insérer très +facilement une fonction pour visualiser les données autrement (par +exemple, changer d'espace: HSL, HSV). Le fichier tire son nom de la +façon dont il fonctionne. C'est un script shell qui fait un appel à +gnuplot et lui passe le jeu de données directement à partir de ce même +fichier, pas besoin de faire appel à un autre fichier. Une fois +généré, le fichier doit être modifié pour avoir les permissions +d'exécution (chmod 755 gnuplot_shell_file.sh). Comme je trouve le format +extrêmement pratique, il se retrouve preque partout dans mes sources. + + +V MLN +----- + +a) La sauvegarde des images au format gnuplot shell + +* mln/io/plot/save_image_sh.hh: Librairie sauvegarde format gnuplot shell. + +to do ... + + + +b) Les histogrammes + +Un des travaux demandés par théo est la réalisation d'une librairie +d'histogramme permettant de fournir un résultat sous forme d'image. +L'intérêt est ensuite de pouvoir filtrer directement ces histogrammes +par les algorithmes de milena, ou encore d'étudier les valeurs +caractéristiques par d'autres accumulateurs. Les codes réellement +utilisés sont histo1d et histo3d RGB. Tous les autres codes sont très +expérimentaux. Notemment, le code HSL demande de quantifier l'espace +de comptage puisqu'il est décrit sous la forme de triplets de float +(les autres sont inférés). Néanmoins, le code est à conserver car il +contient une séquence d'appels pour les routines permettant de +considérer la dimension de la teinte comme circulaire. + +* mln/accu/stat/histo1d.hh: Accumulateur histogramme image1d. +* use/accu/stat/histo1d: Code minimal utilisant un histogramme 1d. + +* mln/accu/stat/histo2d.hh: Accumulateur histogramme image2d. +* mln/value/rg.hh: Définition du type vectoriel 2d rouge/vert (RG). +* mln/fun/v2v/rgb_to_rg.hh: Transformation de l'espace RGB vers l'espace RG. +* use/accu/stat/histo2d: Code minimal utilisant un histogramme 2d. + + +* mln/accu/stat/histo3d_rgb.hh: Accumulateur histogramme image3d RGB. +* mln/accu/stat/histo3d_hsl.hh: Accumulateur histogramme image3d HSL. + +* use/accu/stat/histo3_rgb: Code minimal utilisant un histogramme 3d RGB. +* use/accu/stat/histo3_hsl: Code minimal utilisant un histogramme 3d HSL. + + + +* tests/accu/stat/histo1d + + + + +* tests/accu/stat/histo2d + + + +* use/accu/stat/histo3d_rgb +* tests/accu/stat/histo3d_rgb + +* use/accu/stat/histo3d_hsl +* tests/accu/stat/histo3d_hsl + + +c) La visualisation des histogrammes 3d + +* demo/accu/stat/histo2d + +* mln/display/dispay_histo.hh +* mln/displayproject_histo.hh diff --git a/scribo/sandbox/green/mln/accu/stat/histo1d.hh b/scribo/sandbox/green/mln/accu/stat/histo1d.hh new file mode 100644 index 0000000..d480cf0 --- /dev/null +++ b/scribo/sandbox/green/mln/accu/stat/histo1d.hh @@ -0,0 +1,340 @@ +// Copyright (C) 2007, 2008, 2009, 2010 EPITA LRDE +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef MLN_ACCU_STAT_HISTO1D_HH +#define MLN_ACCU_STAT_HISTO1D_HH + +/// \file +/// +/// \brief Define a histogram as accumulator which returns an image1d. +/// +/// This source implements the discrete histogram version. It was +/// created for images which the values are derived from integer +/// type. The number of bins is directly infered from the cardinality +/// of the image value. So the int_u8 image has got 256 bins, the +/// int_u<14> image has got 16384 bins. But, this code doesn't work +/// for that quantification because of the coord limitation (signed +/// short, as it is defined in mln/core/def/coord.hh). Take care of +/// the limitation from the result image value. We hard code unsigned, +/// but it sometimes not enought to count data in one bin. That last +/// case has not occured since the beginning of the creation of the type. +/// +/// The following sample is a typical use of the histogram. +/// +/// #include <mln/accu/stat/histo1d.hh> +/// #include <mln/data/compute.hh> +/// #include <mln/core/image/image1d.hh> +/// #include <mln/core/image/image2d.hh> +/// #include <mln/img_path.hh> +/// #include <mln/io/pgm/load.hh> +/// #include <mln/value/int_u8.hh> +/// +/// int main() +/// { +/// typedef mln::value::int_u8 t_int_u8; +/// mln::image2d<t_int_u8> img; +/// mln::image1d<unsigned> histo; +/// +/// mln::io::pgm::load(img, OLENA_IMG_PATH"/lena.pgm"); +/// histo = mln::data::compute(mln::accu::meta::histo::histo1d(), img); +/// +/// return 0; +/// } + + +#include <iostream> + +#include <mln/accu/internal/base.hh> + +#include <mln/arith/plus.hh> + +#include <mln/core/concept/meta_accumulator.hh> +#include <mln/core/image/image1d.hh> +#include <mln/core/macros.hh> + +#include <mln/literal/zero.hh> + +#include <mln/trace/entering.hh> +#include <mln/trace/exiting.hh> + +#include <mln/trait/value/comp.hh> + +#include <mln/value/ops.hh> + +namespace mln +{ + + namespace accu + { + + namespace stat + { + + // Forward declaration + template <typename V> + struct histo1d; + + } // end of namespace mln::accu::stat + + + namespace meta + { + + namespace stat + { + + struct histo1d : public Meta_Accumulator<histo1d> + { + template <typename V> + struct with + { + typedef accu::stat::histo1d<V> ret; + }; + }; + + } // end of namespace mln::accu::meta::stat + + } // end of namespace mln::accu::meta + + } // end of namespace mln::accu + + namespace trait + { + + template <typename V> + struct accumulator_< mln::accu::stat::histo1d<V> > + { + typedef accumulator::has_untake::no has_untake; + typedef accumulator::has_set_value::no has_set_value; + typedef accumulator::has_stop::no has_stop; + typedef accumulator::when_pix::use_v when_pix; + }; + + template <typename V> + struct set_precise_binary_<op::eq, + accu::stat::histo1d<V>, + accu::stat::histo1d<V> > + { + typedef bool ret; + }; + + } // end of namespace mln::trait + + namespace accu + { + + namespace stat + { + + /// \brief Define a histogram as accumulator which returns an image1d. + /// + /// Param V defines the type of the input image value. It is in + /// this space that we count the values. For instance, this + /// histogram works well for image2d<int_u8> or with + /// image2d<int_u<14> >. The number of bins depends directly the + /// values V. For 8 bits there is 256 bins, for 14 bits there + /// is 16384 bins. Note that over quantification works too (up + /// to 14 bits). + /// + /// \ingroup modaccuvalues + + template <typename V> + struct histo1d : + public mln::accu::internal::base<image1d<unsigned>, histo1d<V> > + { + typedef V argument; + typedef image1d<unsigned> result; + typedef result q_result; + + /// Constructors + /// \{ + /// \brief Infer the size of the resulting image1d domain. + /// + /// By evaluating the minimum and the maximum of V, we define the domain + /// of the resulting image1d. + histo1d(); + /// \} + + + /// Manipulators. + /// \{ + /// \brief Initialize the histogram with zero value. + /// + /// This method must be called just before starting the use of the + /// histogram. If it's not, resulting values won't converge to the + /// density. + void init(); + + + /// \brief Update the histogram with the graylevel of the pixel t. + /// \param[in] t a graylevel pixel of type V. + /// + /// The end user shouldn't call this method. In place of it, he can + /// go through the data compute interface. + void take(const argument& t); + + + /// \brief Update the histogram with an other histogram. + /// \param[in] other the other histogram. + /// + /// The end user shouldn't call this method. This is part of + /// data compute interface mechanism. + + void take(const histo1d<V>& other); + /// \} + + /// Accessors. + /// \{ + /// \brief Return the histogram as an image1d. + /// + /// This is the machinery to communicate with data compute interface. + /// The end user should'nt use it. + result to_result() const; + operator result () const; + /// \} + + /// \brief Check whethever this accumulator is able to return a result. + /// + /// Depends if the resulting image1d is valid. We can assume it is quite + /// always the case. + bool is_valid() const; + + protected: + result count_; + }; + + /// \brief Check wethever an histogram is equal to an other one. + /// \param[in] histo1 the first histogram to compare with. + /// \param[in] histo2 the second histogram. + /// + /// The operator compares all the bins from the two histograms. + /// Nobody uses this method unless unitary tests. + + template <typename V> + bool operator==(const histo1d<V>& histo1, const histo1d<V>& histo2); + +#ifndef MLN_INCLUDE_ONLY + + template <typename V> + inline + histo1d<V>::histo1d() + { + trace::entering("mln::accu::stat::histo1d::cstor"); + typedef mln_trait_value_comp(V,0) comp; + typedef point<grid::tick, V> v_point1d; + typedef box<v_point1d> v_box1d; + + // comp keep a trace of the dimension of the theorical image. + // mln_min(comp) --> 0 + // mln_max(comp) --> 2^(n-1) [127 for n=7][255 for n=8] ... + + count_.init_(box1d(point1d(mln_min(comp)), + point1d(mln_max(comp)))); + + // std::cout << "min : " << mln_min(comp) << std::endl; + // std::cout << "max : " << mln_max(comp) << std::endl; + + trace::exiting("mln::accu::stat::histo1d::cstor"); + } + + template <typename V> + inline + void histo1d<V>::init() + { + data::fill(count_, literal::zero); + } + + template <typename V> + inline + void histo1d<V>::take(const argument& t) + { + // Just convert a graylevel value (int_u8 like) to a position for an + // iterator on the resulting image. + ++count_(point1d(t)); + } + + + template <typename V> + inline + void histo1d<V>::take(const histo1d<V>& other) + { + count_ += other.count_; + } + + template <typename V> + inline + typename histo1d<V>::result histo1d<V>::to_result() const + { + return count_; + } + + template <typename V> + inline + histo1d<V>::operator result() const + { + return count_; + } + + template <typename V> + inline + bool histo1d<V>::is_valid() const + { + bool result = count_.is_valid(); + + return result; + } + + template <typename V> + bool operator==(const histo1d<V>& histo1, const histo1d<V>& histo2) + { + trace::entering("mln::accu::stat::histo1d::operator=="); + + bool result = true; + const image1d<unsigned>& res1 = histo1.to_result(); + const image1d<unsigned>& res2 = histo2.to_result(); + + mln_precondition(res1.is_valid()); + mln_precondition(res2.is_valid()); + + mln_piter(image1d<unsigned>) p1(res1.domain()); + mln_piter(image1d<unsigned>) p2(res2.domain()); + + for_all_2(p1, p2) + result &= (res1(p1) == res2(p2)); + + trace::exiting("mln::accu::stat::histo1d::operator=="); + return result; + } + +#endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace mln::accu::stat + + } // end of namespace mln::accu + +} // end of namespace mln + +#endif // ! MLN_ACCU_STAT_HISTO1D_HH diff --git a/scribo/sandbox/green/mln/accu/stat/histo2d.hh b/scribo/sandbox/green/mln/accu/stat/histo2d.hh new file mode 100644 index 0000000..c28723c --- /dev/null +++ b/scribo/sandbox/green/mln/accu/stat/histo2d.hh @@ -0,0 +1,358 @@ +// Copyright (C) 2007, 2008, 2009, 2010 EPITA LRDE +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef MLN_ACCU_STAT_HISTO2D_HH +# define MLN_ACCU_STAT_HISTO2D_HH + +/// \file +/// +/// \brief Define a histogram as accumulator which returns an image2d. +/// +/// This source implements the discrete histogram version. It was +/// created for images which the values are derived from integer +/// type. The number of bins is directly infered from the cardinality +/// of the image value. It works with vectorial image, typically RGB +/// space where only RG are preserved. See histo1d.hh for limitations +/// of such implementation. 8 bits quantification starts to be +/// expensive, it produces image2d with [0..255,0..255] as domain. +/// +/// The following sample is a typical use of the histogram. +/// +/// #include <mln/accu/stat/histo2d.hh> +/// #include <mln/core/image/image2d.hh> +/// #include <mln/data/compute.hh> +/// #include <mln/data/transform.hh> +/// #include <mln/fun/v2v/rgb_to_rg.hh> +/// #include <mln/img_path.hh> +/// #include <mln/io/ppm/load.hh> +/// #include <mln/value/rg.hh> +/// #include <mln/value/rgb8.hh> +/// +/// int main() +/// { +/// typedef mln::value::rg<8> t_rg8 +/// typedef mln::value::rgb8 t_rgb8; +/// typedef mln::fun::v2v::rgb_to_rg<8> t_rgb_to_rg; +/// typedef mln::image2d<t_rg8> t_image2d_rg8; +/// typedef mln::image2d<t_rgb8> t_image2d_rgb8; +/// typedef mln::image2d<unsigned> t_histo; +/// t_image2d_rgb8 img_rgb8; +/// t_image2d_rg8 img_rg8; +/// t_histo histo; +/// +/// mln::io::ppm::load(img_rgb8, OLENA_IMG_PATH"/lena.ppm"); +/// img_rg8 = mln::data::transform(img_rgb8, t_rgb_to_rg()); +/// histo = mln::data::compute(mln::accu::meta::stat::histo2d(), img_rg8); +/// +/// return 0; +/// } + +# include <iostream> + +# include <mln/accu/internal/base.hh> + +# include <mln/core/macros.hh> +# include <mln/core/image/image2d.hh> +# include <mln/core/alias/point2d.hh> +# include <mln/core/alias/box2d.hh> + +# include <mln/trait/value/comp.hh> + +# include <mln/arith/plus.hh> + +# include <mln/trace/entering.hh> +# include <mln/trace/exiting.hh> + +# include <mln/value/ops.hh> + +namespace mln +{ + + namespace accu + { + + namespace stat + { + + // Forward declaration + template <typename V> + struct histo2d; + + } // end of namespace mln::accu::stat + + namespace meta + { + + namespace stat + { + + struct histo2d : public Meta_Accumulator<histo2d> + { + template <typename V> + struct with + { + typedef accu::stat::histo2d<V> ret; + }; + }; + + } // end of namespace mln::accu::meta::stat + + } // end of namespace mln::accu::meta + + } // end of namespace mln::accu + + + namespace trait + { + + template <typename V> + struct accumulator_< mln::accu::stat::histo2d<V> > + { + typedef accumulator::has_untake::no has_untake; + typedef accumulator::has_set_value::no has_set_value; + typedef accumulator::has_stop::no has_stop; + typedef accumulator::when_pix::use_v when_pix; + }; + + template <typename V> + struct set_precise_binary_<op::eq, + accu::stat::histo2d<V>, + accu::stat::histo2d<V> > + { + typedef bool ret; + }; + + } // end of namespace mln::trait + + namespace accu + { + + namespace stat + { + + /// \brief Define an histogram which returns an image3d . + /// + /// Param V defines the space in which we count the values. + /// For instance, this histogram works image2d<rgb<2>> or + /// image2d<rgb<7>>. The histogram count the occurrence of each value. + /// The number of bins depends of the grayscale values, for 8 bits there + /// is 256x3 bins. Note that over + /// quantification works too. + /// + /// \ingroup modaccuvalues + + template <typename V> + struct histo2d : + public mln::accu::internal::base<image2d<unsigned>, histo2d<V> > + { + typedef V argument; + typedef image2d<unsigned> result; + typedef result q_result; + + /// Constructors + /// \{ + /// \brief Initialize the size of the resulting image1d. + /// + /// Initialize the size the resulting image from the theorical dynamic + /// of the greylevel values (Use V to manage it). + histo2d(); + /// \} + + + /// Manipulators. + /// \{ + /// \brief Initialize the histogram with zero value. + /// + /// This method must be called just before starting the use of the + /// histogram. If it's not, resulting values won't converge to the + /// density. + void init(); + + + /// \brief Update the histogram with the RGB pixel t. + /// \param[in] t a greylevel pixel of type V. + /// + /// The end user shouldn't call this method. In place of it, he can + /// go through the data compute interface. + void take(const argument& t); + + + /// \brief Update the histogram with an other histogram. + /// \param[in] other the other histogram. + void take(const histo2d<V>& other); + /// \} + + /// Accessors. + /// \{ + /// \brief Return the histogram as an image1d. + /// + /// This is the machinery to communicate with data compute interface. + /// The end user should'nt use it. + result to_result() const; + operator result () const; + /// \} + + /// \brief Check whethever this accumulator is able to return a result. + /// + /// Depends if the resulting image1d is valid. We can assume it is quite + /// always the case. + bool is_valid() const; + + protected: + result count_; + }; + + /// \brief Check wethever an histogram is equal to an other one. + /// \param[in] histo1 the first histogram to compare with. + /// \param[in] histo2 the second histogram. + /// + /// The operator compare all the bins from the two histogram. + + template <typename V> + bool operator==(const histo2d<V>& histo1, + const histo2d<V>& histo2); + +#ifndef MLN_INCLUDE_ONLY + + template <typename V> + inline + histo2d<V>::histo2d() + { + trace::entering("mln::accu::stat::histo2d::histo2d"); + typedef mln_trait_value_comp(V,0) comp0; + typedef mln_trait_value_comp(V,1) comp1; + + // comp keep a trace of the dimension of the theorical image. + // mln_min(comp) --> 0 + // mln_max(comp) --> 2^(n-1) [127 for n=7][255 for n=8] ... + + count_.init_(box2d(point2d(mln_min(comp0), + mln_min(comp1)), + point2d(mln_max(comp0), + mln_max(comp1)))); + + trace::exiting("mln::accu::stat::histo2d::histo2d"); + } + + template <typename V> + inline + void histo2d<V>::init() + { + trace::entering("mln::accu::stat::histo2d::init"); + + data::fill(count_, 0); + trace::exiting("mln::accu::stat::histo2d::init"); + } + + template <typename V> + inline + void histo2d<V>::take(const argument& t) + { + trace::entering("mln::accu::stat::histo2d::take"); + + // Just convert a greyscale value (int_u8 like) to a position for an + // iterator on the resulting image. + // Take care to the constructor : Point(slice, row, column) + ++count_(point2d(t.red(), t.green())); + + trace::exiting("mln::accu::stat::histo2d::take"); + } + + + template <typename V> + inline + void histo2d<V>::take(const histo2d<V>& other) + { + trace::entering("mln::accu::stat::histo2d::take"); + + count_ += other.count_; + + trace::exiting("mln::accu::stat::histo2d::take"); + } + + template <typename V> + inline + typename histo2d<V>::result histo2d<V>::to_result() const + { + trace::entering("mln::accu::stat::histo2d::to_result"); + + trace::exiting("mln::accu::stat::histo2d::to_result"); + return count_; + } + + template <typename V> + inline + histo2d<V>::operator result() const + { + trace::entering("mln::accu::stat::histo2d::operator result"); + + trace::exiting("mln::accu::stat::histo2d::operator result"); + return count_; + } + + template <typename V> + inline + bool histo2d<V>::is_valid() const + { + trace::entering("mln::accu::stat::histo2d::is_valid"); + bool result = count_.is_valid(); + + trace::exiting("mln::accu::stat::histo2d::is_valid"); + return result; + } + + template <typename V> + bool operator==(const histo2d<V>& histo1, + const histo2d<V>& histo2) + { + trace::entering("mln::accu::stat::operator=="); + + bool result = true; + const image2d<unsigned>& res1 = histo1.to_result(); + const image2d<unsigned>& res2 = histo2.to_result(); + + mln_precondition(res1.is_valid()); + mln_precondition(res2.is_valid()); + + mln_piter(image2d<unsigned>) p1(res1.domain()); + mln_piter(image2d<unsigned>) p2(res2.domain()); + + for_all_2(p1, p2) + result &= (res1(p1) == res2(p2)); + + trace::exiting("mln::accu::stat::operator=="); + return result; + } + +#endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace mln::accu::stat + + } // end of namespace mln::accu + +} // end of namespace mln + +#endif // ! MLN_ACCU_STAT_HISTO2D_HH diff --git a/milena/sandbox/green/mln/accu/stat/histo3d_hsl.hh b/scribo/sandbox/green/mln/accu/stat/histo3d_hsl.hh similarity index 100% copy from milena/sandbox/green/mln/accu/stat/histo3d_hsl.hh copy to scribo/sandbox/green/mln/accu/stat/histo3d_hsl.hh diff --git a/milena/sandbox/green/mln/accu/stat/histo3d_rgb.hh b/scribo/sandbox/green/mln/accu/stat/histo3d_rgb.hh similarity index 100% copy from milena/sandbox/green/mln/accu/stat/histo3d_rgb.hh copy to scribo/sandbox/green/mln/accu/stat/histo3d_rgb.hh diff --git a/milena/sandbox/green/mln/clustering/k_mean.hh b/scribo/sandbox/green/mln/clustering/k_mean.hh similarity index 100% copy from milena/sandbox/green/mln/clustering/k_mean.hh copy to scribo/sandbox/green/mln/clustering/k_mean.hh diff --git a/milena/sandbox/green/mln/clustering/kmean1d.hh b/scribo/sandbox/green/mln/clustering/kmean1d.hh similarity index 100% copy from milena/sandbox/green/mln/clustering/kmean1d.hh copy to scribo/sandbox/green/mln/clustering/kmean1d.hh diff --git a/milena/sandbox/green/mln/clustering/kmean2d.hh b/scribo/sandbox/green/mln/clustering/kmean2d.hh similarity index 100% copy from milena/sandbox/green/mln/clustering/kmean2d.hh copy to scribo/sandbox/green/mln/clustering/kmean2d.hh diff --git a/milena/sandbox/green/mln/clustering/kmean3d.hh b/scribo/sandbox/green/mln/clustering/kmean3d.hh similarity index 100% copy from milena/sandbox/green/mln/clustering/kmean3d.hh copy to scribo/sandbox/green/mln/clustering/kmean3d.hh diff --git a/milena/sandbox/green/mln/clustering/kmean_rgb.hh b/scribo/sandbox/green/mln/clustering/kmean_rgb.hh similarity index 100% copy from milena/sandbox/green/mln/clustering/kmean_rgb.hh copy to scribo/sandbox/green/mln/clustering/kmean_rgb.hh diff --git a/milena/sandbox/green/mln/display/display_histo.hh b/scribo/sandbox/green/mln/display/display_histo.hh similarity index 100% copy from milena/sandbox/green/mln/display/display_histo.hh copy to scribo/sandbox/green/mln/display/display_histo.hh diff --git a/milena/sandbox/green/mln/display/project_histo.hh b/scribo/sandbox/green/mln/display/project_histo.hh similarity index 100% copy from milena/sandbox/green/mln/display/project_histo.hh copy to scribo/sandbox/green/mln/display/project_histo.hh diff --git a/milena/sandbox/green/mln/fun/p2b/achromatic.hh b/scribo/sandbox/green/mln/fun/p2b/achromatic.hh similarity index 100% copy from milena/sandbox/green/mln/fun/p2b/achromatic.hh copy to scribo/sandbox/green/mln/fun/p2b/achromatic.hh diff --git a/milena/sandbox/green/mln/fun/p2b/component_equals.hh b/scribo/sandbox/green/mln/fun/p2b/component_equals.hh similarity index 100% copy from milena/sandbox/green/mln/fun/p2b/component_equals.hh copy to scribo/sandbox/green/mln/fun/p2b/component_equals.hh diff --git a/milena/sandbox/green/mln/fun/v2v/achromatism.hh b/scribo/sandbox/green/mln/fun/v2v/achromatism.hh similarity index 100% copy from milena/sandbox/green/mln/fun/v2v/achromatism.hh copy to scribo/sandbox/green/mln/fun/v2v/achromatism.hh diff --git a/milena/sandbox/green/mln/fun/v2v/hue_concentration.hh b/scribo/sandbox/green/mln/fun/v2v/hue_concentration.hh similarity index 100% copy from milena/sandbox/green/mln/fun/v2v/hue_concentration.hh copy to scribo/sandbox/green/mln/fun/v2v/hue_concentration.hh diff --git a/milena/sandbox/green/mln/fun/v2v/int_u16_to_int_u14.hh b/scribo/sandbox/green/mln/fun/v2v/int_u16_to_int_u14.hh similarity index 100% copy from milena/sandbox/green/mln/fun/v2v/int_u16_to_int_u14.hh copy to scribo/sandbox/green/mln/fun/v2v/int_u16_to_int_u14.hh diff --git a/milena/sandbox/green/mln/fun/v2v/log.hh b/scribo/sandbox/green/mln/fun/v2v/log.hh similarity index 100% copy from milena/sandbox/green/mln/fun/v2v/log.hh copy to scribo/sandbox/green/mln/fun/v2v/log.hh diff --git a/milena/sandbox/green/mln/fun/v2v/rg_to_rgb.hh b/scribo/sandbox/green/mln/fun/v2v/rg_to_rgb.hh similarity index 100% copy from milena/sandbox/green/mln/fun/v2v/rg_to_rgb.hh copy to scribo/sandbox/green/mln/fun/v2v/rg_to_rgb.hh diff --git a/milena/sandbox/green/mln/fun/v2v/rgb8_to_int_u8.hh b/scribo/sandbox/green/mln/fun/v2v/rgb8_to_int_u8.hh similarity index 100% copy from milena/sandbox/green/mln/fun/v2v/rgb8_to_int_u8.hh copy to scribo/sandbox/green/mln/fun/v2v/rgb8_to_int_u8.hh diff --git a/milena/sandbox/green/mln/fun/v2v/rgb8_to_rgbn.hh b/scribo/sandbox/green/mln/fun/v2v/rgb8_to_rgbn.hh similarity index 100% copy from milena/sandbox/green/mln/fun/v2v/rgb8_to_rgbn.hh copy to scribo/sandbox/green/mln/fun/v2v/rgb8_to_rgbn.hh diff --git a/milena/sandbox/green/mln/fun/v2v/rgb_to_achromatism_map.hh b/scribo/sandbox/green/mln/fun/v2v/rgb_to_achromatism_map.hh similarity index 100% copy from milena/sandbox/green/mln/fun/v2v/rgb_to_achromatism_map.hh copy to scribo/sandbox/green/mln/fun/v2v/rgb_to_achromatism_map.hh diff --git a/milena/sandbox/green/mln/fun/v2v/rgb_to_hsv.hh b/scribo/sandbox/green/mln/fun/v2v/rgb_to_hsv.hh similarity index 100% copy from milena/sandbox/green/mln/fun/v2v/rgb_to_hsv.hh copy to scribo/sandbox/green/mln/fun/v2v/rgb_to_hsv.hh diff --git a/milena/sandbox/green/mln/fun/v2v/rgb_to_hue_map.hh b/scribo/sandbox/green/mln/fun/v2v/rgb_to_hue_map.hh similarity index 100% copy from milena/sandbox/green/mln/fun/v2v/rgb_to_hue_map.hh copy to scribo/sandbox/green/mln/fun/v2v/rgb_to_hue_map.hh diff --git a/scribo/sandbox/green/mln/fun/v2v/rgb_to_rg.hh b/scribo/sandbox/green/mln/fun/v2v/rgb_to_rg.hh new file mode 100644 index 0000000..d4c1e46 --- /dev/null +++ b/scribo/sandbox/green/mln/fun/v2v/rgb_to_rg.hh @@ -0,0 +1,111 @@ +// Copyright (C) 2007,2008,2009,2010 EPITA LRDE +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef MLN_FUN_V2V_RGB_TO_RG_HH +# define MLN_FUN_V2V_RGB_TO_RG_HH + +# include <mln/value/rg.hh> +# include <mln/value/rgb.hh> +# include <mln/core/contract.hh> + +/// \file +/// +/// \brief Convert a rgb value to a rg value. +/// +/// This source implements the conversion between rgb space and rg space. +/// +/// The following sample is a typical use of the rgb/rg conversion function. +/// +/// #include <mln/accu/stat/histo2d.hh> +/// #include <mln/core/image/image2d.hh> +/// #include <mln/data/compute.hh> +/// #include <mln/data/transform.hh> +/// #include <mln/fun/v2v/rgb_to_rg.hh> +/// #include <mln/img_path.hh> +/// #include <mln/io/ppm/load.hh> +/// #include <mln/value/rg.hh> +/// #include <mln/value/rgb8.hh> +/// +/// int main() +/// { +/// typedef mln::value::rg<8> t_rg8 +/// typedef mln::value::rgb8 t_rgb8; +/// typedef mln::fun::v2v::rgb_to_rg<8> t_rgb_to_rg; +/// typedef mln::image2d<t_rg8> t_image2d_rg8; +/// typedef mln::image2d<t_rgb8> t_image2d_rgb8; +/// typedef mln::image2d<unsigned> t_histo; +/// t_image2d_rgb8 img_rgb8; +/// t_image2d_rg8 img_rg8; +/// t_histo histo; +/// +/// mln::io::ppm::load(img_rgb8, OLENA_IMG_PATH"/lena.ppm"); +/// img_rg8 = mln::data::transform(img_rgb8, t_rgb_to_rg()); +/// histo = mln::data::compute(mln::accu::meta::stat::histo2d(), img_rg8); +/// +/// return 0; +/// } + +namespace mln +{ + + namespace fun + { + + namespace v2v + { + + /// \brief Convert a rgb value to a rg value. + /// + /// Param n defines the quantification used for rgb space and rg space. + /// + /// \ingroup modfunv2v + + template <unsigned n> + struct rgb_to_rg : Function_v2v< rgb_to_rg<n> > + { + typedef value::rg<n> result; + typedef value::rgb<n> argument; + + /// \brief Convert rgb value to rg value. + /// + /// \param[in] v the rgb value to convert. + /// + /// Conversion is done by calling the rg constructor. There is + /// no modification of values. The red/green fields from rgb the value + /// are preserved. Blue value is dropped. + + result operator()(const argument& v) const + { + return value::rg<n>(v); + } + }; + + } // end of namespace mln::fun::v2v + + } // end of namespace mln::fun + +} // end of namespace mln + +#endif // ! MLN_FUN_V2V_RGB_TO_RG_HH diff --git a/milena/sandbox/green/mln/fun/v2v/rgb_to_saturation_map.hh b/scribo/sandbox/green/mln/fun/v2v/rgb_to_saturation_map.hh similarity index 100% copy from milena/sandbox/green/mln/fun/v2v/rgb_to_saturation_map.hh copy to scribo/sandbox/green/mln/fun/v2v/rgb_to_saturation_map.hh diff --git a/milena/sandbox/green/mln/fun/v2v/rgb_to_value_map.hh b/scribo/sandbox/green/mln/fun/v2v/rgb_to_value_map.hh similarity index 100% copy from milena/sandbox/green/mln/fun/v2v/rgb_to_value_map.hh copy to scribo/sandbox/green/mln/fun/v2v/rgb_to_value_map.hh diff --git a/milena/sandbox/green/mln/img_path.hh b/scribo/sandbox/green/mln/img_path.hh similarity index 100% copy from milena/sandbox/green/mln/img_path.hh copy to scribo/sandbox/green/mln/img_path.hh diff --git a/scribo/sandbox/green/mln/io/plot/save_image_sh.hh b/scribo/sandbox/green/mln/io/plot/save_image_sh.hh new file mode 100644 index 0000000..137f78d --- /dev/null +++ b/scribo/sandbox/green/mln/io/plot/save_image_sh.hh @@ -0,0 +1,1056 @@ +// Copyright (C) 2007,2008,2009,2010 EPITA LRDE +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef MLN_IO_PLOT_SAVE_IMAGE_SH_HH +# define MLN_IO_PLOT_SAVE_IMAGE_SH_HH + +/// \file +/// +/// \brief Define some functions to export to gnuplot format as a script shell. +/// +/// Theses routines are dedicated to image visualization. The aim is to display +/// image whatever the value used as pixel. The behaviour of gnuplot is more +/// like xv than imageMagick. A Gnuplot script shell file is a text dump file +/// with a preambule to let gnuplot interpret data. As a script shell, you can +/// launch it (don't forget the permissions), and every thing is packed in it. +/// The script file call gnuplot in batch mode, the result window persists and +/// that's all. +/// + +# include <fstream> +# include <string> + +# include <mln/trace/entering.hh> +# include <mln/trace/exiting.hh> + +# include <mln/core/macros.hh> +# include <mln/core/contract.hh> +# include <mln/core/image/image1d.hh> +# include <mln/core/image/image2d.hh> +# include <mln/core/image/image3d.hh> + +# include <mln/geom/min_ind.hh> +# include <mln/geom/max_ind.hh> +# include <mln/geom/min_row.hh> +# include <mln/geom/max_row.hh> +# include <mln/geom/min_col.hh> +# include <mln/geom/max_col.hh> + +# include <mln/trait/value_.hh> + +# include <mln/value/int_u.hh> +# include <mln/value/int_s.hh> +# include <mln/value/rgb.hh> +# include <mln/value/hsl.hh> +# include <mln/value/hsi.hh> + +# include <mln/util/array.hh> + + +namespace mln +{ + + namespace io + { + + namespace plot + { + + /// \brief Save an image as a gnuplot script shell. + /// + /// Every thing is save. The image could be 1d, 2d or 3d. The value of + /// the pixels could be int_u<n>, int_s<n>, float, double, hsl_f, hsl_d, + /// hsi_f, hsi_d and rgb<n>. + /// + /// \param[in] img the image which contains the data to save. + /// \param[in] filename the name of the unix script shell. + /// \return the status of the opening file operation. + /// + /// The result depends on the permission to save the file with + /// filename parameter as unix path. The script shell file must have the + /// permission to execute (chmod 755). Launch the script shell to call + /// gnuplot in batchmode with fine parameters. + + template <typename I> + bool save_image_sh(const Image<I>& img, const std::string& filename); + + /// \brief Save a stack of image. + /// + /// This is an experimental support. + /// + /// \param[in] stack the stack of image to save. + /// \param[in] filename the name of the unix script shell. + /// \return the status of the opening file operation. + /// + /// The result depends on the permission to save the file with + /// filename parameter as unix path. The script shell file must have the + /// permission to execute (chmod 755). Launch the script shell to call + /// gnuplot in batchmode with fine parameters. + template <typename I> + bool save_image_sh(const util::array< image1d<I> >& stack, + const std::string& filename); + + template <typename I> + bool save_image_sh(const util::array< util::array< image1d<I> > >& stack, + const std::string& filename); + + } // end of namespace mln::io::plot + + } // end of namespace mln::io + + + namespace io + { + + namespace plot + { + +#ifndef MLN_INCLUDE_ONLY + + //------------------------------------------------------------------------ + // Impl. + //------------------------------------------------------------------------ + + namespace impl + { + + + //---------------------------------------------------------------------- + // save_image_sh_array_array_image1d(const array<array<image1d<I>>>&, + // const string&) + //---------------------------------------------------------------------- + + template <typename I> + inline + bool save_image_sh_array_array_image1d(const util::array< util::array< + image1d<I> > >& stack, + const std::string& filename) + { + trace::entering("mln::io::plot::impl::" + "save_image_sh_array_array_image1d"); + + mln_precondition(!stack.is_empty()); + mln_precondition(!stack[0].is_empty()); + mln_precondition(stack[0][0].is_valid()); + + std::ofstream out(filename.c_str()); + bool result = !out.fail(); + unsigned min_ind = geom::min_ind(stack[0][0]); + unsigned max_ind = geom::max_ind(stack[0][0]); + + if (result) + { + // Output data prelude (terminal X11, image). + out << "#!/bin/sh" << std::endl; + out << "####################################" << std::endl; + out << "# Columns = (x, y, val) #" << std::endl; + out << "####################################" << std::endl; + out << std::endl; + out << "gnuplot <<EOF" << std::endl; + out << "set terminal x11 persist 1" << std::endl; + out << "set xrange [" << min_ind; + out << ":" << max_ind; + out << "]" << std::endl; + out << "plot '-' with line"; + + for (unsigned i = 1; i < stack.size(); ++i) + { + for (unsigned j = 1; j < stack[i].size(); ++j) + { + + out << ",\\" << std::endl; + out << " '-' with line"; + } + } + + out << std::endl; + + mln_eiter(util::array< util::array< image1d<I> > >) e0(stack); + + for_all (e0) + { + mln_eiter(util::array< image1d<I> >) e1(stack[e0.index_()]); + + for_all (e1) + { + mln_piter(image1d< I >) + p(stack[e0.index_()][e1.index_()].domain()); + + // Output data. + for_all(p) + { + out << p.ind() << " "; + out << stack[e0.index_()][e1.index_()](p) << std::endl;; + } + + // Close gnuplot data stream. + out << "e" << std::endl; + } + } + + out << "EOF" << std::endl; + out.close(); + } + else + { + std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename; + std::cerr << " couldn't be opened !!" << std::endl; + } + + trace::exiting("mln::io::plot::impl::" + "save_image_sh_array_array_image1d"); + + return result; + } + + //---------------------------------------------------------------------- + // save_image_sh_array_array_image1d_vec3( + // const array<array<image1d<vec<3,T>>>>&, + // const string&) + //---------------------------------------------------------------------- + + template <typename T> + inline + bool save_image_sh_array_array_image1d_vec3( + const util::array<util::array<image1d<algebra::vec<3,T> > > >& stack, + const std::string& filename) + { + trace::entering("mln::io::plot::impl::" + "save_image_sh_array_array_image1d_vec3"); + + typedef algebra::vec<3,T> t_val; + typedef image1d<t_val> t_img; + typedef util::array<t_img> t_array; + typedef util::array<t_array> t_stack; + + mln_precondition(!stack.is_empty()); + mln_precondition(!stack[0].is_empty()); + mln_precondition(stack[0][0].is_valid()); + + std::ofstream out(filename.c_str()); + bool result = !out.fail(); + unsigned min_ind = geom::min_ind(stack[0][0]); + unsigned max_ind = geom::max_ind(stack[0][0]); + + if (result) + { + // Output data prelude (terminal X11, image). + out << "#!/bin/sh" << std::endl; + out << "####################################" << std::endl; + out << "# Columns = (x, y, val) #" << std::endl; + out << "####################################" << std::endl; + out << std::endl; + out << "gnuplot <<EOF" << std::endl; + out << "set terminal x11 persist 1" << std::endl; + out << "set xrange [" << min_ind; + out << ":" << max_ind; + out << "]" << std::endl; + out << "splot '-' with line palette"; + + for (unsigned i = 1; i < stack.size(); ++i) + { + for (unsigned j = 1; j < stack[i].size(); ++j) + { + + out << ",\\" << std::endl; + out << " '-' with line palette"; + } + } + + out << std::endl; + + mln_eiter(t_stack) e0(stack); + + for_all (e0) + { + mln_eiter(t_array) e1(stack[e0.index_()]); + + for_all (e1) + { + mln_piter(t_img) p(stack[e0.index_()][e1.index_()].domain()); + + // Output data. + for_all(p) + { + out << p.ind() << " "; + out << stack[e0.index_()][e1.index_()](p)[0] << " "; + out << stack[e0.index_()][e1.index_()](p)[1] << " "; + out << stack[e0.index_()][e1.index_()](p)[2] << std::endl;; + } + + // Close gnuplot data stream. + out << "e" << std::endl; + } + } + + out << "EOF" << std::endl; + out.close(); + } + else + { + std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename; + std::cerr << " couldn't be opened !!" << std::endl; + } + + trace::exiting("mln::io::plot::impl::" + "save_image_sh_array_array_image1d_vec3"); + + return result; + } + + + //---------------------------------------------------------------------- + // save_image_sh_array_array_image1d_vec2( + // const array<array<image1d<vec<2,T>>>>&, + // const string&) + //---------------------------------------------------------------------- + + template <typename T> + inline + bool save_image_sh_array_array_image1d_vec2( + const util::array<util::array<image1d<algebra::vec<2,T> > > >& stack, + const std::string& filename) + { + trace::entering("mln::io::plot::impl::" + "save_image_sh_array_array_image1d_vec2"); + + typedef algebra::vec<2,T> t_val; + typedef image1d<t_val> t_img; + typedef util::array<t_img> t_array; + typedef util::array<t_array> t_stack; + + mln_precondition(!stack.is_empty()); + mln_precondition(!stack[0].is_empty()); + mln_precondition(stack[0][0].is_valid()); + + std::ofstream out(filename.c_str()); + bool result = !out.fail(); + unsigned min_ind = geom::min_ind(stack[0][0]); + unsigned max_ind = geom::max_ind(stack[0][0]); + + if (result) + { + // Output data prelude (terminal X11, image). + out << "#!/bin/sh" << std::endl; + out << "####################################" << std::endl; + out << "# Columns = (x, y, val) #" << std::endl; + out << "####################################" << std::endl; + out << std::endl; + out << "gnuplot <<EOF" << std::endl; + out << "set terminal x11 persist 1" << std::endl; + out << "set xrange [" << min_ind; + out << ":" << max_ind; + out << "]" << std::endl; + out << "splot '-' with line"; + + for (unsigned i = 1; i < stack.size(); ++i) + { + for (unsigned j = 1; j < stack[i].size(); ++j) + { + + out << ",\\" << std::endl; + out << " '-' with line"; + } + } + + out << std::endl; + + mln_eiter(t_stack) e0(stack); + + for_all (e0) + { + mln_eiter(t_array) e1(stack[e0.index_()]); + + for_all (e1) + { + mln_piter(t_img) p(stack[e0.index_()][e1.index_()].domain()); + + // Output data. + for_all(p) + { + out << p.ind() << " "; + out << stack[e0.index_()][e1.index_()](p)[0] << " "; + out << stack[e0.index_()][e1.index_()](p)[1] << std::endl;; + } + + // Close gnuplot data stream. + out << "e" << std::endl; + } + } + + out << "EOF" << std::endl; + out.close(); + } + else + { + std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename; + std::cerr << " couldn't be opened !!" << std::endl; + } + + trace::exiting("mln::io::plot::impl::" + "save_image_sh_array_array_image1d_vec2"); + + return result; + } + + //---------------------------------------------------------------------- + // save_image_sh_array_image1d(const array<image1d<I>>&, const string&) + //---------------------------------------------------------------------- + + template <typename I> + inline + bool save_image_sh_array_image1d(const util::array< image1d<I> >& stack, + const std::string& filename) + { + trace::entering("mln::io::plot::impl::save_image_sh_array_image1d"); + mln_precondition(!stack.is_empty()); + mln_precondition(stack[0].is_valid()); + + std::ofstream out(filename.c_str()); + bool result = !out.fail(); + unsigned min_ind = geom::min_ind(stack[0]); + unsigned max_ind = geom::max_ind(stack[0]); + + if (result) + { + // Output data prelude (terminal X11, image). + out << "#!/bin/sh" << std::endl; + out << "####################################" << std::endl; + out << "# Columns = (x, y, val) #" << std::endl; + out << "####################################" << std::endl; + out << std::endl; + out << "gnuplot <<EOF" << std::endl; + out << "set terminal x11 persist 1" << std::endl; + out << "set xrange [" << min_ind; + out << ":" << max_ind; + out << "]" << std::endl; + out << "plot '-' with line"; + + for (unsigned i = 1; i < stack.size(); ++i) + { + + out << ",\\" << std::endl; + out << " '-' with line"; + } + + out << std::endl; + + mln_eiter(util::array< image1d<I> >) e(stack); + + for_all (e) + { + mln_piter(image1d< I >) p(stack[e.index_()].domain()); + + // Output data. + for_all(p) + { + out << p.ind() << " "; + out << stack[e.index_()](p) << std::endl;; + } + + // Close gnuplot data stream. + out << "e" << std::endl; + } + + out << "EOF" << std::endl; + out.close(); + } + else + { + std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename; + std::cerr << " couldn't be opened !!" << std::endl; + } + + trace::exiting("mln::io::plot::impl::save_image_sh_array_image1d"); + return result; + } + + + //---------------------------------------------------------------------- + // save_image_sh_image2d_rgb(const image2d<rgb<n>>&, const string&) + //---------------------------------------------------------------------- + + template <unsigned n> + inline + bool save_image_sh_image2d_rgb(const image2d<value::rgb<n> >& img, + const std::string& filename) + { + trace::entering("mln::io::plot::impl::save_image_sh_image2d_rgb"); + mln_precondition(img.is_valid()); + + std::ofstream out(filename.c_str()); + bool result = !out.fail(); + unsigned min_row = geom::min_row(img); + unsigned max_row = geom::max_row(img); + unsigned min_col = geom::min_col(img); + unsigned max_col = geom::max_col(img); + + if (result) + { + mln_piter(image2d< value::rgb<n> >) p(img.domain()); + + // Output data prelude (terminal X11, image). + out << "#!/bin/sh" << std::endl; + out << "####################################" << std::endl; + out << "# Columns = (x, y, r, g, b) #" << std::endl; + out << "####################################" << std::endl; + out << std::endl; + out << "gnuplot <<EOF" << std::endl; + out << "set terminal x11 persist 1" << std::endl; + out << "set xrange [" << min_col; + out << ":" << max_col; + out << "]" << std::endl; + out << "set yrange [-" << max_row; + out << ":" << min_row; + out << "]" << std::endl; + out << "plot '-' using 2:(-\\$1):3:4:5 with rgbimage" << std::endl; + + // Output data. + for_all(p) + { + out << p.row() << " "; + out << p.col() << " "; + out << img(p).red() << " "; + out << img(p).green() << " "; + out << img(p).blue() << std::endl; + } + + // Close gnuplot data stream. + out << "e" << std::endl; + out << "EOF" << std::endl; + + out.close(); + } + else + { + std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename; + std::cerr << " couldn't be opened !!" << std::endl; + } + + trace::exiting("mln::io::plot::impl::save_image_sh_image2d_rgb"); + return result; + } + + //---------------------------------------------------------------------- + // save_image_sh_image2d_hsl(const image2d<hsl_<T,T,T>>&, const string&) + //---------------------------------------------------------------------- + + template <typename T> + inline + bool save_image_sh_image2d_hsl(const image2d<value::hsl_<T,T,T> >& img, + const std::string& filename) + { + trace::entering("mln::io::plot::impl::save_image_sh_image2d_hsl"); + mln_precondition(img.is_valid()); + + std::ofstream out(filename.c_str()); + bool result = !out.fail(); + unsigned min_row = geom::min_row(img); + unsigned max_row = geom::max_row(img); + unsigned min_col = geom::min_col(img); + unsigned max_col = geom::max_col(img); + + typedef mln::value::hsl_<T,T,T> hsl; + + if (result) + { + mln_piter(image2d< hsl >) p(img.domain()); + + // Output data prelude (terminal X11, image). + out << "#!/bin/sh" << std::endl; + out << "####################################" << std::endl; + out << "# Columns = (x, y, val) #" << std::endl; + out << "####################################" << std::endl; + out << std::endl; + out << "gnuplot <<EOF" << std::endl; + out << "q(l,s) = (l < 0.5)? (l*(1+s)):(l+s-(l*s))" << std::endl; + out << "p(l,s) = (2.0 * l - q(l,s))" << std::endl; + out << "n(x) = (x < 0)?(x+1):(x > 1)?(x-1) : (x)"<< std::endl; + out << std::endl; + out << "c(p,q,t) = (t <(1.0/6.0))?(p+(q-p)*6.0*t):\\"<< std::endl; + out << " (t <(1.0/2.0))?(q) :\\" << std::endl; + out << " (t<(2.0/3.0))?(p+(q-p)*6.0*((2.0/3.0)-t)):\\" << std::endl; + out << " (p)" << std::endl; + out << std::endl; + out << "r(h,s,l) = c(p(l,s),q(l,s),n(h/360.0+1.0/3.0))"<< std::endl; + out << "g(h,s,l) = c(p(l,s),q(l,s),n(h/360.0))" << std::endl; + out << "b(h,s,l) = c(p(l,s),q(l,s),n(h/360.0-1.0/3.0))"<< std::endl; + out << std::endl; + out << "set terminal x11 persist 1" << std::endl; + out << "set palette gray" << std::endl; + out << "set xrange [" << min_col; + out << ":" << max_col; + out << "]" << std::endl; + out << "set yrange [-" << max_row; + out << ":" << min_row; + out << "]" << std::endl; + out << "plot '-' using 2:(-\\$1):\\" << std::endl; + out << " (r(\\$3,\\$4,\\$5)):\\" << std::endl; + out << " (g(\\$3,\\$4,\\$5)):\\" << std::endl; + out << " (b(\\$3,\\$4,\\$5)) with rgbimage" << std::endl; + + // Output data. + for_all(p) + { + out << p.row() << " "; + out << p.col() << " "; + out << img(p).hue() << " "; + out << img(p).sat() << " "; + out << img(p).lum() << std::endl; + } + + // Close gnuplot data stream. + out << "e" << std::endl; + out << "EOF" << std::endl; + + out.close(); + } + else + { + std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename; + std::cerr << " couldn't be opened !!" << std::endl; + } + + trace::exiting("mln::io::plot::impl::save_image_sh_image2d_hsl"); + return result; + } + + //---------------------------------------------------------------------- + // save_image_sh_image2d_hsi(const image2d<hsi_<T,T,T>>&, const string&) + //---------------------------------------------------------------------- + + template <typename T> + inline + bool save_image_sh_image2d_hsi(const image2d<value::hsi_<T,T,T> >& img, + const std::string& filename) + { + trace::entering("mln::io::plot::impl::save_image_sh_image2d_hsi"); + mln_precondition(img.is_valid()); + + std::ofstream out(filename.c_str()); + bool result = !out.fail(); + unsigned min_row = geom::min_row(img); + unsigned max_row = geom::max_row(img); + unsigned min_col = geom::min_col(img); + unsigned max_col = geom::max_col(img); + + typedef mln::value::hsi_<T,T,T> hsi; + + if (result) + { + mln_piter(image2d< hsi >) p(img.domain()); + + // Output data prelude (terminal X11, image). + out << "#!/bin/sh" << std::endl; + out << "####################################" << std::endl; + out << "# Columns = (x, y, val) #" << std::endl; + out << "####################################" << std::endl; + out << std::endl; + out << "gnuplot <<EOF" << std::endl; + out << "teta(h) = (h/180.0) * pi" << std::endl; + out << "alpha(s,h) = s*cos(teta(h))" << std::endl; + out << "beta(s,h) = s*sin(teta(h))" << std::endl; + out << "n(x) = (x < 0)?(x+1) : (x > 1)?(x-1):(x)"<< std::endl; + out << std::endl; + out << "c(p,q,t) = (t <(1.0/6.0))?(p+(q-p)*6.0*t):\\"<< std::endl; + out << " (t <(1.0/2.0))?(q) :\\" << std::endl; + out << " (t <(2.0/3.0))?(p+(q-p)*6.0*((2.0/3.0)-t)):\\"<< std::endl; + out << " (p)" << std::endl; + out << std::endl; + out << "r(h,s,i) = (sqrt(3.0)/3.0) * i \\" << std::endl; + out << " + (2.0/(sqrt(6.0))) * beta(s,h)" << std::endl; + out << "g(h,s,i) = (sqrt(3.0)/3.0) * i \\" << std::endl; + out << " + (2.0/(sqrt(2.0))) * alpha(s,h)\\" << std::endl; + out << " - (1.0/(sqrt(6.0))) * beta(s,h)" << std::endl; + out << "b(h,s,i) = (sqrt(3.0)/3.0) * i \\" << std::endl; + out << " - (2.0/(sqrt(2.0))) * alpha(s,h) \\"<< std::endl; + out << " - (1.0/(sqrt(6.0))) * beta(s,h)" << std::endl; + out << std::endl; + out << "set terminal x11 persist 1" << std::endl; + out << "set palette gray" << std::endl; + out << "set xrange [" << min_col; + out << ":" << max_col; + out << "]" << std::endl; + out << "set yrange [-" << max_row; + out << ":" << min_row; + out << "]" << std::endl; + out << "plot '-' using 2:(-\\$1):\\" << std::endl; + out << " (r(\\$3,\\$4,\\$5)):\\" << std::endl; + out << " (g(\\$3,\\$4,\\$5)):\\" << std::endl; + out << " (b(\\$3,\\$4,\\$5)) with rgbimage" << std::endl; + + // Output data. + for_all(p) + { + out << p.row() << " "; + out << p.col() << " "; + out << img(p).hue() << " "; + out << img(p).sat() << " "; + out << img(p).inty() << std::endl; + } + + // Close gnuplot data stream. + out << "e" << std::endl; + out << "EOF" << std::endl; + + out.close(); + } + else + { + std::cerr << "ERROR[mln::io::plot::save_image_sh]:" << filename; + std::cerr << " couldn't be opened !!" << std::endl; + } + + trace::exiting("mln::io::plot::impl::save_image_sh_image2d_hsi"); + return result; + } + + //---------------------------------------------------------------------- + // save_image_sh_image2d(const image2d<I>&, const string&) + //---------------------------------------------------------------------- + + template <typename I> + inline + bool save_image_sh_image2d(const image2d<I>& img, + const std::string& filename) + { + trace::entering("mln::io::plot::impl::save_image_sh_image2d"); + mln_precondition(img.is_valid()); + + std::ofstream out(filename.c_str()); + bool result = !out.fail(); + unsigned min_row = geom::min_row(img); + unsigned max_row = geom::max_row(img); + unsigned min_col = geom::min_col(img); + unsigned max_col = geom::max_col(img); + + if (result) + { + mln_piter(image2d<I>) p(img.domain()); + + // Output data prelude (terminal X11, image). + out << "#!/bin/sh" << std::endl; + out << "####################################" << std::endl; + out << "# Columns = (x, y, val) #" << std::endl; + out << "####################################" << std::endl; + out << std::endl; + out << "gnuplot <<EOF" << std::endl; + out << "set terminal x11 persist 1" << std::endl; + out << "set palette gray" << std::endl; + out << "set xrange [" << min_col; + out << ":" << max_col; + out << "]" << std::endl; + out << "set yrange [-" << max_row; + out << ":" << min_row; + out << "]" << std::endl; + out << "plot '-' using 2:(-\\$1):3 with image" <<std::endl; + + // Output data. + for_all(p) + { + out << p.row() << " "; + out << p.col() << " "; + out << img(p) << std::endl; + } + + // Close gnuplot data stream. + out << "e" << std::endl; + out << "EOF" << std::endl; + + out.close(); + } + else + { + std::cerr << "ERROR[mln::io::plot::save_image_sh]:"<< filename; + std::cerr << " couldn't be opened !!" << std::endl; + } + + trace::exiting("mln::io::plot::impl::save_image_sh_image2d"); + return result; + } + + //---------------------------------------------------------------------- + // save_image_sh_image1d(const image1d<I>&, const string&) + //---------------------------------------------------------------------- + + template <typename I> + inline + bool save_image_sh_image1d(const image1d<I>& img, + const std::string& filename) + { + trace::entering("mln::io::plot::impl::save_image_sh_image1d"); + mln_precondition(img.is_valid()); + + std::ofstream out(filename.c_str()); + bool result = !out.fail(); + + if (result) + { + mln_piter(image1d<I>) p(img.domain()); + + // Output data prelude (terminal X11, impulse). + out << "#!/bin/sh" << std::endl; + out << "##########################" << std::endl; + out << "# Two columns = (x, val) #" << std::endl; + out << "##########################" << std::endl; + out << std::endl; + out << "gnuplot <<EOF" << std::endl; + out << "set terminal x11 persist 1" << std::endl; + out << "plot '-' with impulse" << std::endl; + + // Output data. + for_all(p) + { + out << p.ind() << " "; + out << img(p) << std::endl; + } + + // Close gnuplot data stream. + out << "e" << std::endl; + out << "EOF" << std::endl; + + out.close(); + } + else + { + std::cerr << "ERROR[mln::io::plot::save_image_sh]:"<< filename; + std::cerr << " couldn't be opened !!" << std::endl; + } + + trace::exiting("mln::io::plot::impl::save_image_sh_image1d"); + return result; + } + + //---------------------------------------------------------------------- + // save_image_sh_image3d(const image3d<I>&, const string&) + //---------------------------------------------------------------------- + + + template <typename I> + inline + bool save_image_sh_image3d(const image3d<I>& img, + const std::string& filename) + { + trace::entering("mln::io::plot::impl::save_image_sh_image3d"); + mln_precondition(img.is_valid()); + + std::ofstream out(filename.c_str()); + bool result = !out.fail(); + + if (result) + { + mln_piter(image3d<I>) p(img.domain()); + + // Output data prelude (terminal X11, pointtype 0). + out << "#!/bin/sh" << std::endl; + out << "####################################" << std::endl; + out << "# Columns = (x, y, z, val) #" << std::endl; + out << "####################################" << std::endl; + out << std::endl; + out << "gnuplot <<EOF" << std::endl; + out << "set terminal x11 persist 1" << std::endl; + out << "splot '-' with points palette pointtype 7" << std::endl; + + // Output data. + for_all(p) + { + out << p.row() << " "; + out << p.col() << " "; + out << p.sli() << " "; + out << img(p) << std::endl; + } + + // Close gnuplot data stream. + out << "e" << std::endl; + out << "EOF" << std::endl; + + out.close(); + } + else + { + std::cerr << "ERROR[mln::io::plot::save_image_sh]:"<< filename; + std::cerr << " couldn't be opened !!" << std::endl; + } + + trace::exiting("mln::io::plot::impl::save_image_sh_image3d"); + return result; + } + + } // end of namespace impl + + + //------------------------------------------------------------------------ + // Internal. + //------------------------------------------------------------------------ + + namespace internal + { + template <typename I> + inline + bool save_image_sh_dispatch(const util::array< image1d<I> >& stack, + const std::string& filename) + { + return impl::save_image_sh_array_image1d(stack, filename); + } + + template <typename I> + inline + bool save_image_sh_dispatch(const util::array< + util::array <image1d<I> > >& stack, + const std::string& filename) + { + return impl::save_image_sh_array_array_image1d(stack, filename); + } + + template <typename T> + inline + bool save_image_sh_dispatch( + const util::array<util::array<image1d<algebra::vec<3,T> > > >& stack, + const std::string& filename) + { + return impl::save_image_sh_array_array_image1d_vec3(stack, filename); + } + + template <typename T> + inline + bool save_image_sh_dispatch( + const util::array<util::array<image1d<algebra::vec<2,T> > > >& stack, + const std::string& filename) + { + return impl::save_image_sh_array_array_image1d_vec2(stack, filename); + } + + template <unsigned n> + inline + bool save_image_sh_dispatch(const image2d<value::rgb<n> >& img, + const std::string& filename) + { + return impl::save_image_sh_image2d_rgb(img, filename); + } + + template <typename T> + inline + bool save_image_sh_dispatch(const image2d<value::hsl_<T,T,T> >& img, + const std::string& filename) + { + return impl::save_image_sh_image2d_hsl(img, filename); + } + + template <typename T> + inline + bool save_image_sh_dispatch(const image2d<value::hsi_<T,T,T> >& img, + const std::string& filename) + { + return impl::save_image_sh_image2d_hsi(img, filename); + } + + + template <typename I> + inline + bool save_image_sh_dispatch(const image2d<I>& img, + const std::string& filename) + { + return impl::save_image_sh_image2d(img, filename); + } + + template <typename I> + inline + bool save_image_sh_dispatch(const image1d<I>& img, + const std::string& filename) + { + return impl::save_image_sh_image1d(img, filename); + } + + template <typename I> + inline + bool save_image_sh_dispatch(const image3d<I>& img, + const std::string& filename) + { + return impl::save_image_sh_image3d(img, filename); + } + + template <typename I> + inline + bool save_image_sh_dispatch(const Image<I>& img, + const std::string& filename) + { + return save_image_sh_dispatch(exact(img), filename); + } + + } // end of namespace mln::io::plot::internal + + //------------------------------------------------------------------------ + // Facade. + //------------------------------------------------------------------------ + + template <typename I> + inline + bool save_image_sh(const Image<I>& img, const std::string& filename) + { + trace::entering("mln::io::plot::save_image_sh"); + + bool result = internal::save_image_sh_dispatch(img, filename); + + trace::exiting("mln::io::plot::save_image_sh"); + return result; + } + + template <typename I> + inline + bool save_image_sh(const util::array< image1d<I> >& stack, + const std::string& filename) + { + trace::entering("mln::io::plot::save_image_sh"); + + bool result = internal::save_image_sh_dispatch(stack, filename); + + trace::exiting("mln::io::plot::save_image_sh"); + return result; + } + + template <typename I> + inline + bool save_image_sh(const util::array< util::array< image1d<I> > >& stack, + const std::string& filename) + { + trace::entering("mln::io::plot::save_image_sh"); + + bool result = internal::save_image_sh_dispatch(stack, filename); + + trace::exiting("mln::io::plot::save_image_sh"); + return result; + } + + +#endif // ! MLN_INCLUDE_ONLY + + + } // end of namespace mln::io::plot + + } // end of namespace mln::io + +} // end of namespace mln + +#endif // ! MLN_IO_PLOT_SAVE_IMAGE_SH_HH diff --git a/milena/sandbox/green/mln/math/ceil.hh b/scribo/sandbox/green/mln/math/ceil.hh similarity index 100% copy from milena/sandbox/green/mln/math/ceil.hh copy to scribo/sandbox/green/mln/math/ceil.hh diff --git a/milena/sandbox/green/mln/math/floor.hh b/scribo/sandbox/green/mln/math/floor.hh similarity index 100% copy from milena/sandbox/green/mln/math/floor.hh copy to scribo/sandbox/green/mln/math/floor.hh diff --git a/milena/sandbox/green/mln/value/hsv.hh b/scribo/sandbox/green/mln/value/hsv.hh similarity index 100% copy from milena/sandbox/green/mln/value/hsv.hh copy to scribo/sandbox/green/mln/value/hsv.hh diff --git a/scribo/sandbox/green/mln/value/rg.hh b/scribo/sandbox/green/mln/value/rg.hh new file mode 100644 index 0000000..d083ffd --- /dev/null +++ b/scribo/sandbox/green/mln/value/rg.hh @@ -0,0 +1,175 @@ +// Copyright (C) 2007, 2008, 2009, 2010 EPITA LRDE +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef MLN_VALUE_RG_HH +# define MLN_VALUE_RG_HH + +/// \file +/// +/// \brief Define the red/green vectorial image type. +/// +/// This source implements the red/green (RG) vectorial image type. It +/// is a partial copy of the rgb type. This type doesn't manage +/// anykind of interaction. Its purpose is limited to store a couple +/// of values. Do not use it outside this purpose, i can't garantie +/// the behaviour. +/// +/// The following sample is a typical use of the rg type. +/// +/// #include <mln/accu/stat/histo2d.hh> +/// #include <mln/core/image/image2d.hh> +/// #include <mln/data/compute.hh> +/// #include <mln/data/transform.hh> +/// #include <mln/fun/v2v/rgb_to_rg.hh> +/// #include <mln/img_path.hh> +/// #include <mln/io/ppm/load.hh> +/// #include <mln/value/rg.hh> +/// #include <mln/value/rgb8.hh> +/// +/// int main() +/// { +/// typedef mln::value::rg<8> t_rg8 +/// typedef mln::value::rgb8 t_rgb8; +/// typedef mln::fun::v2v::rgb_to_rg<8> t_rgb_to_rg; +/// typedef mln::image2d<t_rg8> t_image2d_rg8; +/// typedef mln::image2d<t_rgb8> t_image2d_rgb8; +/// typedef mln::image2d<unsigned> t_histo; +/// t_image2d_rgb8 img_rgb8; +/// t_image2d_rg8 img_rg8; +/// t_histo histo; +/// +/// mln::io::ppm::load(img_rgb8, OLENA_IMG_PATH"/lena.ppm"); +/// img_rg8 = mln::data::transform(img_rgb8, t_rgb_to_rg()); +/// histo = mln::data::compute(mln::accu::meta::stat::histo2d(), img_rg8); +/// +/// return 0; +/// } + + +# include <mln/algebra/vec.hh> +# include <mln/value/concept/vectorial.hh> +# include <mln/value/int_u.hh> +# include <mln/value/rgb8.hh> +# include <mln/trait/value_.hh> + + +namespace mln +{ + + namespace value + { + + // Forward declaration. + template <unsigned n> struct rg; + + } // end of namespace mln::value + + namespace trait + { + + template <unsigned n> + struct value_< mln::value::rg<n> > + { + enum { + dim = 2, + nbits = dim * n, + card = mln_value_card_from_(nbits) + }; + + typedef trait::value::nature::vectorial nature; + typedef trait::value::kind::color kind; + typedef trait::value::quant::high quant; + + typedef void comp; + typedef mln::value::int_u<n> comp_0; + typedef mln::value::int_u<n> comp_1; + + static comp_0 get_comp_0(const mln::value::rg<n>& v){return v.red(); } + static comp_1 get_comp_1(const mln::value::rg<n>& v){return v.green();} + + typedef algebra::vec<dim, float> sum; + + static const char* name() + { + static std::string s = std::string("rg").append(1, 8 + '0'); + return s.c_str(); + } + }; + + } // end of namespace mln::trait + + namespace value + { + + /// \brief Define the red/green vectorial image type. + /// + /// Param n defines the quantification used for red/green space. + + template <unsigned n> + struct rg :public mln::value::Vectorial< rg<n> >, + public internal::value_like_< + algebra::vec< 2, int_u<n> >, // Equivalent. + algebra::vec< 2, int_u<n> >, // Encoding. + algebra::vec< 2, int >, // Interoperation. + rg<n> > // Exact. + { + typedef int_u<n> t_red; + typedef int_u<n> t_green; + + int_u<n> red() const {return this->v_[0];} + int_u<n>& red() {return this->v_[0];} + int_u<n> green() const {return this->v_[1];} + int_u<n>& green() {return this->v_[1];} + + /// Constructors + /// \{ + /// \brief Create a rg value. + /// + /// Two constructors exist, the first one do nothing and the second one + /// initializes the red/green components from a rgb value. + rg(){} + rg(const rgb8& val){this->v_[0] = val.red(); this->v_[1] = val.green();} + /// \} + + /// \brief Affect a rg value to this object. + /// \param[in] rhs the value to affect to this object. + /// + /// If the two objects are different, then then copy the + /// underline array of values. + + rg operator=(const rg& rhs) + { + if (&rhs != this) + this->v_ = rhs.v_; + + return *this; + } + }; + + } // end of namespace mln::value + +} // end of namespace mln + +#endif // ! MLN_VALUE_RG_HH diff --git a/scribo/sandbox/green/tests/accu/stat/histo1d/Makefile.am b/scribo/sandbox/green/tests/accu/stat/histo1d/Makefile.am new file mode 100644 index 0000000..77f9015 --- /dev/null +++ b/scribo/sandbox/green/tests/accu/stat/histo1d/Makefile.am @@ -0,0 +1,153 @@ +# +# Generic Makefile +# + +######### +# TOOLS # +######### + +#LOADLIBES= -lboost_filesystem +INCLUDES1= -I$(HOME)/git/olena/scribo/sandbox/green +INCLUDES2= -I$(HOME)/git/olena/milena +INCLUDES= $(INCLUDES1) $(INCLUDES2) +CXXFLAGS= -ggdb -O0 -Wall -W -pedantic -ansi -pipe $(INCLUDES) +#CXXFLAGS= -DNDEBUG -O1 -Wall -W -pedantic -ansi -pipe $(INCLUDES) +#CXXFLAGS= -DNDEBUG -O3 -Wall -W -pedantic -ansi -pipe $(INCLUDES) +ECHO= echo +RM= rm +MKDIR= mkdir -p +CP= cp + +SOURCE_PATTERN= green/tests +BUILD__PATTERN= green/build/tests + + +ifeq ($(findstring $(BUILD__PATTERN),$(PWD)), $(BUILD__PATTERN)) +# Case where make is done from build directory. +SOURCE_DIR= $(subst $(BUILD__PATTERN),$(SOURCE_PATTERN),$(PWD)) +BUILD__DIR= $(PWD)/ +else +# Case where make is done from source directory. +SOURCE_DIR= $(PWD)/ +BUILD__DIR= $(subst $(SOURCE_PATTERN),$(BUILD__PATTERN),$(PWD)) +endif + +SRC= $(notdir $(wildcard $(SOURCE_DIR)/*.cc)) +OLD= $(notdir $(wildcard $(SOURCE_DIR)/*~)) +OBJ= $(patsubst %.cc,%.o,$(SRC)) +SOURCE_MAKEFILE=Makefile.am +BUILD__MAKEFILE=Makefile +TARGET_FILE= $(notdir $(PWD)) +SOURCE_FILES= $(notdir $(wildcard $(SOURCE_DIR)/*.*)) +BUILD__FILES= $(filter-out $(SRC) $(SOURCE_MAKEFILE), $(SOURCE_FILES)) + +BUILD__F_PATH= $(addprefix $(BUILD__DIR)/,$(BUILD__FILES)) +SOURCE_F_PATH= $(addprefix $(SOURCE_DIR)/,$(SOURCE_FILES)) + +BUILD__M_PATH= $(addprefix $(BUILD__DIR)/,$(BUILD__MAKEFILE)) +SOURCE_M_PATH= $(addprefix $(SOURCE_DIR)/,$(SOURCE_MAKEFILE)) + +TARGET_F_PATH= $(addprefix $(BUILD__DIR)/,$(TARGET_FILE)) +OBJ_F_PATH= $(addprefix $(BUILD__DIR)/,$(OBJ)) +SRC_F_PATH= $(addprefix $(SOURCE_DIR)/,$(SRC)) +OLD_F_PATH= $(addprefix $(SOURCE_DIR)/,$(OLD)) + +############# +# BOOTSTRAP # +############# + + +bootstrap: $(BUILD__DIR) $(BUILD__F_PATH) $(BUILD__M_PATH) + +# Create, if nessary, the destination directory +$(BUILD__DIR): + $(MKDIR) $(BUILD__DIR) + +# Copy, if nessary, all the files, except the Makefile.am +$(BUILD__F_PATH): $(SOURCE_F_PATH) + $(CP) $(addprefix $(SOURCE_DIR),$(@F)) $@ + +# Copy if nessary, the Makefile.am into Makefile +$(BUILD__M_PATH): $(SOURCE_M_PATH) + $(CP) $(SOURCE_M_PATH) $(BUILD__M_PATH) + + +####### +# ALL # +####### + +# We assume that the call is done from the build directory. +# With the directive vpath, hidden files are found in the source directory. + +all: $(TARGET_F_PATH) + + +$(TARGET_F_PATH): $(OBJ_F_PATH) + $(LINK.cc) $< $(LOADLIBES) $(LDLIBS) -o $@ + +$(OBJ_F_PATH):$(SRC_F_PATH) + $(COMPILE.cc) $(OUTPUT_OPTION) $< + + +######### +# CLEAN # +######### + +# Force every time the deletion +clean: clean_target clean_obj clean_dst clean_old #clean_make + + +clean_target: + -@$(RM) $(TARGET_F_PATH) &> /dev/null + +clean_obj: + -@$(RM) $(OBJ_F_PATH) &> /dev/null + +clean_dst: + -@$(RM) $(BUILD_F_PATH) &> /dev/null + +clean_make: + -@$(RM) $(BUILD_M_PATH) &> /dev/null + +clean_old: + -@$(RM) $(OLD_F_PATH) &> /dev/null + + +######### +# PRINT # +######### + +print: print_tools print_bootstrap + +print_tools: + @$(ECHO) "HOME = $(HOME)" + @$(ECHO) "INCLUDES = $(INCLUDES)" + @$(ECHO) "CXXFLAGS = $(CXXFLAGS)" + @$(ECHO) "ECHO = $(ECHO)" + @$(ECHO) "RM = $(RM)" + @$(ECHO) "MKDIR = $(MKDIR)" + @$(ECHO) "CP = $(CP)" + @$(ECHO) + +print_bootstrap: + @$(ECHO) "PWD = $(PWD)" + @$(ECHO) "SOURCE_PATTERN = $(SOURCE_PATTERN)" + @$(ECHO) "BUILD__PATTERN = $(BUILD__PATTERN)" + @$(ECHO) "SOURCE_DIR = $(SOURCE_DIR)" + @$(ECHO) "BUILD__DIR = $(BUILD__DIR)" + @$(ECHO) "SOURCE_MAKEFILE = $(SOURCE_MAKEFILE)" + @$(ECHO) "BUILD__MAKEFILE = $(BUILD__MAKEFILE)" + @$(ECHO) "TARGET_FILE = $(TARGET_FILE)" + @$(ECHO) "SOURCE_FILES = $(SOURCE_FILES)" + @$(ECHO) "SOURCE_F_PATH = $(SOURCE_F_PATH)" + @$(ECHO) "BUILD__FILES = $(BUILD__FILES)" + @$(ECHO) "BUILD__F_PATH = $(BUILD__F_PATH)" + @$(ECHO) "BUILD__M_PATH = $(BUILD__M_PATH)" + @$(ECHO) "SOURCE_M_PATH = $(SOURCE_M_PATH)" + @$(ECHO) "SRC = $(SRC)" + @$(ECHO) "OBJ = $(OBJ)" + @$(ECHO) "OLD = $(OLD)" + @$(ECHO) "SRC_F_PATH = $(SRC_F_PATH)" + @$(ECHO) "OBJ_F_PATH = $(OBJ_F_PATH)" + @$(ECHO) "OLD_F_PATH = $(OLD_F_PATH)" + @$(ECHO) diff --git a/scribo/sandbox/green/tests/accu/stat/histo1d/histo1d.cc b/scribo/sandbox/green/tests/accu/stat/histo1d/histo1d.cc new file mode 100644 index 0000000..5a5c4c4 --- /dev/null +++ b/scribo/sandbox/green/tests/accu/stat/histo1d/histo1d.cc @@ -0,0 +1,21 @@ +/// TEST HISTO1D + +#include <mln/accu/stat/histo1d.hh> +#include <mln/data/compute.hh> +#include <mln/core/image/image1d.hh> +#include <mln/core/image/image2d.hh> +#include <mln/img_path.hh> +#include <mln/io/pgm/load.hh> +#include <mln/value/int_u8.hh> + +int main() +{ + typedef mln::value::int_u8 t_int_u8; + mln::image2d<t_int_u8> img; + mln::image1d<unsigned> histo; + + mln::io::pgm::load(img, OLENA_IMG_PATH"/lena.pgm"); + histo = mln::data::compute(mln::accu::meta::stat::histo1d(), img); + + return 0; +} diff --git a/scribo/sandbox/green/use/accu/stat/histo1d/Makefile.am b/scribo/sandbox/green/use/accu/stat/histo1d/Makefile.am new file mode 100644 index 0000000..a96b2e9 --- /dev/null +++ b/scribo/sandbox/green/use/accu/stat/histo1d/Makefile.am @@ -0,0 +1,153 @@ +# +# Generic Makefile +# + +######### +# TOOLS # +######### + +#LOADLIBES= -lboost_filesystem +INCLUDES1= -I$(HOME)/git/olena/scribo/sandbox/green +INCLUDES2= -I$(HOME)/git/olena/milena +INCLUDES= $(INCLUDES1) $(INCLUDES2) +CXXFLAGS= -ggdb -O0 -Wall -W -pedantic -ansi -pipe $(INCLUDES) +#CXXFLAGS= -DNDEBUG -O1 -Wall -W -pedantic -ansi -pipe $(INCLUDES) +#CXXFLAGS= -DNDEBUG -O3 -Wall -W -pedantic -ansi -pipe $(INCLUDES) +ECHO= echo +RM= rm +MKDIR= mkdir -p +CP= cp + +SOURCE_PATTERN= green/use +BUILD__PATTERN= green/build/use + + +ifeq ($(findstring $(BUILD__PATTERN),$(PWD)), $(BUILD__PATTERN)) +# Case where make is done from build directory. +SOURCE_DIR= $(subst $(BUILD__PATTERN),$(SOURCE_PATTERN),$(PWD)) +BUILD__DIR= $(PWD)/ +else +# Case where make is done from source directory. +SOURCE_DIR= $(PWD)/ +BUILD__DIR= $(subst $(SOURCE_PATTERN),$(BUILD__PATTERN),$(PWD)) +endif + +SRC= $(notdir $(wildcard $(SOURCE_DIR)/*.cc)) +OLD= $(notdir $(wildcard $(SOURCE_DIR)/*~)) +OBJ= $(patsubst %.cc,%.o,$(SRC)) +SOURCE_MAKEFILE=Makefile.am +BUILD__MAKEFILE=Makefile +TARGET_FILE= $(notdir $(PWD)) +SOURCE_FILES= $(notdir $(wildcard $(SOURCE_DIR)/*.*)) +BUILD__FILES= $(filter-out $(SRC) $(SOURCE_MAKEFILE), $(SOURCE_FILES)) + +BUILD__F_PATH= $(addprefix $(BUILD__DIR)/,$(BUILD__FILES)) +SOURCE_F_PATH= $(addprefix $(SOURCE_DIR)/,$(SOURCE_FILES)) + +BUILD__M_PATH= $(addprefix $(BUILD__DIR)/,$(BUILD__MAKEFILE)) +SOURCE_M_PATH= $(addprefix $(SOURCE_DIR)/,$(SOURCE_MAKEFILE)) + +TARGET_F_PATH= $(addprefix $(BUILD__DIR)/,$(TARGET_FILE)) +OBJ_F_PATH= $(addprefix $(BUILD__DIR)/,$(OBJ)) +SRC_F_PATH= $(addprefix $(SOURCE_DIR)/,$(SRC)) +OLD_F_PATH= $(addprefix $(SOURCE_DIR)/,$(OLD)) + +############# +# BOOTSTRAP # +############# + + +bootstrap: $(BUILD__DIR) $(BUILD__F_PATH) $(BUILD__M_PATH) + +# Create, if nessary, the destination directory +$(BUILD__DIR): + $(MKDIR) $(BUILD__DIR) + +# Copy, if nessary, all the files, except the Makefile.am +$(BUILD__F_PATH): $(SOURCE_F_PATH) + $(CP) $(addprefix $(SOURCE_DIR),$(@F)) $@ + +# Copy if nessary, the Makefile.am into Makefile +$(BUILD__M_PATH): $(SOURCE_M_PATH) + $(CP) $(SOURCE_M_PATH) $(BUILD__M_PATH) + + +####### +# ALL # +####### + +# We assume that the call is done from the build directory. +# With the directive vpath, hidden files are found in the source directory. + +all: $(TARGET_F_PATH) + + +$(TARGET_F_PATH): $(OBJ_F_PATH) + $(LINK.cc) $< $(LOADLIBES) $(LDLIBS) -o $@ + +$(OBJ_F_PATH):$(SRC_F_PATH) + $(COMPILE.cc) $(OUTPUT_OPTION) $< + + +######### +# CLEAN # +######### + +# Force every time the deletion +clean: clean_target clean_obj clean_dst clean_old #clean_make + + +clean_target: + -@$(RM) $(TARGET_F_PATH) &> /dev/null + +clean_obj: + -@$(RM) $(OBJ_F_PATH) &> /dev/null + +clean_dst: + -@$(RM) $(BUILD_F_PATH) &> /dev/null + +clean_make: + -@$(RM) $(BUILD_M_PATH) &> /dev/null + +clean_old: + -@$(RM) $(OLD_F_PATH) &> /dev/null + + +######### +# PRINT # +######### + +print: print_tools print_bootstrap + +print_tools: + @$(ECHO) "HOME = $(HOME)" + @$(ECHO) "INCLUDES = $(INCLUDES)" + @$(ECHO) "CXXFLAGS = $(CXXFLAGS)" + @$(ECHO) "ECHO = $(ECHO)" + @$(ECHO) "RM = $(RM)" + @$(ECHO) "MKDIR = $(MKDIR)" + @$(ECHO) "CP = $(CP)" + @$(ECHO) + +print_bootstrap: + @$(ECHO) "PWD = $(PWD)" + @$(ECHO) "SOURCE_PATTERN = $(SOURCE_PATTERN)" + @$(ECHO) "BUILD__PATTERN = $(BUILD__PATTERN)" + @$(ECHO) "SOURCE_DIR = $(SOURCE_DIR)" + @$(ECHO) "BUILD__DIR = $(BUILD__DIR)" + @$(ECHO) "SOURCE_MAKEFILE = $(SOURCE_MAKEFILE)" + @$(ECHO) "BUILD__MAKEFILE = $(BUILD__MAKEFILE)" + @$(ECHO) "TARGET_FILE = $(TARGET_FILE)" + @$(ECHO) "SOURCE_FILES = $(SOURCE_FILES)" + @$(ECHO) "SOURCE_F_PATH = $(SOURCE_F_PATH)" + @$(ECHO) "BUILD__FILES = $(BUILD__FILES)" + @$(ECHO) "BUILD__F_PATH = $(BUILD__F_PATH)" + @$(ECHO) "BUILD__M_PATH = $(BUILD__M_PATH)" + @$(ECHO) "SOURCE_M_PATH = $(SOURCE_M_PATH)" + @$(ECHO) "SRC = $(SRC)" + @$(ECHO) "OBJ = $(OBJ)" + @$(ECHO) "OLD = $(OLD)" + @$(ECHO) "SRC_F_PATH = $(SRC_F_PATH)" + @$(ECHO) "OBJ_F_PATH = $(OBJ_F_PATH)" + @$(ECHO) "OLD_F_PATH = $(OLD_F_PATH)" + @$(ECHO) diff --git a/scribo/sandbox/green/use/accu/stat/histo1d/histo1d.cc b/scribo/sandbox/green/use/accu/stat/histo1d/histo1d.cc new file mode 100644 index 0000000..1c6176b --- /dev/null +++ b/scribo/sandbox/green/use/accu/stat/histo1d/histo1d.cc @@ -0,0 +1,24 @@ +/// \file +/// +/// \brief Minimal code for building 1d image histogram version. +/// + +#include <mln/accu/stat/histo1d.hh> +#include <mln/data/compute.hh> +#include <mln/core/image/image1d.hh> +#include <mln/core/image/image2d.hh> +#include <mln/img_path.hh> +#include <mln/io/pgm/load.hh> +#include <mln/value/int_u8.hh> + +int main() +{ + typedef mln::value::int_u8 t_int_u8; + mln::image2d<t_int_u8> img; + mln::image1d<unsigned> histo; + + mln::io::pgm::load(img, OLENA_IMG_PATH"/lena.pgm"); + histo = mln::data::compute(mln::accu::meta::stat::histo1d(), img); + + return 0; +} diff --git a/scribo/sandbox/green/use/accu/stat/histo2d/Makefile.am b/scribo/sandbox/green/use/accu/stat/histo2d/Makefile.am new file mode 100644 index 0000000..a96b2e9 --- /dev/null +++ b/scribo/sandbox/green/use/accu/stat/histo2d/Makefile.am @@ -0,0 +1,153 @@ +# +# Generic Makefile +# + +######### +# TOOLS # +######### + +#LOADLIBES= -lboost_filesystem +INCLUDES1= -I$(HOME)/git/olena/scribo/sandbox/green +INCLUDES2= -I$(HOME)/git/olena/milena +INCLUDES= $(INCLUDES1) $(INCLUDES2) +CXXFLAGS= -ggdb -O0 -Wall -W -pedantic -ansi -pipe $(INCLUDES) +#CXXFLAGS= -DNDEBUG -O1 -Wall -W -pedantic -ansi -pipe $(INCLUDES) +#CXXFLAGS= -DNDEBUG -O3 -Wall -W -pedantic -ansi -pipe $(INCLUDES) +ECHO= echo +RM= rm +MKDIR= mkdir -p +CP= cp + +SOURCE_PATTERN= green/use +BUILD__PATTERN= green/build/use + + +ifeq ($(findstring $(BUILD__PATTERN),$(PWD)), $(BUILD__PATTERN)) +# Case where make is done from build directory. +SOURCE_DIR= $(subst $(BUILD__PATTERN),$(SOURCE_PATTERN),$(PWD)) +BUILD__DIR= $(PWD)/ +else +# Case where make is done from source directory. +SOURCE_DIR= $(PWD)/ +BUILD__DIR= $(subst $(SOURCE_PATTERN),$(BUILD__PATTERN),$(PWD)) +endif + +SRC= $(notdir $(wildcard $(SOURCE_DIR)/*.cc)) +OLD= $(notdir $(wildcard $(SOURCE_DIR)/*~)) +OBJ= $(patsubst %.cc,%.o,$(SRC)) +SOURCE_MAKEFILE=Makefile.am +BUILD__MAKEFILE=Makefile +TARGET_FILE= $(notdir $(PWD)) +SOURCE_FILES= $(notdir $(wildcard $(SOURCE_DIR)/*.*)) +BUILD__FILES= $(filter-out $(SRC) $(SOURCE_MAKEFILE), $(SOURCE_FILES)) + +BUILD__F_PATH= $(addprefix $(BUILD__DIR)/,$(BUILD__FILES)) +SOURCE_F_PATH= $(addprefix $(SOURCE_DIR)/,$(SOURCE_FILES)) + +BUILD__M_PATH= $(addprefix $(BUILD__DIR)/,$(BUILD__MAKEFILE)) +SOURCE_M_PATH= $(addprefix $(SOURCE_DIR)/,$(SOURCE_MAKEFILE)) + +TARGET_F_PATH= $(addprefix $(BUILD__DIR)/,$(TARGET_FILE)) +OBJ_F_PATH= $(addprefix $(BUILD__DIR)/,$(OBJ)) +SRC_F_PATH= $(addprefix $(SOURCE_DIR)/,$(SRC)) +OLD_F_PATH= $(addprefix $(SOURCE_DIR)/,$(OLD)) + +############# +# BOOTSTRAP # +############# + + +bootstrap: $(BUILD__DIR) $(BUILD__F_PATH) $(BUILD__M_PATH) + +# Create, if nessary, the destination directory +$(BUILD__DIR): + $(MKDIR) $(BUILD__DIR) + +# Copy, if nessary, all the files, except the Makefile.am +$(BUILD__F_PATH): $(SOURCE_F_PATH) + $(CP) $(addprefix $(SOURCE_DIR),$(@F)) $@ + +# Copy if nessary, the Makefile.am into Makefile +$(BUILD__M_PATH): $(SOURCE_M_PATH) + $(CP) $(SOURCE_M_PATH) $(BUILD__M_PATH) + + +####### +# ALL # +####### + +# We assume that the call is done from the build directory. +# With the directive vpath, hidden files are found in the source directory. + +all: $(TARGET_F_PATH) + + +$(TARGET_F_PATH): $(OBJ_F_PATH) + $(LINK.cc) $< $(LOADLIBES) $(LDLIBS) -o $@ + +$(OBJ_F_PATH):$(SRC_F_PATH) + $(COMPILE.cc) $(OUTPUT_OPTION) $< + + +######### +# CLEAN # +######### + +# Force every time the deletion +clean: clean_target clean_obj clean_dst clean_old #clean_make + + +clean_target: + -@$(RM) $(TARGET_F_PATH) &> /dev/null + +clean_obj: + -@$(RM) $(OBJ_F_PATH) &> /dev/null + +clean_dst: + -@$(RM) $(BUILD_F_PATH) &> /dev/null + +clean_make: + -@$(RM) $(BUILD_M_PATH) &> /dev/null + +clean_old: + -@$(RM) $(OLD_F_PATH) &> /dev/null + + +######### +# PRINT # +######### + +print: print_tools print_bootstrap + +print_tools: + @$(ECHO) "HOME = $(HOME)" + @$(ECHO) "INCLUDES = $(INCLUDES)" + @$(ECHO) "CXXFLAGS = $(CXXFLAGS)" + @$(ECHO) "ECHO = $(ECHO)" + @$(ECHO) "RM = $(RM)" + @$(ECHO) "MKDIR = $(MKDIR)" + @$(ECHO) "CP = $(CP)" + @$(ECHO) + +print_bootstrap: + @$(ECHO) "PWD = $(PWD)" + @$(ECHO) "SOURCE_PATTERN = $(SOURCE_PATTERN)" + @$(ECHO) "BUILD__PATTERN = $(BUILD__PATTERN)" + @$(ECHO) "SOURCE_DIR = $(SOURCE_DIR)" + @$(ECHO) "BUILD__DIR = $(BUILD__DIR)" + @$(ECHO) "SOURCE_MAKEFILE = $(SOURCE_MAKEFILE)" + @$(ECHO) "BUILD__MAKEFILE = $(BUILD__MAKEFILE)" + @$(ECHO) "TARGET_FILE = $(TARGET_FILE)" + @$(ECHO) "SOURCE_FILES = $(SOURCE_FILES)" + @$(ECHO) "SOURCE_F_PATH = $(SOURCE_F_PATH)" + @$(ECHO) "BUILD__FILES = $(BUILD__FILES)" + @$(ECHO) "BUILD__F_PATH = $(BUILD__F_PATH)" + @$(ECHO) "BUILD__M_PATH = $(BUILD__M_PATH)" + @$(ECHO) "SOURCE_M_PATH = $(SOURCE_M_PATH)" + @$(ECHO) "SRC = $(SRC)" + @$(ECHO) "OBJ = $(OBJ)" + @$(ECHO) "OLD = $(OLD)" + @$(ECHO) "SRC_F_PATH = $(SRC_F_PATH)" + @$(ECHO) "OBJ_F_PATH = $(OBJ_F_PATH)" + @$(ECHO) "OLD_F_PATH = $(OLD_F_PATH)" + @$(ECHO) diff --git a/scribo/sandbox/green/use/accu/stat/histo2d/histo2d.cc b/scribo/sandbox/green/use/accu/stat/histo2d/histo2d.cc new file mode 100644 index 0000000..6369b5a --- /dev/null +++ b/scribo/sandbox/green/use/accu/stat/histo2d/histo2d.cc @@ -0,0 +1,33 @@ +/// \file +/// +/// \brief Minimal code for building 2d image histogram version. +/// + +#include <mln/accu/stat/histo2d.hh> +#include <mln/core/image/image2d.hh> +#include <mln/data/compute.hh> +#include <mln/data/transform.hh> +#include <mln/fun/v2v/rgb_to_rg.hh> +#include <mln/img_path.hh> +#include <mln/io/ppm/load.hh> +#include <mln/value/rg.hh> +#include <mln/value/rgb8.hh> + +int main() +{ + typedef mln::value::rg<8> t_rg8; + typedef mln::value::rgb8 t_rgb8; + typedef mln::fun::v2v::rgb_to_rg<8> t_rgb_to_rg; + typedef mln::image2d<t_rg8> t_image2d_rg8; + typedef mln::image2d<t_rgb8> t_image2d_rgb8; + typedef mln::image2d<unsigned> t_histo; + t_image2d_rgb8 img_rgb8; + t_image2d_rg8 img_rg8; + t_histo histo; + + mln::io::ppm::load(img_rgb8, OLENA_IMG_PATH"/lena.ppm"); + img_rg8 = mln::data::transform(img_rgb8, t_rgb_to_rg()); + histo = mln::data::compute(mln::accu::meta::stat::histo2d(), img_rg8); + + return 0; +} -- 1.5.6.5
participants (1)
-
Yann Jacquelet