URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-09-29 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Update benchmark for types of image.
* fabien/README: Explain hierarchy of the sandbox.
* fabien/TODO: Remove.
* fabien/bin/dumpl16_to_colorize.cc: New bin tool.
* fabien/bin/dumpl8_to_colorize.cc: New bin tool.
* fabien/igr/color/find_color.cc: Update color detection.
* fabien/magick/tiled_image.cc: Add draft of tiled image using
ImageMagick.
* fabien/mln/test/conversion.hh: Update conversion test.
* fabien/tests/core/image/Makefile,
* fabien/tests/core/image/bench.hh,
* fabien/tests/core/image/bench.sh,
* fabien/tests/core/image/disk_ima.cc,
* fabien/tests/core/image/ima2d.cc,
* fabien/tests/core/image/tiled2d.cc:
Update performance benchmark for different types of image.
---
README | 114 +++++++++++++++++++++++++++++++++++++++++++
bin/dumpl16_to_colorize.cc | 64 ++++++++++++++++++++++++
bin/dumpl8_to_colorize.cc | 62 +++++++++++++++++++++++
igr/color/find_color.cc | 62 ++++++++++++++++-------
magick/tiled_image.cc | 38 ++++++++++++++
mln/test/conversion.hh | 14 +++--
tests/core/image/Makefile | 3 +
tests/core/image/bench.hh | 19 +++++++
tests/core/image/bench.sh | 5 +
tests/core/image/disk_ima.cc | 33 +-----------
tests/core/image/ima2d.cc | 31 +++++++++++
tests/core/image/tiled2d.cc | 29 +---------
12 files changed, 396 insertions(+), 78 deletions(-)
Index: trunk/milena/sandbox/fabien/TODO (deleted)
===================================================================
Index: trunk/milena/sandbox/fabien/igr/color/find_color.cc
===================================================================
--- trunk/milena/sandbox/fabien/igr/color/find_color.cc (revision 4562)
+++ trunk/milena/sandbox/fabien/igr/color/find_color.cc (revision 4563)
@@ -10,42 +10,50 @@
#include <mln/convert/from_to.hh>
#include <mln/data/convert.hh>
#include <mln/math/diff_abs.hh>
+#include <mln/math/min.hh>
using namespace mln;
using value::rgb8;
using value::hsl_;
using value::int_u8;
+#define GREEN 120.f
+#define BLUE 240.f
+
inline
-bool
-is_green(hsl_<float, float, float> value)
+float
+hue_truth(hsl_<float, float, float> value, float hue, float range)
{
- if (value.hue() > 75 && value.hue() < 170 &&
- value.sat() > 0.5 &&
- value.lum() > 0.3 && value.lum() < 0.7)
- return true;
+ float truth = 0.0;
- return false;
+ if (value.hue() > (hue - range) && value.hue() < (hue + range))
+ {
+ truth += 1.f - ((math::diff_abs(hue, value.hue()) / 100.0) / (range / 100));
+ }
+
+ if (truth > 1.f)
+ truth = 1.f;
+ if (truth < 0.f)
+ truth = 0.f;
+ return truth;
}
inline
-int_u8
-how_green(hsl_<float, float, float> value)
+float
+sat_truth(hsl_<float, float, float> value)
{
- float proba = 0.0;
+ return value.sat();
+}
- if (value.hue() > 60 && value.hue() < 180)
+inline
+float
+lum_truth(hsl_<float, float, float> value)
{
- proba += 1.f - ((math::diff_abs(120.f, value.hue()) / 100.0) / 0.6);
- proba *= value.sat();
- proba *= 1.f - (math::diff_abs(0.5f, value.lum()));
+ return 1.f - 2 * (math::diff_abs(0.5f, value.lum()));
}
- if (proba > 1.f)
- proba = 1.f;
- return (int_u8) (proba * 255);
-}
+
int main(int argc, char* argv[])
{
@@ -58,17 +66,33 @@
image2d<rgb8> input;
io::ppm::load(input, argv[1]);
image2d<int_u8> output;
+
initialize(output, input);
+ image2d<int_u8> hue_ima;
+ initialize(hue_ima, input);
+ image2d<int_u8> sl_p_ima;
+ initialize(sl_p_ima, input);
+ image2d<int_u8> sl_m_ima;
+ initialize(sl_m_ima, input);
typedef image2d<hsl_<float, float, float> > H;
H ima_hsl = data::convert(hsl_<float, float, float>(), input);
mln_piter_(H) p(ima_hsl.domain());
for_all(p)
{
- output(p) = how_green(ima_hsl(p));
+ float truth = 0.0;
+ truth = hue_truth(ima_hsl(p), GREEN, 60.f) * sat_truth(ima_hsl(p)) *
lum_truth(ima_hsl(p));
+ output(p) = (int_u8) (truth * 255);
+
+ hue_ima(p) = (int_u8) (hue_truth(ima_hsl(p), GREEN, 60.f) * 255);
+ sl_p_ima(p) = (int_u8) (sat_truth(ima_hsl(p)) * lum_truth(ima_hsl(p)) * 255);
+ sl_m_ima(p) = (int_u8) (math::min(sat_truth(ima_hsl(p)), lum_truth(ima_hsl(p))) *
255);
}
io::pgm::save(output, argv[2]);
+ io::pgm::save(hue_ima, "hue.pgm");
+ io::pgm::save(sl_p_ima, "sl_p.pgm");
+ io::pgm::save(sl_m_ima, "sl_m.pgm");
return 0;
}
Index: trunk/milena/sandbox/fabien/tests/core/image/ima2d.cc
===================================================================
--- trunk/milena/sandbox/fabien/tests/core/image/ima2d.cc (revision 0)
+++ trunk/milena/sandbox/fabien/tests/core/image/ima2d.cc (revision 4563)
@@ -0,0 +1,31 @@
+#include <mln/core/image/image2d.hh>
+
+#include <mln/io/ppm/load.hh>
+#include <mln/literal/colors.hh>
+#include <mln/value/rgb8.hh>
+
+#include <mln/debug/quiet.hh>
+
+#include "bench.hh"
+
+
+using namespace mln;
+using value::rgb8;
+
+
+int main(int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << " input"
<< std::endl;
+ return 1;
+ }
+
+ image2d<rgb8> ima;
+
+ io::ppm::load(ima, argv[1]);
+
+ bench_disk_perf(ima);
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/tests/core/image/disk_ima.cc
===================================================================
--- trunk/milena/sandbox/fabien/tests/core/image/disk_ima.cc (revision 4562)
+++ trunk/milena/sandbox/fabien/tests/core/image/disk_ima.cc (revision 4563)
@@ -7,6 +7,8 @@
#include <mln/debug/quiet.hh>
+#include "bench.hh"
+
using namespace mln;
using value::rgb8;
@@ -20,36 +22,11 @@
return 1;
}
- //image2d<rgb8> ima;
- disk_ima<rgb8> tiled_ima;
-
- //io::ppm::load(ima, argv[1]);
- io::ppm::load(tiled_ima, argv[1]);
-
- //std::cout << "bbox: " << tiled_ima.bbox() << std::endl;
- //std::cout << "file: " << tiled_ima.file_() << std::endl;
-
- /*point2d pt0(0, 0);
- mln_assertion(tiled_ima(pt0) == ima(pt0));
+ disk_ima<rgb8> ima;
- point2d pt(0, 1);
- mln_assertion(tiled_ima(pt) == ima(pt));
+ io::ppm::load(ima, argv[1]);
- point2d pt2(1, 0);
- mln_assertion(tiled_ima(pt2) == ima(pt2));
-
- point2d pt3(1, 1);
- mln_assertion(tiled_ima(pt3) == ima(pt3));*/
-
- mln_piter_(disk_ima<rgb8>) p(tiled_ima.domain());
- for_all(p)
- if (p.row() % 16 == 0)
- {
- //std::cout << tiled_ima(p);
- tiled_ima(p) = literal::green;
- //std::cout << " -> " << tiled_ima(p) << std::endl;
- //mln_assertion(tiled_ima(p) == ima(p));
- }
+ bench_disk_perf(ima);
return 0;
}
Index: trunk/milena/sandbox/fabien/tests/core/image/bench.sh
===================================================================
--- trunk/milena/sandbox/fabien/tests/core/image/bench.sh (revision 4562)
+++ trunk/milena/sandbox/fabien/tests/core/image/bench.sh (revision 4563)
@@ -2,6 +2,7 @@
make disk_ima
make tiled2d
+make ima2d
echo "---"
echo "Disk Image Performance"
@@ -10,3 +11,7 @@
echo "---"
echo "Tiled Image Performance"
time ./tiled2d $1
+
+echo "---"
+echo "Image 2D Performance"
+time ./ima2d $1
Index: trunk/milena/sandbox/fabien/tests/core/image/tiled2d.cc
===================================================================
--- trunk/milena/sandbox/fabien/tests/core/image/tiled2d.cc (revision 4562)
+++ trunk/milena/sandbox/fabien/tests/core/image/tiled2d.cc (revision 4563)
@@ -7,6 +7,8 @@
#include <mln/debug/quiet.hh>
+#include "bench.hh"
+
using namespace mln;
using value::rgb8;
@@ -20,36 +22,11 @@
return 1;
}
- //image2d<rgb8> ima;
tiled2d<rgb8> tiled_ima;
- //io::ppm::load(ima, argv[1]);
io::ppm::load(tiled_ima, argv[1]);
- //std::cout << "bbox: " << tiled_ima.bbox() << std::endl;
- //std::cout << "file: " << tiled_ima.file_() << std::endl;
-
- /*point2d pt0(0, 0);
- mln_assertion(tiled_ima(pt0) == ima(pt0));
-
- point2d pt(0, 1);
- mln_assertion(tiled_ima(pt) == ima(pt));
-
- point2d pt2(1, 0);
- mln_assertion(tiled_ima(pt2) == ima(pt2));
-
- point2d pt3(1, 1);
- mln_assertion(tiled_ima(pt3) == ima(pt3));*/
-
- mln_piter_(tiled2d<rgb8>) p(tiled_ima.domain());
- for_all(p)
- if (p.row() % 16 == 0)
- {
- //std::cout << tiled_ima(p);
- tiled_ima(p) = literal::green;
- //std::cout << " -> " << tiled_ima(p) << std::endl;
- //mln_assertion(tiled_ima(p) == ima(p));
- }
+ bench_disk_perf(tiled_ima);
return 0;
}
Index: trunk/milena/sandbox/fabien/tests/core/image/Makefile
===================================================================
--- trunk/milena/sandbox/fabien/tests/core/image/Makefile (revision 4562)
+++ trunk/milena/sandbox/fabien/tests/core/image/Makefile (revision 4563)
@@ -10,3 +10,6 @@
disk_ima: disk_ima.cc
${CXX} ${CXXFLAGS} ${INC} $^ -o disk_ima
+
+ima2d: ima2d.cc
+ ${CXX} ${CXXFLAGS} ${INC} $^ -o ima2d
Index: trunk/milena/sandbox/fabien/tests/core/image/bench.hh
===================================================================
--- trunk/milena/sandbox/fabien/tests/core/image/bench.hh (revision 0)
+++ trunk/milena/sandbox/fabien/tests/core/image/bench.hh (revision 4563)
@@ -0,0 +1,19 @@
+#include <mln/core/concept/image.hh>
+#include <mln/literal/colors.hh>
+
+using namespace mln;
+
+template <typename I>
+inline
+void
+bench_disk_perf(Image<I>& ima_)
+{
+ I& ima = exact(ima_);
+
+ mln_piter(I) p(ima.domain());
+ for_all(p)
+ if (p.row() % 16 == 0)
+ {
+ ima(p) = literal::green;
+ }
+}
Index: trunk/milena/sandbox/fabien/mln/test/conversion.hh
===================================================================
--- trunk/milena/sandbox/fabien/mln/test/conversion.hh (revision 4562)
+++ trunk/milena/sandbox/fabien/mln/test/conversion.hh (revision 4563)
@@ -33,6 +33,8 @@
# include <mln/core/concept/image.hh>
# include <mln/data/convert.hh>
# include <mln/math/diff_abs.hh>
+# include <mln/math/sqr.hh>
+# include <mln/math/sqrt.hh>
# include <mln/value/rgb8.hh>
@@ -60,6 +62,8 @@
namespace impl
{
+ /// Distance between two color values.
+ /// We have to specialized it for each type of color.
template <typename V>
inline
float color_distance(const V& color1, const V& color2)
@@ -67,6 +71,8 @@
return -1.0; // FIXME
}
+ /// Distance between two RGB values.
+ /// \return Value is normalized ([0..1]).
template <>
inline
float color_distance<value::rgb8>(const value::rgb8& color1, const
value::rgb8& color2)
@@ -82,8 +88,7 @@
return dist;
}
- /// \return The percentage of points which value is not preserved.
- /// The return value is normalized ([0..1]).
+ /// \return Root mean square.
template <typename I, typename V>
inline
float conversion_(const I& ima, const V& value)
@@ -97,12 +102,11 @@
mln_piter(I) p(ima.domain());
for_all(p)
{
- delta += color_distance(ima(p), output(p));
- //if (ima(p) != output(p))
- // delta += 1.0;
+ delta += math::sqr(color_distance(ima(p), output(p)));
}
delta /= ima.nelements();
+ delta = math::sqrt(delta);
return delta;
}
Index: trunk/milena/sandbox/fabien/bin/dumpl16_to_colorize.cc
===================================================================
--- trunk/milena/sandbox/fabien/bin/dumpl16_to_colorize.cc (revision 0)
+++ trunk/milena/sandbox/fabien/bin/dumpl16_to_colorize.cc (revision 4563)
@@ -0,0 +1,64 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/make/image3d.hh>
+#include <mln/debug/slices_2d.hh>
+#include <mln/debug/colorize.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u12.hh>
+#include <mln/value/label_16.hh>
+#include <mln/value/label_32.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/core/concept/literal.hh>
+
+#include <mln/io/dump/load.hh>
+#include <mln/io/ppm/save.hh>
+
+
+int usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.dump dim
nbasins output.ppm" << std::endl;
+ return 1;
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::int_u12;
+ using value::label_16;
+ using value::label_32;
+ using value::rgb8;
+ typedef label_16 L;
+
+ if (argc != 5)
+ return usage(argv);
+
+ unsigned dim = atoi(argv[2]);
+ unsigned nbasins = atoi(argv[3]);
+ if (dim != 2 && dim != 3)
+ {
+ std::cout << "<dimensions> invalid" << std::endl;
+ return 1;
+ }
+
+ if (dim == 2)
+ {
+ image2d<L> ima2d;
+ io::dump::load(ima2d, argv[1]);
+ image2d<rgb8> ima_rgb = debug::colorize(rgb8(), ima2d, nbasins);
+ io::ppm::save(ima_rgb, argv[4]);
+ }
+ else
+ {
+ image3d<L> ima3d;
+ io::dump::load(ima3d, argv[1]);
+ image3d<rgb8> ima_rgb = debug::colorize(rgb8(), ima3d, nbasins);
+
+ image2d<rgb8> ima_result = debug::slices_2d(ima_rgb, 1.f, literal::black);
+ io::ppm::save(ima_result, argv[4]);
+ }
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/bin/dumpl8_to_colorize.cc
===================================================================
--- trunk/milena/sandbox/fabien/bin/dumpl8_to_colorize.cc (revision 0)
+++ trunk/milena/sandbox/fabien/bin/dumpl8_to_colorize.cc (revision 4563)
@@ -0,0 +1,62 @@
+#include <mln/core/image/image2d.hh>
+#include <mln/make/image3d.hh>
+#include <mln/debug/slices_2d.hh>
+#include <mln/labeling/colorize.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_u12.hh>
+#include <mln/value/label_8.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/core/concept/literal.hh>
+
+#include <mln/io/dump/load.hh>
+#include <mln/io/ppm/save.hh>
+
+
+int usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.dump dim
nbasins output.ppm" << std::endl;
+ return 1;
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::int_u12;
+ using value::label_8;
+ using value::rgb8;
+ typedef label_8 L;
+
+ if (argc != 5)
+ return usage(argv);
+
+ unsigned dim = atoi(argv[2]);
+ unsigned nbasins = atoi(argv[3]);
+ if (dim != 2 && dim != 3)
+ {
+ std::cout << "<dimensions> invalid" << std::endl;
+ return 1;
+ }
+
+ if (dim == 2)
+ {
+ image2d<L> ima2d;
+ io::dump::load(ima2d, argv[1]);
+ image2d<rgb8> ima_rgb = labeling::colorize(rgb8(), ima2d, nbasins);
+ io::ppm::save(ima_rgb, argv[4]);
+ }
+ else
+ {
+ image3d<L> ima3d;
+ io::dump::load(ima3d, argv[1]);
+ image3d<rgb8> ima_rgb = labeling::colorize(rgb8(), ima3d, nbasins);
+
+ image2d<rgb8> ima_result = debug::slices_2d(ima_rgb, 1.f, literal::black);
+ io::ppm::save(ima_result, argv[4]);
+ }
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/magick/tiled_image.cc
===================================================================
--- trunk/milena/sandbox/fabien/magick/tiled_image.cc (revision 0)
+++ trunk/milena/sandbox/fabien/magick/tiled_image.cc (revision 4563)
@@ -0,0 +1,38 @@
+#include <Magick++.h>
+#include <iostream>
+
+
+int main(int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << "
filename" << std::endl;
+ return 1;
+ }
+
+ std::cout << "Loading image..." << std::endl;
+ Magick::Image image(argv[1]);
+ std::cout << "Loading done." << std::endl;
+
+ std::cout << "columns: " << image.columns() << std::endl;
+ std::cout << "rows: " << image.rows() << std::endl;
+
+ unsigned ncols = image.columns();
+ unsigned nrows = image.rows();
+ const Magick::PixelPacket *pixel_cache;
+ unsigned count = 0;
+ for (unsigned row = 0; row < nrows; row += 1024)
+ {
+ std::cout << "Processing row #" << row << std::endl;
+ pixel_cache = image.getConstPixels(0, 0, ncols / 128, row);
+ for (unsigned col = 0; col < ncols / 128; col += 256)
+ {
+ const Magick::PixelPacket *pixel = pixel_cache + col;
+ ++count;
+ }
+ }
+
+ std::cout << "nbr pixels: " << count << std::endl;
+
+ return 0;
+}
Index: trunk/milena/sandbox/fabien/README
===================================================================
--- trunk/milena/sandbox/fabien/README (revision 0)
+++ trunk/milena/sandbox/fabien/README (revision 4563)
@@ -0,0 +1,114 @@
+ ________
+< README >
+ --------
+ \ ^__^
+ \ (oo)\_______
+ (__)\ )\/\
+ ||----w |
+ || ||
+
+
+
+
+./bin/
+======
+Divers binaires pour convertir des images.
+Par exemple, `dumpi12_to_pgm' convertit un dump en int_u12 en une image PGM.
+
+./binarization/ (Deprecated)
+===============
+
+./dcmtk/
+========
+Support incomplet de la bibliotheque DCMTK.
+Abandonne au profit de GDCM (bibliotheque pour le format DICOM).
+
+./igr/
+======
+
+ ./igr/color
+ ===========
+
+ ./igr/fixed_seg
+ ===============
+
+ ./igr/mat2mln
+ =============
+
+ ./igr/plot_points
+ =================
+
+ ./igr/point_filtering
+ =====================
+
+ ./igr/smooth_fixed_seg
+ ======================
+
+ ./igr/space_smooth
+ ==================
+
+ ./igr/time_smooth
+ =================
+
+
+./magick/ (Deprecated)
+=========
+Premiers tests pour support ImageMagick.
+Ce support a ete deplace dans mln/io/magick
+
+./mln/
+======
+
+ ./mln/canvas/browsing/
+ ======================
+ Brouillon pour support du `snake' en n dimensions.
+ Peut etre ignore.
+
+ ./mln/core/image/
+ =================
+ Nouveaux types d'images.
+ disk_ima = image avec access direct au disque dur
+ tiled2d = image 2D avec cache
+ cache = utilise par `tiled2d', gere la politique de cache
+ page = utilise par `cache', gere la forme d'un bloc de donnees
+ magick_tiled2d = brouillon pour image avec cache gere par ImageMagick
+
+ ./mln/data/
+ ===========
+ Brouillon pour support du `fast_median' avec un autre canvas.
+ Peut etre ignore.
+
+ ./mln/debug/
+ ============
+ int2rgb : convertit un int en une valeur RGB afin de pouvoir l'afficher
+
+ ./mln/display/
+ ==============
+ display_region : cree une image avec les lignes de watershed remplacees
+ par une color precise afin d'exhiber les regions
+
+ ./mln/io/pnm/
+ =============
+ Support de la lecture de PNM pour la creation d'image mappees sur disque
+ (`disk_ima').
+
+ ./mln/test/
+ ===========
+ Teste la conversion d'un type de valeur de couleur dans un autre espace
+ de couleur. Renvoie le "root mean square".
+
+ ./mln/upsampling/
+ =================
+ Implementations des HQx.
+
+ ./mln/world/inter_pixel/
+ ========================
+ display_region : cree une image pour aider a la visualization, a ete remplace
+ par la demo d'inter_pixel
+ is_zero_face : implement zero-face
+
+
+
+./tests/
+========
+Tests pour les sources situees dans ./mln/