Easy way to get number of vertices from segmentation in python

Hey everyone.

I am would like to get the number of vertices of a model via Python, but I also need this model as a segment, not a modelNode.

I found a way to get this on the GUI via models → information → number of points and for modelNodes as len(slicer.util.arrayFromModelPoints(modelNode) but these both do not work with SegmentationNodes.

is there an easy way to do this?

Thanks in advance :smiley:

You can export segments to models by right-clicking on the segmentation in Data module. You can also access the vtkPolyData object of a segment with a few Python commands and get the number of points from there.

Usually the segmentation’s closed surface representation is generated on-the-fly from the labelmap representation, so the number of points in it should not matter. Why do you need this information?

I am working on a KI project, where I need all of my models to have the same size (otherwise it’s doing weird things). currently I’m doing this with MeshLab (here I can set a target face number, instead of target reduction number), but I want to reduce the number of dependencies as much as possible.
I might get away with doing this all in modelNodes instead of segmentations, but if there were a way to get basically the number of faces without a conversion to modelNodes first, that’d be great.

Number of faces does not matter, correspondence does. Because if n-th cell in one mesh does not correspond to n-th cell in the other mesh (e.g., they are not at the same anatomical location) then the two meshes are completely unrelated, even if two meshes have the same number of faces.

Decimation and all kinds of mesh reduction methods can change the number of faces but does not provide correspondence between meshes. What you need is spatial registration of models - warp one model to be aligned to the other, which results in not just the same number of faces but all points and faces corresponding to each other in the two meshes. Most commonly used model registration methods in Slicer are described here.