Skip to content

Commit

Permalink
Merge pull request #416 from JoostJM/add-center-of-mass
Browse files Browse the repository at this point in the history
Add center of mass (General Info)
  • Loading branch information
JoostJM authored Aug 28, 2018
2 parents 217a840 + 91405b0 commit f3ee994
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions radiomics/generalinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,36 @@ def getImageSpacingValue(self):
else:
return None

def getCenterOfMassIndexValue(self):
"""
Returns z, y and x coordinates of the center of mass of the ROI in terms of the image coordinate space (continuous index).
Calculation is based on the original (non-resampled) mask.
.. note::
Because this represents the continuous index, the order of x, y and z is reversed, i.e. the first element is the z index, the second
the y index and the last element is the x index.
"""
if self.mask is not None:
maskArray = sitk.GetArrayFromImage(self.mask)
maskCoordinates = numpy.array(numpy.where(maskArray == self.label))
center_index = numpy.mean(maskCoordinates, axis=1)
return tuple(center_index)
else:
return None

def getCenterOfMassValue(self):
"""
Returns the real-world x, y and z coordinates of the center of mass of the ROI. This is the real-world transformation of
:py:func:`~radiomics.generalinfo.getCenterOfMassIndexValue()`, taking into account the spacing, direction and origin of the mask.
Calculation is based on the original (non-resampled) mask.
"""
if self.mask is not None:
return self.mask.TransformContinuousIndexToPhysicalPoint(self.getCenterOfMassIndexValue())
else:
return None

def getEnabledImageTypesValue(self):
"""
Return a string representation of the enabled image types and any custom settings for each image type.
Expand Down

0 comments on commit f3ee994

Please sign in to comment.