Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add center of mass (General Info) #416

Merged
merged 1 commit into from
Aug 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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