Commit ad8c64bf authored by Roland Levillain's avatar Roland Levillain
Browse files

apps/bench: Comparison on dilation.

	* apps/bench/dilation-lena.cc: New.
	* apps/bench/lena1024.pgm: New.
	* apps/bench/Makefile.am (EXTRA_DIST): Add lena1024.pgm.
	(noinst_PROGRAMS): Add dilation-lena.
	(MOSTLYCLEANFILES): Update.
parent d9fc1df7
2010-12-13 Roland Levillain <roland@lrde.epita.fr>
apps/bench: Comparison on dilation.
* apps/bench/dilation-lena.cc: New.
* apps/bench/lena1024.pgm: New.
* apps/bench/Makefile.am (EXTRA_DIST): Add lena1024.pgm.
(noinst_PROGRAMS): Add dilation-lena.
(MOSTLYCLEANFILES): Update.
2010-12-06 Roland Levillain <roland@lrde.epita.fr>
 
apps/bench: More (specialized) test/bench gradient on lena.pgm.
......@@ -16,7 +16,10 @@
include $(top_srcdir)/milena/apps/apps.mk
EXTRA_DIST = lena1024.pgm
noinst_PROGRAMS = \
dilation-lena \
gradient-lena \
gradient-spe-lena
......@@ -25,6 +28,10 @@ noinst_HEADERS = \
minus.hh
MOSTLYCLEANFILES = \
dilation-lena-out-spe.pgm \
dilation-lena-out-gen.pgm \
dilation-lena-out-fast.pgm \
dilation-lena-out-faster.pgm \
gradient-lena-out.pgm \
gradient-spe-lena-out-0.pgm \
gradient-spe-lena-out-1.pgm \
......
// Copyright (C) 2010 EPITA Research and Development Laboratory (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.
#include <iostream>
#include <mln/core/image/image2d.hh>
#include <mln/core/alias/window2d.hh>
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
#include <mln/value/int_u8.hh>
#include <mln/accu/stat/max.hh>
#include <mln/util/timer.hh>
#include "apps/data.hh"
namespace nongen
{
typedef mln::image2d<mln::value::int_u8> image;
image dilation(const image& input)
{
image output (input.nrows(), input.ncols()); // Initialize an output image.
for (unsigned int r = 0; r < input.nrows(); ++r) // Iterate on rows.
for (unsigned int c = 0; c < input.ncols(); ++c)
{ // Iterate on columns.
unsigned char sup = input.at_(r, c);
if (r != 0 && input.at_(r-1, c) > sup) sup = input.at_(r-1, c);
if (r != input.nrows() - 1 && input.at_(r+1, c) > sup) sup = input.at_(r+1, c);
if (c != 0 && input.at_(r, c-1) > sup) sup = input.at_(r, c-1);
if (c != input.ncols() - 1 && input.at_(r, c+1) > sup) sup = input.at_(r, c+1);
output.at_(r, c) = sup;
}
return output;
}
}
namespace gen
{
using namespace mln;
template <typename I, typename W>
mln_concrete(I) dilation(const I& input, const W& win)
{
mln_concrete(I) output; initialize(output, input); // Initialize output.
mln_piter(I) p(input.domain()); // Iterator on sites of the domain of `input'.
mln_qiter(W) q(win, p); // Iterator on the neighbors of `p' w.r.t. `win'.
for_all(p)
{
// FIXME: Cheat: replace the accu::supremum by a maximum.
mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum.
for_all(q) if (input.has(q))
sup.take(input(q));
output(p) = sup.to_result();
}
return output;
}
}
namespace fast
{
using namespace mln;
template <typename I, typename W>
mln_concrete(I) dilation(const I& input, const W& win)
{
typedef mln_concrete(I) O;
O output; initialize(output, input); // Initialize output.
mln_pixter(const I) pi(input); // Iterator on the pixels of `input'.
mln_pixter(O) po(output); // Iterator on the pixels of `output'.
mln_qixter(const I, W) q(pi, win); // Iterator on the neighbors of `p' w.r.t. `win'.
for_all_2(pi, po)
{
// FIXME: Cheat: replace the accu::supremum by a maximum.
mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum.
for_all(q)
sup.take(q.val());
po.val() = sup.to_result();
}
return output;
}
}
namespace faster
{
using namespace mln;
template <typename I, typename W>
mln_concrete(I) dilation(const I& input, const W& win)
{
typedef mln_concrete(I) O;
O output; initialize(output, input); // Initialize output.
mln_pixter(const I) p(input); // Iterator on the pixels of `input'.
mln_qixter(const I, W) q(p, win); // Iterator on the neighbors of `p' w.r.t. `win'.
for_all(p)
{
// FIXME: Cheat: replace the accu::supremum by a maximum.
mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum.
for_all(q)
sup.take(q.val());
*(output.buffer() + p.offset()) = sup.to_result();
}
return output;
}
}
int main()
{
using namespace mln;
using value::int_u8;
border::thickness = 1;
image2d<int_u8> lena;
io::pgm::load(lena, MLN_APPS_DIR "/bench/lena1024.pgm");
image2d<int_u8> d;
util::timer t;
t.start();
d = nongen::dilation(lena);
t.stop();
std::cout << t.read() << std::endl;
io::pgm::save(d, "dilation-lena-out-spe.pgm");
t.start();
d = gen::dilation(lena, win_c4p());
t.stop();
std::cout << t.read() << std::endl;
io::pgm::save(d, "dilation-lena-out-gen.pgm");
t.start();
d = fast::dilation(lena, win_c4p());
t.stop();
std::cout << t.read() << std::endl;
io::pgm::save(d, "dilation-lena-out-fast.pgm");
t.start();
d = faster::dilation(lena, win_c4p());
t.stop();
std::cout << t.read() << std::endl;
io::pgm::save(d, "dilation-lena-out-faster.pgm");
}
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment