Commit 0a944f37 authored by Baptiste Esteban's avatar Baptiste Esteban
Browse files

Add saliency map test

parent 0280227f
Pipeline #28907 passed with stage
in 17 minutes and 56 seconds
#include <mln/accu/accumulators/mean.hpp>
#include <mln/core/colors.hpp>
#include <mln/accu/accumulators/count.hpp>
#include <mln/core/image/ndimage.hpp>
#include <mln/core/image/view/cast.hpp>
#include <mln/core/neighborhood/c4.hpp>
#include <mln/io/imread.hpp>
#include <mln/io/imsave.hpp>
#include <mln/morpho/tos.hpp>
#include <mln/morpho/watershed_hierarchy.hpp>
......
......@@ -22,7 +22,7 @@ add_core_test(${test_prefix}depth_first depthfirst.cpp)
add_core_test(${test_prefix}maxtree maxtree.cpp)
add_core_test(${test_prefix}alphatree alphatree.cpp)
add_core_test(${test_prefix}private_directional_hqueue directional_hqueue.cpp)
#add_core_test(${test_prefix}component_tree component_tree.cpp)
add_core_test(${test_prefix}component_tree component_tree.cpp)
target_link_libraries(${test_prefix}dilate PRIVATE TBB::TBB)
#include <gtest/gtest.h>
#include <iostream>
#include <mln/core/image/ndimage.hpp>
#include <mln/io/imread.hpp>
#include <mln/io/imsave.hpp>
#include <mln/morpho/component_tree.hpp>
#include <mln/morpho/tos.hpp>
using node_t = int;
static std::vector<mln::morpho::edge_t<int, double>> saliency_map(mln::image2d<uint8_t> node_map)
{
std::vector<mln::morpho::edge_t<int, double>> res;
auto width = node_map.width();
auto dom = node_map.domain();
mln_foreach (auto p, dom)
{
for (auto q : mln::c4.after(p))
{
if (dom.has(q))
{
mln::morpho::edge_t<int, double> edge = {p[0] + width * p[1], q[0] + width * q[1], 0};
// std::cout << p[0] + width * p[1] << ' ' << node_map.index_of_point(p) << '\n';
// std::cout << q[0] + width * q[1] << ' ' << node_map.index_of_point(q) << '\n';
// std::cout << "\n\n";
edge.w = std::abs(node_map(p) - node_map(q));
res.emplace_back(edge);
}
}
}
return res;
}
TEST(Component_tree, Saliency_Map)
{
mln::image2d<uint8_t> img = {{0, 0, 100, 0}, {0, 0, 75, 0}, {95, 80, 60, 0}, {0, 0, 0, 0}};
int expected_s_map_val[24][3] = {{0, 1, 0}, {0, 4, 0}, {1, 2, 100}, {1, 5, 0}, {2, 3, 100}, {2, 6, 25},
{3, 7, 0}, {4, 5, 0}, {4, 8, 95}, {5, 6, 75}, {5, 9, 80}, {6, 7, 75},
{6, 10, 15}, {7, 11, 0}, {8, 9, 15}, {8, 12, 95}, {9, 10, 20}, {9, 13, 80},
{10, 11, 60}, {10, 14, 60}, {11, 15, 0}, {12, 13, 0}, {13, 14, 0}, {14, 15, 0}};
auto [t, node_map] = mln::morpho::tos(img, {0, 0});
#include <mln/morpho/alphatree.hpp>
const std::vector<mln::morpho::edge_t<int, double>>& s_map = saliency_map(img);
for (int i = 0; i < 24; ++i)
{
auto expected_edge = expected_s_map_val[i];
ASSERT_EQ(expected_edge[2], s_map[i].w);
}
}
#include <fixtures/ImageCompare/image_compare.hpp>
#include <gtest/gtest.h>
TEST(Component_tree, Saliency)
TEST(Morpho, SaliencyAlphaTree)
{
mln::image2d<uint8_t> img = {{0, 0, 100, 0}, {0, 0, 75, 0}, {95, 80, 60, 0}, {0, 0, 0, 0}};
int expected_saliency[9 * 9] = {255, 255, 255, 255, 155, 255, 155, 255, 255, //
255, 255, 255, 255, 155, 255, 155, 255, 255, //
255, 255, 255, 255, 155, 230, 155, 255, 255, //
255, 255, 255, 255, 180, 255, 180, 255, 255, //
160, 160, 160, 175, 175, 240, 180, 255, 255, //
255, 255, 240, 255, 235, 255, 195, 255, 255, //
160, 160, 160, 175, 175, 195, 195, 255, 255, //
255, 255, 255, 255, 255, 255, 255, 255, 255, //
255, 255, 255, 255, 255, 255, 255, 255, 255};
auto [t, node_map] = mln::morpho::tos(img, {0, 0});
auto saliency = t.saliency(img);
for (int i = 0; i < 9 * 9; ++i)
{
ASSERT_EQ(expected_saliency[i], static_cast<int>(saliency({i % 9, i / 9})));
}
mln::image2d<std::uint8_t> input = {
{1, 1, 3, 1}, //
{2, 6, 8, 7}, //
{5, 3, 2, 2} //
};
mln::image2d<double> expected = {
{0, 0, 0, 2, 0, 2, 0}, //
{1, 3, 3, 3, 3, 3, 3}, //
{0, 3, 0, 2, 0, 1, 0}, //
{3, 3, 3, 3, 3, 3, 3}, //
{0, 2, 0, 1, 0, 0, 0} //
};
auto [t, nm] =
mln::morpho::alphatree(input, mln::c4, [](auto a, auto b) -> double { return mln::functional::l2dist(a, b); });
const auto res = t.saliency(nm, ::ranges::make_span(t.values.data(), t.values.size()));
ASSERT_IMAGES_EQ_EXP(res, expected);
}
\ No newline at end of file
Supports Markdown
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