Commit ea826a24 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Add the marginal grain filter apps.

    *  apps/misc/CMakeLists.txt,
    *  apps/misc/ppm_grain_filter_marginal.cpp: New.
parent 9c9bc048
......@@ -2,4 +2,5 @@ link_libraries(${FreeImage_LIBRARIES})
add_executable(print_tos_stat print_tos_stat.cpp $<TARGET_OBJECTS:g2-tools>)
add_executable(reconstruct_from_tree reconstruct_from_tree.cpp)
add_executable(ppm_grain_filter_marginal ppm_grain_filter_marginal.cpp)
add_executable(psnr psnr.cpp)
\ No newline at end of file
#include <mln/core/image/image2d.hpp>
#include <mln/core/neighb2d.hpp>
#include <mln/io/imread.hpp>
#include <mln/io/imsave.hpp>
#include <mln/accu/accumulators/count.hpp>
#include <mln/accu/accumulators/mean.hpp>
#include <mln/accu/accumulators/accu_if.hpp>
#include <mln/morpho/tos/ctos.hpp>
#include <mln/morpho/component_tree/accumulate.hpp>
#include <mln/morpho/component_tree/filtering.hpp>
#include <mln/morpho/component_tree/reconstruction.hpp>
#include <apps/tos/addborder.hpp>
#include <apps/tos/Kinterpolate.hpp>
#include <apps/tos/croutines.hpp>
int main(int argc, char** argv)
{
using namespace mln;
if (argc < 4)
{
std::cerr << "Usage: " << argv[0] << " input(color) lambda output(gray)\n"
"Compute a grain filter marginally (on each components independenlty)\n";
std::exit(1);
}
typedef morpho::component_tree<unsigned, image2d<unsigned> > tree_t;
image2d<rgb8> f, F;
image2d<rgb8> out;
unsigned lambda;
io::imread(argv[1], f);
lambda = std::atoi(argv[2]);
box2d domain = f.domain();
f = addborder_marginal(f);
F = immerse_k1(f);
resize(out, F);
for (int i = 0; i < 3; ++i) {
auto tree = morpho::cToS(channel(f, i), c4);
grain_filter_inplace(tree, lambda);
auto vmap = morpho::make_attribute_map_from_image(tree, channel(F,i));
morpho::reconstruction(tree, vmap, channel(out,i));
}
out = Kadjust_to(out, domain);
io::imsave(out, argv[3]);
}
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