Commit f74653cd authored by Baptiste Esteban's avatar Baptiste Esteban
Browse files

Refacto saliency map

parent ee3f1d79
Pipeline #28901 passed with stages
in 16 minutes and 26 seconds
......@@ -298,24 +298,25 @@ Saliency Computation
--------------
It is also possible to compute the saliency map to obtain another visualization.
.. cpp:function:: auto saliency(Image node_map)
.. cpp:function:: auto saliency(image2d<int> node_map, ranges::span<double> values) const
Compute and return the saliency map of the tree.
Compute and return the saliency map of the tree. **Works only for 2D images and with tree node values of type** ``double``.
:param node_map: An image thats maps ``point -> node id``
:param values: the levels of the tree for each node
:return: The saliency map as an image
.. list-table::
* - .. image:: /images/watershed_hierarchy_area_gray.png
* - .. image:: /images/lena_gray.jpg
:width: 100%
- .. image:: /images/saliency_watershed.png
:width: 100%
* - Watershed hierarchy by area with a cut at a threshold of 25
- The corresponding saliency map
* - Original image
- Saliency map of the watershed hierarchy by area
A complete example
------------------
......
#include <mln/morpho/component_tree.hpp>
#include <iostream>
namespace mln::morpho
{
namespace internal
......@@ -51,27 +49,22 @@ namespace mln::morpho
}
return b;
};
std::vector<internal::edge_t<point2d, int>> s_map;
mln_foreach (auto p, node_map.domain())
{
if (p[0] == 440 && p[1] == 224)
std::cout << "";
for (auto q : c4.after(p))
{
if (node_map.domain().has(q))
s_map.emplace_back(p, q, values[lca(node_map(p), node_map(q))]);
}
}
const auto kwidth = node_map.width() * 2 - 1;
const auto kheight = node_map.height() * 2 - 1;
image2d<double> res(kwidth, kheight);
fill(res, 0);
for (const auto [u, v, w] : s_map)
mln_foreach (auto p, node_map.domain())
{
const auto dir = v - u;
res(point2d{2 * u[0], 2 * u[1]} + dir) = w;
for (auto q : c4.after(p))
{
if (node_map.domain().has(q))
{
const auto dir = q - p;
res(point2d{2 * p[0], 2 * p[1]} + dir) = values[lca(node_map(p), node_map(q))];
}
}
}
return res;
......
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