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

Add hyperspectral apps with self-dual profiles computation.

	*  apps/CMakeLists.txt,
	*  apps/hyperspec/CMakeLists.txt,
	*  apps/hyperspec/profiles.hpp,
	*  apps/hyperspec/profiles_from_marginal_tos.cpp,
	*  apps/hyperspec/profiles_from_tos.cpp: New.
parent 54064d33
......@@ -8,7 +8,10 @@ add_subdirectory(simplification)
add_subdirectory(clattice)
add_subdirectory(g2)
add_subdirectory(mumford_shah_on_tree)
#add_subdirectory(misc)
#add_subdirectory(theo)
add_subdirectory(tosgui)
add_subdirectory(saliency)
add_subdirectory(supervised-gui)
add_subdirectory(hierachical_seg-gui)
add_subdirectory(hyperspec)
add_executable(profiles_from_tos profiles_from_tos.cpp $<TARGET_OBJECTS:g2-tools>)
target_link_libraries(profiles_from_tos ${FreeImage_LIBRARIES})
add_executable(profiles_from_marginal_tos profiles_from_marginal_tos.cpp $<TARGET_OBJECTS:g2-tools>)
target_link_libraries(profiles_from_marginal_tos ${FreeImage_LIBRARIES})
\ No newline at end of file
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/morphers/casted_image.hpp>
#include <mln/core/algorithm/transform.hpp>
#include <mln/core/algorithm/accumulate.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 <mln/accu/accumulator.hpp>
#include <mln/accu/accumulators/accu_if.hpp>
#include <mln/accu/accumulators/min.hpp>
#include <mln/accu/accumulators/max.hpp>
#include <mln/accu/accumulators/moment_of_inertia.hpp>
#include <mln/colors/literal.hpp>
#include <apps/tos/Kinterpolate.hpp>
#include <apps/tos/topology.hpp>
#include <apps/tos/croutines.hpp>
#include <iostream>
#include <boost/format.hpp>
typedef mln::morpho::component_tree<unsigned, mln::image2d<unsigned> > tree_t;
namespace mln
{
template <class V, class VMap>
std::vector< image2d<float> >
profile(const tree_t& tree, const image2d<V>& F, const VMap& vmap, std::vector<float>& lambdas,
std::vector< image2d<typename VMap::value_type> >& res)
{
typedef accu::accumulators::moment_of_inertia<point2df, vec2f> myaccu_t;
auto amap = morpho::paccumulate(tree, F, myaccu_t ());
typedef typename VMap::value_type W;
float amap_max;
{
auto tmp = make_image(tree, amap);
amap_max = accumulate(tmp, accu::features::max<>());
for (float x = 0.1; x < amap_max; x += 0.1)
lambdas.push_back(x);
}
res.reserve(lambdas.size()+1);
{
image2d<float> out;
resize(out, F);
morpho::reconstruction(tree, amap, out);
io::imsave(out, "amap.tiff");
}
{
image2d<W> out;
resize(out, F);
morpho::reconstruction(tree, vmap, out);
//io::imsave(imcast<rgb16>(out), "rec_0.00.tiff");
res.push_back(std::move(out));
for (float t : lambdas)
{
image2d<W> out;
resize(out, F);
auto crit = make_functional_property_map<tree_t::node_type>([amap, t](tree_t::node_type x) { return amap[x] >= t; });
morpho::filter_direct_and_reconstruct(tree, crit, vmap, out);
//io::imsave(imcast<rgb16>(out), (boost::format("rec_%.02f.tiff") % t).str());
res.push_back(std::move(out));
}
}
std::vector< image2d<float> > out;
out.resize(lambdas.size());
for (unsigned i = 0; i < lambdas.size(); ++i) {
out[i] = eval(imcast<float>(imtransform(res[i+1] - res[i], functional::l2norm_t<> ())));
}
return out;
}
template <typename T>
struct mymean : Accumulator< mymean<T> >
{
typedef accu::accumulators::mean<T> accu_t;
typedef void argument_type;
typedef typename accu_t::result_type result_type;
mymean() = default;
void init() {
m_accu.init();
}
template <typename Pix>
void take(const Pix& pix) {
if (K1::is_face_2(pix.point())) {
m_accu.take(pix.val());
}
}
void take(const mymean& other) {
m_accu.take(other.m_accu);
}
result_type to_result() const {
return m_accu.to_result();
}
private:
accu_t m_accu;
};
}
#include "profiles.hpp"
#include <mln/morpho/tos/ctos.hpp>
#include <apps/tos/croutines.hpp>
#include <iostream>
#include <boost/format.hpp>
#include <tbb/parallel_for.h>
namespace mln
{
std::vector< image2d<float> >
run(const image2d<uint16>& f, std::vector< image2d<uint16> >& rec)
{
tree_t tree = morpho::cToS(f, c4);
grain_filter_inplace(tree, 10);
image2d<uint16> F = Kadjust_to(f, tree._get_data()->m_pmap.domain());
auto vmap = morpho::make_attribute_map_from_image(tree, F);
std::vector<float> lambdas;
std::vector< image2d<float> > profiles = profile(tree, F, vmap, lambdas, rec);
return profiles;
}
}
int main(int argc, char** argv)
{
using namespace mln;
if (argc < 3)
{
std::cerr << "Usage: " << argv[0] << " input.tiff stem\n";
std::exit(1);
}
image2d<rgb16> f;
io::imread(argv[1], f);
f = addborder_marginal(f);
std::vector< image2d<float> > profiles[3];
std::vector< image2d<uint16> > rec[3];
tbb::parallel_for(0, 3,[&rec, &f, &profiles](int i) {
profiles[i] = run(eval(channel(f,i)), rec[i]);
});
std::string stem = argv[2];
int n = std::min(rec[0].size(), std::min(rec[1].size(), rec[2].size()));
float lambda = 0;
image2d<rgb16> r;
resize(r, rec[0][0]);
for (int i = 0; i < n; ++i, lambda += 0.1)
{
copy(rec[0][i], red(r));
copy(rec[1][i], green(r));
copy(rec[2][i], blue(r));
io::imsave(r, (boost::format("%s-rec-%.02f.tiff") % stem % lambda).str());
}
}
#include "profiles.hpp"
#include <apps/g2/compute_ctos.hpp>
#include <apps/tos/croutines.hpp>
#include <iostream>
#include <boost/format.hpp>
int main(int argc, char** argv)
{
using namespace mln;
if (argc < 3)
{
std::cerr << "Usage: " << argv[0] << " input.tiff stem\n";
std::exit(1);
}
image2d<rgb16> f;
io::imread(argv[1], f);
tree_t tree = compute_ctos(f);
grain_filter_inplace(tree, 10);
image2d<rgb16> F;
F = Kadjust_to(f, tree._get_data()->m_pmap.domain());
auto vmap = morpho::pixaccumulate_proper(tree, F, mymean<rgb16>());
{
mln_foreach(auto x, tree.nodes_without_root()) {
if (vmap[x] == colors::literal::black)
vmap[x] = vmap[x.parent()];
}
}
std::vector<float> lambdas;
std::vector< image2d<rgb<int>> > recs;
std::vector< image2d<float> > profiles = profile(tree, F, vmap, lambdas, recs);
std::string stem = argv[2];
int i = 0;
for (const image2d<float>& x : profiles) {
auto res = Kadjust_to(x, f.domain());
io::imsave(res, (boost::format("%s-%.02f.tiff") % stem % lambdas[i]).str());
i++;
}
}
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