Center of mass calculation

How can we ignore part a volume in order to calculate a center of mass, based on HU. It seems that each tine it takes into account the “empty” voxels whatever value is applied: 0 or NaN.

You need to segment your region of interest with Segment Editor, then from there it’s very easy to get the center of mass of the segment using Segment Statistics for example.

@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?

Well I work on bone (foot bones) using WBCT dicoms. I want to transform both the dicom volume and the segment to a new reference frame where the COM is the origin.

In this case, center of gravity computed based on HU might not what you need (you don’t want cortical bone to throw off computation of the bone axis), but you may want to use solidified segmentation of the bone.

Check out this extension - it may provide useful features for you:

You can get fully automatic human feet bones segmentation from TotalSegmentator extension.

1 Like

Thank you so much for the extension link.