Commit 776604e8 authored by Fabien Freling's avatar Fabien Freling
Browse files

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.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@4563 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent fc7b7d50
2009-09-29 Fabien Freling <fabien.freling@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.
2009-09-28 Yann Jacquelet <jacquelet@lrde.epita.fr>
Prepare kmean demo for theo. Work in progress.
......
________
< 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/
___________
< TODO list >
-----------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
[X] Create values between pixels
[X] Watershed between pixels
[ ] Sum of watershed slices
[X] Fix display_edge
[ ] Save edges image
#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;
}
#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;
}
......@@ -10,43 +10,51 @@
#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;
if (value.hue() > (hue - range) && value.hue() < (hue + range))
{
truth += 1.f - ((math::diff_abs(hue, value.hue()) / 100.0) / (range / 100));
}
return false;
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;
if (value.hue() > 60 && value.hue() < 180)
{
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 value.sat();
}
if (proba > 1.f)
proba = 1.f;
return (int_u8) (proba * 255);
inline
float
lum_truth(hsl_<float, float, float> value)
{
return 1.f - 2 * (math::diff_abs(0.5f, value.lum()));
}
int main(int argc, char* argv[])
{
if (argc != 3)
......@@ -58,17 +66,33 @@ int main(int argc, char* argv[])
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;
}
#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;
}
......@@ -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 mln
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 @@ namespace mln
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 @@ namespace mln
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 @@ namespace mln
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;
}
......
......@@ -10,3 +10,6 @@ tiled2d: tiled2d.cc
disk_ima: disk_ima.cc
${CXX} ${CXXFLAGS} ${INC} $^ -o disk_ima
ima2d: ima2d.cc
${CXX} ${CXXFLAGS} ${INC} $^ -o ima2d
#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;
}
}
......@@ -2,6 +2,7 @@
make disk_ima
make tiled2d
make ima2d
echo "---"
echo "Disk Image Performance"
......@@ -10,3 +11,7 @@ time ./disk_ima $1
echo "---"
echo "Tiled Image Performance"
time ./tiled2d $1
echo "---"
echo "Image 2D Performance"
time ./ima2d $1
......@@ -7,6 +7,8 @@
#include <mln/debug/quiet.hh>
#include "bench.hh"
using namespace mln;
using value::rgb8;
......@@ -20,36 +22,11 @@ int main(int argc, char* argv[])
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));
point2d pt(0, 1);
mln_assertion(tiled_ima(pt) == ima(pt));
point2d pt2(1, 0);
mln_assertion(tiled_ima(pt2) == ima(pt2));
disk_ima<rgb8> ima;
point2d pt3(1, 1);
mln_assertion(tiled_ima(pt3) == ima(pt3));*/
io::ppm::load(ima, argv[1]);
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;
}
#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;
}
......@@ -7,6 +7,8 @@
#include <mln/debug/quiet.hh>
#include "bench.hh"