-
Hi all, I am trying to get the images corresponding to the shapes of an image (using the tree of shapes). I do not speak about the nodes of the tree, but about an image containing ones where each shape is defined, and zeros elsewhere. If someone can help me, I will be very grateful. Thanks for your help. |
Beta Was this translation helpful? Give feedback.
Answered by
PerretB
Nov 9, 2020
Replies: 1 comment
-
Hello, the following example demonstrates how to get a binary mask giving all the vertices of the base graph (pixels) that do (not) belong to a node of a hierarchy: import higra as hg
import numpy as np
import matplotlib.pyplot as plt
from skimage import data
im = data.coins()
plt.imshow(im)
# construct the tree of shapes of im
tree, altitudes = hg.component_tree_tree_of_shapes_image2d(im)
# perform an area filter to remove small components of the tree
area = hg.attribute_area(tree)
tree, _ = hg.simplify_tree(tree, area < 100)
# construct a vector that will be true for any node expect the one we want
deleted = np.ones(tree.num_vertices(), dtype=np.bool)
# arbitrarily select the 50th node from the root
deleted[tree.root()-50] = False
# reconstruct the selected node (every node except the selected one)
pixels = hg.reconstruct_leaf_data(tree, deleted, deleted)
plt.figure()
plt.imshow(pixels) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
PerretB
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
the following example demonstrates how to get a binary mask giving all the vertices of the base graph (pixels) that do (not) belong to a node of a hierarchy: