Commit 4e8c2734 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Add some tools.

print_tos_stat: Statistics computation about the CToS.
psnr: PSNR computation.
reconstruct_from_tree: Image reconstruction.

	*  apps/CMakeLists.txt,
	*  apps/misc/CMakeLists.txt,
	*  apps/misc/print_tos_stat.cpp,
	*  apps/misc/psnr.cpp,
	*  apps/misc/reconstruct_from_tree.cpp: New.
parent bd951c3a
......@@ -8,7 +8,7 @@ add_subdirectory(simplification)
add_subdirectory(clattice)
add_subdirectory(g2)
add_subdirectory(mumford_shah_on_tree)
#add_subdirectory(misc)
add_subdirectory(misc)
add_subdirectory(theo)
add_subdirectory(tosgui)
add_subdirectory(saliency)
......
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(psnr psnr.cpp)
\ No newline at end of file
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/morphers/casted_image.hpp>
#include <mln/io/imread.hpp>
#include <mln/morpho/component_tree/compute_depth.hpp>
#include <apps/g2/compute_ctos.hpp>
int main(int argc, char** argv)
{
using namespace mln;
typedef morpho::component_tree<unsigned, image2d<unsigned> > tree_t;
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " image1 [image2...]\n"
<< "Ouputs some stats about the (Color) ToS (#nodes,Average Depth,Max Depth)\n";
std::exit(1);
}
image2d<rgb8> f;
tree_t tree;
std::cout << "Image,Size,Count,AvgDepth,MaxDepth\n";
for (int i = 1; i < argc; ++i)
{
try {
io::imread(argv[i], f);
} catch (...) {
image2d<uint8> g;
io::imread(argv[i], g);
f = eval(imcast<rgb8>(g));
}
tree = compute_ctos(f);
auto depthmap = morpho::compute_depth(tree);
size_t n = 0;
double sumdepth = 0;
unsigned maxdepth = 0;
mln_foreach (auto x, tree.nodes())
{
sumdepth += depthmap[x];
maxdepth = std::max(maxdepth, depthmap[x]);
n++;
}
std::cout << argv[i] << "," << f.domain().size() << ","
<< n << "," << (sumdepth / n) << "," << maxdepth << "\n";
}
}
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/morphers/casted_image.hpp>
#include <mln/io/imread.hpp>
#include <mln/io/imsave.hpp>
#include <mln/core/algorithm/accumulate.hpp>
#include <mln/accu/accumulators/sum.hpp>
int main(int argc, char** argv)
{
using namespace mln;
if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " input1 input2\n";
std::exit(1);
}
image2d<rgb8> f, g;
io::imread(argv[1], f);
io::imread(argv[2], g);
auto f_ = imcast<rgb<float>>(f);
auto g_ = imcast<rgb<float>>(g);
auto diff = imtransform(f_ - g_, [](rgb<float> x) -> double { return l2norm_sqr(x); });
auto dims = f.domain().shape();
double sum = accumulate(diff, accu::features::sum<double> ());
double MSE = sum / (3 * dims[0] * dims[1]);
std::cout << "MSE: " << MSE << "\n";
if (MSE == 0)
std::cout << "PSNR: " << -1 << "\n";
else {
float psnr = 20 * std::log10(255) - 10 * std::log10(MSE);
std::cout << "PSNR: " << psnr << "\n";
}
}
#include <iostream>
#include <mln/core/image/image2d.hpp>
#include <mln/core/colors.hpp>
#include <mln/io/imread.hpp>
#include <mln/io/imsave.hpp>
#include <mln/morpho/component_tree/component_tree.hpp>
#include <mln/morpho/component_tree/io.hpp>
#include <mln/morpho/component_tree/accumulate.hpp>
#include <mln/morpho/component_tree/reconstruction.hpp>
#include <mln/accu/accumulators/mean.hpp>
#include <mln/accu/accumulators/accu_if.hpp>
#include <mln/accu/accumulators/accu_transform.hpp>
#include <apps/tos/Kinterpolate.hpp>
#include <apps/tos/topology.hpp>
int main(int argc, char** argv)
{
if (argc < 4)
{
std::cerr << "Usage: " << argv[0] << " input.tree img(color|gray) out.tiff \n"
<< "Reconstruct from a tree. The image may in K0|K1 with(out) border.\n"
;
std::exit(1);
}
using namespace mln;
morpho::component_tree<unsigned, image2d<unsigned> > tree;
image2d<rgb8> ima;
{
std::ifstream fs(argv[1], std::ios::binary);
morpho::load(fs, tree);
}
io::imread(argv[2], ima);
image2d<rgb8> f = Kadjust_to(ima, tree._get_data()->m_pmap.domain());
typedef accu::accumulators::mean<rgb8> ACCU;
typedef image2d<rgb8> I;
auto is_face_2 = [](const mln_cpixel(I)& px) { return K1::is_face_2(px.point()); };
auto val_of_pix = [](const mln_cpixel(I)& px) { return px.val(); };
typedef accu::accumulators::accu_transform<ACCU, decltype(val_of_pix), mln_cpixel(I)> ACCU_1;
typedef accu::accumulators::accu_if<ACCU_1, decltype(is_face_2), mln_cpixel(I)> ACCU_2;
//auto vmap = morpho::pixaccumulate_proper(tree, f, ACCU_2(ACCU_1(ACCU(), val_of_pix),is_face_2));
auto vmap = morpho::vaccumulate_proper(tree, f, accu::features::mean<>());
image2d<rgb8> out;
resize(out, f);
morpho::reconstruction(tree, vmap, out);
image2d<rgb8> final = Kadjust_to(out, ima.domain());
io::imsave(final, 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