Commit 655bfaf4 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Add parent/S image outputs for maxtree comparison algorithms app.

    *  apps/maxtree_comparison/CMakeLists.txt,
    *  apps/maxtree_comparison/filter-cli.cpp,
    *  apps/maxtree_comparison/maxtree-cli.cpp: New.
parent daa19de1
......@@ -30,12 +30,24 @@ add_executable(maxtree_parallel_ufind_line bench_parallel_ufind_line.cpp)
add_executable(maxtree_parallel_ufindrank bench_parallel_ufindrank.cpp)
add_executable(maxtree_parallel_hqueue bench_parallel_hqueue.cpp)
add_executable(maxtree_parallel_pqueue bench_parallel_pqueue.cpp)
add_executable(maxtree_parallel_pqueue_2 bench_parallel_pqueue_2.cpp)
#add_executable(maxtree_parallel_pqueue_3 bench_parallel_pqueue_3.cpp)
target_link_libraries(maxtree_parallel_ufind ${FreeImage_LIBRARIES} ${Boost_PROGRAM_OPTIONS_LIBRARY})
target_link_libraries(maxtree_parallel_ufind_line ${FreeImage_LIBRARIES} ${Boost_PROGRAM_OPTIONS_LIBRARY})
target_link_libraries(maxtree_parallel_ufindrank ${FreeImage_LIBRARIES} ${Boost_PROGRAM_OPTIONS_LIBRARY})
target_link_libraries(maxtree_parallel_hqueue ${FreeImage_LIBRARIES} ${Boost_PROGRAM_OPTIONS_LIBRARY})
target_link_libraries(maxtree_parallel_pqueue ${FreeImage_LIBRARIES} ${Boost_PROGRAM_OPTIONS_LIBRARY})
target_link_libraries(maxtree_parallel_pqueue_2 ${FreeImage_LIBRARIES} ${Boost_PROGRAM_OPTIONS_LIBRARY})
#target_link_libraries(maxtree_parallel_pqueue_3 -lfreeimage ${Boost_PROGRAM_OPTIONS_LIBRARY})
add_executable(bench_maxtree bench_maxtree.cpp)
target_link_libraries(bench_maxtree ${Boost_PROGRAM_OPTIONS_LIBRARY})
add_executable(maxtree-cli maxtree-cli.cpp)
target_link_libraries(maxtree-cli ${FreeImage_LIBRARIES})
add_executable(filter-cli filter-cli.cpp)
target_link_libraries(filter-cli ${FreeImage_LIBRARIES})
#include <mln/core/image/image2d.hpp>
#include <mln/core/neighb2d.hpp>
#include <mln/io/imread.hpp>
#include <mln/io/imsave.hpp>
int main(int argc, char** argv)
{
if (argc < 6) {
std::cerr << "Usage: " << argv[0] << " original parent order lambda out\n"
"original: original image\n"
"parent: parent image\n"
"order: order image\n"
"lambda: area filter size\n"
"out: output image\n";
std::exit(1);
}
using namespace mln;
typedef uint8 V;
image2d<V> f(0);
image2d<unsigned> par(0);
image2d<unsigned> S(0);
io::imread(argv[1], f);
io::imread(argv[2], par);
io::imread(argv[3], S);
image2d<unsigned> area;
resize(area, f).init(0);
// Accumulate
mln_reverse_foreach(unsigned i, S.values()){
area[i]++;
area[par[i]] += area[i];
}
unsigned lambda = std::atoi(argv[4]);
mln_foreach(unsigned i, S.values()) {
if (area[i] < lambda)
f[i] = f[par[i]];
}
io::imsave(f, argv[5]);
}
#include <mln/core/image/image2d.hpp>
#include <mln/core/neighb2d.hpp>
#include <mln/morpho/maxtree_pqueue_parallel.hpp>
#include <mln/io/imread.hpp>
#include <mln/io/imsave.hpp>
int main(int argc, char** argv)
{
if (argc < 5) {
std::cerr << "Usage: " << argv[0] << " input (4|8) parent.tiff order.tiff\n"
"input: input image (32bit unsigned)\n"
"(4|8): connexity (either 4 or 8)\n"
"parent.tiff: output parent image\n"
"order.tiff: output order image\n";
std::exit(1);
}
using namespace mln;
typedef uint8 V;
image2d<V> f;
io::imread(argv[1], f);
image2d<unsigned> parent;
std::vector<unsigned> S;
int connexity = std::atoi(argv[2]);
if (connexity == 4) {
std::tie(parent, S) = morpho::impl::parallel::maxtree_pqueue(f, c4);
} else if (connexity == 8) {
std::tie(parent, S) = morpho::impl::parallel::maxtree_pqueue(f, c8);
} else {
std::cerr << "Connexity must be 4 or 8\n";
std::exit(1);
}
unsigned nr = f.nrows();
unsigned nc = f.ncols();
image2d<unsigned> par(nr, nc, 0);
image2d<unsigned> order(nr, nc, 0);
{
point2d p;
{
mln_iter(vin, parent.values());
mln_iter(vout, par.values());
mln_forall(vin, vout) {
p = f.point_at_index(*vin);
*vout = p[0] * nc + p[1];
};
}
{
mln_iter(vin, S);
mln_iter(vout, order.values());
mln_forall(vin, vout) {
p = f.point_at_index(*vin);
*vout = p[0] * nc + p[1];
}
}
}
io::imsave(par, argv[3]);
io::imsave(order, argv[4]);
}
Markdown is supported
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