Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 32b72ad7 authored by CERUTTI Guillaume's avatar CERUTTI Guillaume
Browse files

enable label properties in mesh -> cell transfer

parent 2dd554a2
No related branches found
No related tags found
No related merge requests found
Pipeline #939639 failed
......@@ -35,6 +35,7 @@ class surfaceMeshCellProperty(gnomonAbstractCellImageQuantification):
self._parameters = {}
self._parameters['attribute_names'] = d_inliststringlist("Attributes", [""], [""], "List of vertex attributes to transfer from the surface mesh")
self._parameters['label_threshold'] = d_int("Max Label Number", 64, 0, 1e4, "Maximal number of different values for an attribute to be considered a label")
def refreshParameters(self):
if len(self.surface_topomesh)>0:
......@@ -42,6 +43,8 @@ class surfaceMeshCellProperty(gnomonAbstractCellImageQuantification):
attribute_names = self['attribute_names']
property_names = list(surface_topomesh.wisp_property_names(0))
property_names = [p for p in property_names if surface_topomesh.has_wisp_property(p, 0, is_computed=True)]
property_names = [p for p in property_names if surface_topomesh.wisp_property(p, 0).values().dtype != np.dtype('O')]
if len(property_names) == 0:
property_names = [""]
attribute_names = [p for p in attribute_names if p in property_names]
......@@ -92,9 +95,20 @@ class surfaceMeshCellProperty(gnomonAbstractCellImageQuantification):
vertex_property = surface_topomesh.wisp_property(property_name, 0).values(list(surface_topomesh.wisps(0)))
property_values = np.unique(vertex_property)
property_is_binary = vertex_property.ndim == 1 and len(property_values) <= 2 and (0 in property_values or 1 in property_values)
property_is_label = vertex_property.ndim == 1 and len(property_values) <= self['label_threshold']
cell_property = None
if property_is_binary:
cell_property = (nd.sum(vertex_property, vertex_cells, index=cell_labels) > 0).astype(int)
elif property_is_label:
def most_represented(array):
values, counts = np.unique(array, return_counts=True)
return values[np.argmax(counts)]
dtype = property_values.dtype
default = np.iinfo(dtype).min if np.issubdtype(dtype, np.integer) else np.nan
cell_property = nd.labeled_comprehension(
vertex_property, vertex_cells, index=cell_labels,
func=most_represented, out_dtype=dtype, default=default
)
else:
if vertex_property.ndim == 1:
cell_property = nd.mean(vertex_property, vertex_cells, index=cell_labels)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment