Commit 6b91dd08 authored by Quentin Kaci's avatar Quentin Kaci
Browse files

Add some tests on alphatree (float, 8 connectivity, 3d image)

parent 5e9f4e15
Pipeline #27899 passed with stages
in 36 minutes and 36 seconds
#include <mln/core/colors.hpp>
#include <mln/core/image/ndimage.hpp>
#include <mln/core/neighborhood/c4.hpp>
#include <mln/core/neighborhood/c8.hpp>
#include <mln/core/neighborhood/c26.hpp>
#include <mln/morpho/alphatree.hpp>
#include <mln/morpho/cut.hpp>
......@@ -8,9 +10,8 @@
#include <gtest/gtest.h>
template <typename V>
mln::image2d<int> //
cut(const mln::morpho::component_tree<V>& t, mln::image2d<int>& node_map, int alpha)
template <typename V, typename I, typename T>
I cut(const mln::morpho::component_tree<V>& t, I& node_map, T alpha)
{
std::size_t n = t.parent.size();
......@@ -33,7 +34,7 @@ cut(const mln::morpho::component_tree<V>& t, mln::image2d<int>& node_map, int al
if (t.values[t.parent[i]] <= alpha) // progate to parent
labels[i] = labels[t.parent[i]];
mln::image2d<int> imlabel;
I imlabel;
imlabel.resize(node_map.domain());
mln_foreach (auto px, imlabel.pixels())
......@@ -54,7 +55,7 @@ TEST(Morpho, AlphaTree)
};
auto [t, node_map] = mln::morpho::alphatree(ima, mln::c4, [](const auto& a, const auto& b) -> std::uint8_t { return mln::functional::l2dist_t<>()(a, b);});
mln::image2d<int> ref0 = {
mln::image2d<int> ref_0 = {
{0, 1, 2, 3, 4}, //
{5, 6, 7, 8, 9}, //
{10, 11, 12, 13, 14}, //
......@@ -62,7 +63,7 @@ TEST(Morpho, AlphaTree)
{15, 20, 21, 22, 23}, //
};
mln::image2d<int> ref1 = {
mln::image2d<int> ref_1 = {
{0, 1, 2, 3, 4}, //
{5, 6, 7, 8, 9}, //
{5, 11, 12, 13, 14}, //
......@@ -70,7 +71,7 @@ TEST(Morpho, AlphaTree)
{15, 20, 21, 22, 23}, //
};
mln::image2d<int> ref10 = {
mln::image2d<int> ref_10 = {
{0, 0, 2, 3, 4}, //
{5, 0, 2, 8, 9}, //
{5, 11, 12, 13, 14}, //
......@@ -79,7 +80,7 @@ TEST(Morpho, AlphaTree)
};
mln::image2d<int> ref11 = {
mln::image2d<int> ref_11 = {
{0, 0, 2, 3, 4}, //
{5, 0, 2, 8, 4}, //
{5, 11, 12, 13, 14}, //
......@@ -88,13 +89,13 @@ TEST(Morpho, AlphaTree)
};
ASSERT_IMAGES_EQ_EXP(cut(t, node_map, 0), ref0);
ASSERT_IMAGES_EQ_EXP(cut(t, node_map, 1), ref1);
ASSERT_IMAGES_EQ_EXP(cut(t, node_map, 10), ref10);
ASSERT_IMAGES_EQ_EXP(cut(t, node_map, 11), ref11);
ASSERT_IMAGES_EQ_EXP(cut(t, node_map, 0u), ref_0);
ASSERT_IMAGES_EQ_EXP(cut(t, node_map, 1u), ref_1);
ASSERT_IMAGES_EQ_EXP(cut(t, node_map, 10u), ref_10);
ASSERT_IMAGES_EQ_EXP(cut(t, node_map, 11u), ref_11);
}
TEST(Morpho, AlphaTreeRGB8)
TEST(Morpho, AlphaTreeRGB8Uint16Distance)
{
const mln::image2d<mln::rgb8> ima = {
{{10, 0, 0}, {10, 0, 0}, {12, 20, 38}}, //
......@@ -102,58 +103,122 @@ TEST(Morpho, AlphaTreeRGB8)
{{11, 18, 0}, {25, 17, 11}, {9, 0, 5}} //
};
auto [t, nm] = mln::morpho::alphatree(
ima, mln::c4, [](const auto& a, const auto& b) -> std::uint16_t { return mln::functional::l2dist_t<>()(a, b); });
const mln::image2d<int> ref_0 = {
{0, 0, 1}, //
{2, 3, 4}, //
{5, 6, 7} //
};
const mln::image2d<int> ref_8 = {
{6, 6, 13}, //
{12, 6, 10}, //
{9, 8, 7} //
{0, 0, 1}, //
{2, 0, 4}, //
{5, 6, 7} //
};
const mln::image2d<int> ref_16 = {
{6, 6, 13}, //
{5, 6, 10}, //
{5, 8, 7} //
{0, 0, 1}, //
{2, 0, 4}, //
{2, 6, 7} //
};
const mln::image2d<int> ref_17 = {
{6, 6, 13}, //
{4, 6, 10}, //
{4, 4, 7} //
ASSERT_IMAGES_EQ_EXP(cut(t, nm, 0u), ref_0);
ASSERT_IMAGES_EQ_EXP(cut(t, nm, 8u), ref_8);
ASSERT_IMAGES_EQ_EXP(cut(t, nm, 16u), ref_16);
}
TEST(Morpho, AlphaTreeRGB8FloatDistance)
{
const mln::image2d<mln::rgb8> ima = {
{{10, 0, 0}, {10, 0, 0}, {12, 20, 38}}, //
{{13, 22, 16}, {15, 2, 6}, {37, 25, 12}}, //
{{11, 18, 0}, {25, 17, 11}, {9, 0, 5}} //
};
const mln::image2d<int> ref_18 = {
{3, 3, 13}, //
{3, 3, 10}, //
{3, 3, 7} //
auto [t, nm] = mln::morpho::alphatree(
ima, mln::c4, [](const auto& a, const auto& b) -> std::float_t { return mln::functional::l2dist_t<>()(a, b); });
const mln::image2d<int> ref_0 = {
{0, 0, 1}, //
{2, 3, 4}, //
{5, 6, 7} //
};
const mln::image2d<int> ref_24 = {
{2, 2, 13}, //
{2, 2, 10}, //
{2, 2, 2} //
const mln::image2d<int> ref_16 = {
{0, 0, 1}, //
{2, 0, 4}, //
{5, 6, 7} //
};
const mln::image2d<int> ref_32 = {
{1, 1, 13}, //
{1, 1, 1}, //
{1, 1, 1} //
{0, 0, 1}, //
{2, 0, 4}, //
{2, 6, 7} //
};
ASSERT_IMAGES_EQ_EXP(cut(t, nm, 0.f), ref_0);
ASSERT_IMAGES_EQ_EXP(cut(t, nm, 16.f), ref_16);
ASSERT_IMAGES_EQ_EXP(cut(t, nm, 32.f), ref_32);
}
TEST(Morpho, AlphaTree8C)
{
mln::image2d<std::uint32_t> ima = {
{128, 124, 150, 137, 106}, //
{116, 128, 156, 165, 117}, //
{117, 90, 131, 108, 151}, //
{107, 87, 118, 109, 167}, //
{107, 73, 125, 157, 117}, //
};
const mln::image2d<int> ref_36 = {
{0, 0, 0}, //
{0, 0, 0}, //
{0, 0, 0} //
auto [t, nm] = mln::morpho::alphatree(
ima, mln::c8, [](const auto& a, const auto& b) -> std::uint32_t { return mln::functional::l2dist_t<>()(a, b); });
mln::image2d<int> ref_0 = {
{0, 1, 2, 3, 4}, //
{5, 0, 6, 7, 8}, //
{9, 10, 11, 12, 13}, //
{14, 15, 16, 17, 18}, //
{14, 19, 20, 21, 22}, //
};
mln::image2d<int> ref_16 = {
{0, 0, 2, 2, 4}, //
{5, 0, 6, 7, 8}, //
{9, 10, 11, 8, 7}, //
{9, 10, 16, 16, 18}, //
{9, 19, 20, 18, 22}, //
};
ASSERT_IMAGES_EQ_EXP(cut(t, nm, 0.f), ref_0);
ASSERT_IMAGES_EQ_EXP(cut(t, nm, 16.f), ref_16);
}
TEST(Morpho, AlphaTree3DImage)
{
const mln::image3d<uint32_t> ima = {
{{10, 0, 0}, {10, 0, 0}, {12, 20, 38}}, //
{{13, 22, 16}, {15, 2, 6}, {37, 25, 12}}, //
{{11, 18, 0}, {25, 17, 11}, {9, 0, 5}} //
};
auto [t, nm] = mln::morpho::alphatree(
ima, mln::c4, [](const auto& a, const auto& b) -> std::uint16_t { return mln::functional::l2dist_t<>()(a, b); });
auto rng = std::vector<int>(t.parent.size());
std::iota(rng.begin(), rng.end(), 0);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 0u, rng), nm);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 8u, rng), ref_8);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 16u, rng), ref_16);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 17u, rng), ref_17);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 18u, rng), ref_18);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 24u, rng), ref_24);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 32u, rng), ref_32);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 36u, rng), ref_36);
ima, mln::c26, [](const auto& a, const auto& b) -> std::uint32_t { return mln::functional::l2dist_t<>()(a, b); });
const mln::image3d<int> ref_0 = {
{{0, 1, 1}, {0, 1, 1}, {2, 3, 4}}, //
{{5, 6, 7}, {8, 9, 10}, {11, 12, 13}}, //
{{14, 15, 16}, {12, 17, 18}, {19, 20, 21}} //
};
const mln::image3d<int> ref_16 = {
{{0, 1, 1}, {0, 1, 1}, {1, 3, 4}}, //
{{5, 6, 7}, {8, 9, 10}, {11, 0, 13}}, //
{{5, 15, 9}, {0, 15, 13}, {19, 9, 10}} //
};
ASSERT_IMAGES_EQ_EXP(cut(t, nm, 0u), ref_0);
ASSERT_IMAGES_EQ_EXP(cut(t, nm, 16u), ref_16);
}
\ No newline at end of file
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