Pinpoint center of mass
The distance transformation reveals the most embedded portions of an object. On the other hand, ndi.center_of_mass()
returns the coordinates for the center of an object.
The "mass" corresponds to intensity values, with higher values pulling the center closer to it.
For this exercise, calculate the center of mass for the two labeled areas. Then, plot them on top of the image.
This is a part of the course
“Biomedical Image Analysis in Python”
Exercise instructions
- Using
vol
andlabels
, calculate the center of mass for the two labeled objects. Print the coordinates. - Use
plt.scatter()
to add the center of mass markers to the plot. Note that scatterplots draw from the bottom-left corner. Image columns correspond tox
values and rows toy
values.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Extract centers of mass for objects 1 and 2
coms = ____
print('Label 1 center:', ____)
print('Label 2 center:', ____)
# Add marks to plot
for c0, c1, c2 in coms:
plt.scatter(____, ____, s=100, marker='o')
plt.show()
This exercise is part of the course
Biomedical Image Analysis in Python
Learn the fundamentals of exploring, manipulating, and measuring biomedical image data.
In this chapter, you'll get to the heart of image analysis: object measurement. Using a 4D cardiac time series, you'll determine if a patient is likely to have heart disease. Along the way, you'll learn the fundamentals of image segmentation, object labeling, and morphological measurement.
Exercise 1: Objects and labelsExercise 2: Segment the heartExercise 3: Select objectsExercise 4: Extract objectsExercise 5: Measuring intensityExercise 6: Measure varianceExercise 7: Separate histogramsExercise 8: Measuring morphologyExercise 9: Calculate volumeExercise 10: Calculate distanceExercise 11: Pinpoint center of massExercise 12: Measuring in timeExercise 13: Summarize the time seriesExercise 14: Measure ejection fractionWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.