Commit 92aad730 authored by Edwin Carlinet's avatar Edwin Carlinet Committed by ecarlinet
Browse files

Add color grain filter APP.

parent f969293e
......@@ -3,6 +3,8 @@ 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(grain_filter_color grain_filter_color.cpp)
add_executable(psnr psnr.cpp)
add_executable(compute_depth compute_depth.cpp)
#include <mln/core/image/image2d.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/component_tree/io.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/topology.hpp>
#include <apps/tos/Kinterpolate.hpp>
int main(int argc, char** argv)
using namespace mln;
if (argc < 5)
std::cerr << "Usage: " << argv[0] << " input(.jpg|.png) tree lambda output(.jpg|.png)\n"
"Note: Non-filtered pixels are left with their original color. Filtered pixels"
"are set to the average color of the least survival node."
<< std::endl;
typedef morpho::component_tree<unsigned, image2d<unsigned> > tree_t;
image2d<rgb8> f;
tree_t tree;
unsigned lambda;
io::imread(argv[1], f);
morpho::load(argv[2], tree);
lambda = std::atoi(argv[3]);
image2d<rgb8> F = Kadjust_to(f, tree._get_data()->m_pmap.domain());
auto isface2 = [](const point2d& p) { return K1::is_face_2(p); };
typedef accu::accumulators::accu_if< accu::accumulators::count<>, decltype(isface2), point2d> ACC;
ACC accu(accu::accumulators::count<> (), isface2);
auto areamap = morpho::paccumulate(tree, F, accu);
auto vmap = morpho::vaccumulate_proper(tree, F, accu::features::mean<> ());
std::cout << "Grain size: " << lambda << std::endl;
mln_foreach(auto x, tree.nodes())
if (areamap[x] < lambda)
vmap[x] = vmap[x.parent()];
mln_foreach(auto px, F.pixels())
tree_t::node_type x = tree.get_node_at(px.index());
if (areamap[x] < lambda)
px.val() = vmap[x];
F = Kadjust_to(F, f.domain());
io::imsave(F, 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