@francois You can ignore part of a volume that is outside a segment as @cpinter described. You can also get a point inside a segment nearest to its center using segmentationNode.GetSegmentCenterRAS (this is useful if you want to jump to a slice where the segment is visible; the center of gravity may be outside the segment). If to7 want to compute the center of gravity yourself then you can do so using numpy (you can use np.where
to ignore values that are outside the range you are interested in).
Note that 0 HU value corresponds to water (fat, soft tissue, …) so it might not be suitable as a threshold. HU value of air is -1000, you can use that as a thrshold for determining if a voxel is “empty”.
What would you like to use center of gravity for?