Mulai sekarangMulai gratis

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.

Latihan ini merupakan bagian dari kursus

Biomedical Image Analysis in Python

Lihat Kursus

Instruksi latihan

  • Using vol and labels, 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 to x values and rows to y values.

Latihan interaktif langsung praktik

Cobalah latihan ini dengan melengkapi kode contoh ini.

# 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()
Edit dan Jalankan Kode