Commit 329d1450 authored by Baptiste Esteban's avatar Baptiste Esteban
Browse files

Add rgb8 image alphatree test

parent 17aed36e
Pipeline #27769 passed with stages
in 32 minutes and 25 seconds
......@@ -215,7 +215,7 @@ namespace mln::morpho
std::size_t node_count = flatzones_count;
std::vector<int> par(node_count);
std::vector<int> levels(node_count, 0);
std::vector<W> levels(node_count, 0);
// 4. Compute the hierarchy
{
std::iota(std::begin(par), std::end(par), 0);
......
......@@ -21,18 +21,18 @@ namespace mln::morpho
assert(vals.size() == t.parent.size());
image_ch_value_t<Nodemap, L> lbl = imchvalue<L>(nm);
image_concrete_t<Nodemap> cut_nm = imconcretize(nm);
image_ch_value_t<Nodemap, L> lbl = imchvalue<L>(nm);
image_concrete_t<Nodemap> cut_nm = imconcretize(nm);
mln_foreach(auto p, nm.domain())
mln_foreach (auto p, nm.domain())
{
cut_nm(p) = nm(p);
while (t.parent[cut_nm(p)] != cut_nm(p) && t.values[t.parent[cut_nm(p)]] <= th)
cut_nm(p) = t.parent[cut_nm(p)];
cut_nm(p) = nm(p);
while (t.parent[cut_nm(p)] != cut_nm(p) && t.values[t.parent[cut_nm(p)]] <= th)
cut_nm(p) = t.parent[cut_nm(p)];
}
mln_foreach(auto px, cut_nm.pixels())
lbl(px.point()) = vals[px.val()];
mln_foreach (auto px, cut_nm.pixels())
lbl(px.point()) = vals[px.val()];
return lbl;
}
......
#include <mln/morpho/alphatree.hpp>
#include <mln/core/neighborhood/c4.hpp>
#include <mln/core/colors.hpp>
#include <mln/core/image/ndimage.hpp>
#include <mln/io/imread.hpp>
#include <mln/core/neighborhood/c4.hpp>
#include <mln/morpho/cut.hpp>
#include <fixtures/ImagePath/image_path.hpp>
#include <fixtures/ImageCompare/image_compare.hpp>
#include <gtest/gtest.h>
#include <cmath>
#include <iostream>
template <typename V>
mln::image2d<int> //
cut(const mln::morpho::component_tree<int>& t, mln::image2d<int>& node_map, int alpha)
cut(const mln::morpho::component_tree<V>& t, mln::image2d<int>& node_map, int alpha)
{
std::size_t n = t.parent.size();
......@@ -19,7 +23,7 @@ cut(const mln::morpho::component_tree<int>& t, mln::image2d<int>& node_map, int
int nlabel = 0;
{
mln_foreach(auto px, node_map.pixels())
mln_foreach (auto px, node_map.pixels())
if (labels[px.val()] == -1)
labels[px.val()] = nlabel++;
}
......@@ -37,7 +41,7 @@ cut(const mln::morpho::component_tree<int>& t, mln::image2d<int>& node_map, int
mln::image2d<int> imlabel;
imlabel.resize(node_map.domain());
mln_foreach(auto px, imlabel.pixels())
mln_foreach (auto px, imlabel.pixels())
px.val() = labels[node_map(px.point())];
return imlabel;
......@@ -46,12 +50,12 @@ cut(const mln::morpho::component_tree<int>& t, mln::image2d<int>& node_map, int
TEST(Morpho, AlphaTree)
{
mln::image2d<uint8_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}, //
mln::image2d<uint8_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}, //
};
auto [t, node_map] = mln::morpho::alphatree(ima, mln::c4);
......@@ -94,3 +98,68 @@ TEST(Morpho, AlphaTree)
ASSERT_IMAGES_EQ_EXP(cut(t, node_map, 10), ref10);
ASSERT_IMAGES_EQ_EXP(cut(t, node_map, 11), ref11);
}
TEST(Morpho, AlphaTreeRGB8)
{
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_8 = {
{6, 6, 13}, //
{12, 6, 10}, //
{9, 8, 7} //
};
const mln::image2d<int> ref_16 = {
{6, 6, 13}, //
{5, 6, 10}, //
{5, 8, 7} //
};
const mln::image2d<int> ref_17 = {
{6, 6, 13}, //
{4, 6, 10}, //
{4, 4, 7} //
};
const mln::image2d<int> ref_18 = {
{3, 3, 13}, //
{3, 3, 10}, //
{3, 3, 7} //
};
const mln::image2d<int> ref_24 = {
{2, 2, 13}, //
{2, 2, 10}, //
{2, 2, 2} //
};
const mln::image2d<int> ref_32 = {
{1, 1, 13}, //
{1, 1, 1}, //
{1, 1, 1} //
};
const mln::image2d<int> ref_36 = {
{0, 0, 0}, //
{0, 0, 0}, //
{0, 0, 0} //
};
auto [t, nm] = mln::morpho::alphatree(
ima, mln::c4, [](const auto& a, const auto& b) -> int { return mln::functional::l2dist_t<>()(a, b); });
std::vector<int> rng(t.parent.size());
std::iota(rng.begin(), rng.end(), 0);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 0, rng), nm);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 8, rng), ref_8);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 16, rng), ref_16);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 17, rng), ref_17);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 18, rng), ref_18);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 24, rng), ref_24);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 32, rng), ref_32);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 36, rng), ref_36);
}
\ No newline at end of file
......@@ -2,81 +2,79 @@
#include <mln/morpho/cut.hpp>
#include <mln/accu/accumulators/mean.hpp>
#include <mln/core/neighborhood/c4.hpp>
#include <mln/core/image/ndimage.hpp>
#include <mln/core/neighborhood/c4.hpp>
#include <fixtures/ImageCompare/image_compare.hpp>
#include <gtest/gtest.h>
#include <mln/io/imprint.hpp>
#include <numeric>
TEST(Morpho, AlphaTreeCutMeanLabelization)
{
mln::image2d<std::uint8_t> ima = {
{1, 1, 5},
{2, 5, 6},
{0, 1, 4}
};
mln::image2d<std::uint8_t> cut_1 = {
{1, 1, 5},
{1, 5, 5},
{0, 0, 4}
};
mln::image2d<std::uint8_t> cut_2 = {
{1, 1, 5},
{1, 5, 5},
{1, 1, 5}
};
mln::image2d<std::uint8_t> cut_3 = {
{2, 2, 2},
{2, 2, 2},
{2, 2, 2}
};
auto [t, nm] = mln::morpho::alphatree(ima, mln::c4);
auto val = t.compute_attribute_on_values(nm, ima, mln::accu::accumulators::mean<std::uint8_t, std::uint8_t>());
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 0, val), ima);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 1, val), cut_1);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 2, val), cut_2);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 3, val), cut_3);
mln::image2d<std::uint8_t> ima = {
{1, 1, 5}, //
{2, 5, 6}, //
{0, 1, 4} //
};
mln::image2d<std::uint8_t> cut_1 = {
{1, 1, 5}, //
{1, 5, 5}, //
{0, 0, 4} //
};
mln::image2d<std::uint8_t> cut_2 = {
{1, 1, 5}, //
{1, 5, 5}, //
{1, 1, 5} //
};
mln::image2d<std::uint8_t> cut_3 = {
{2, 2, 2}, //
{2, 2, 2}, //
{2, 2, 2} //
};
auto [t, nm] = mln::morpho::alphatree(ima, mln::c4);
auto val = t.compute_attribute_on_values(nm, ima, mln::accu::accumulators::mean<std::uint8_t, std::uint8_t>());
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 0, val), ima);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 1, val), cut_1);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 2, val), cut_2);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 3, val), cut_3);
}
TEST(Morpho, AlphaTreeCutRangeLabelization)
{
mln::image2d<std::uint8_t> ima = {
{1, 1, 5},
{2, 5, 6},
{0, 1, 4}
};
mln::image2d<std::uint8_t> cut_1 = {
{1, 1, 5},
{1, 5, 5},
{0, 0, 4}
};
mln::image2d<std::uint8_t> cut_2 = {
{1, 1, 5},
{1, 5, 5},
{1, 1, 5}
};
mln::image2d<std::uint8_t> cut_3 = {
{2, 2, 2},
{2, 2, 2},
{2, 2, 2}
};
auto [t, nm] = mln::morpho::alphatree(ima, mln::c4);
auto val = t.compute_attribute_on_values(nm, ima, mln::accu::accumulators::mean<std::uint8_t, std::uint8_t>());
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 0, val), ima);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 1, val), cut_1);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 2, val), cut_2);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 3, val), cut_3);
mln::image2d<int> ima = {
{1, 1, 5}, //
{2, 5, 6}, //
{0, 1, 4} //
};
mln::image2d<int> cut_1 = {
{5, 5, 4}, //
{5, 4, 4}, //
{3, 3, 6} //
};
mln::image2d<int> cut_2 = {
{2, 2, 1}, //
{2, 1, 1}, //
{2, 2, 1} //
};
mln::image2d<int> cut_3 = {
{0, 0, 0}, //
{0, 0, 0}, //
{0, 0, 0} //
};
auto [t, nm] = mln::morpho::alphatree(ima, mln::c4);
auto val = std::vector<int>(t.parent.size());
std::iota(val.begin(), val.end(), 0);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 0, val), nm);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 1, val), cut_1);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 2, val), cut_2);
ASSERT_IMAGES_EQ_EXP(mln::morpho::horizontal_cut_labelization_from(t, nm, 3, val), cut_3);
}
\ 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