import numpy as np import matplotlib.pyplot as plt from cellpose import models, io from skimage.io import imread from skimage.measure import regionprops
io.logger_setup()
model = models.Cellpose(gpu=True, model_type='cyto3')
image_path = '/Volumes/Extreme Pro/MCK characterization/ANALYSISTRAINING.tif' image = imread(image_path)
if image.ndim == 3 and image.shape[2] == 4: # Extract channel 3 (assuming 0-based index, so channel 3 is the fourth channel) channel_3_image = image[:, :, 3] else: print("Image does not have the expected number of channels.") exit()
masks, flows, styles, diams = model.eval([channel_3_image], diameter=None, channels=[3, 3])
props = regionprops(masks[0])
centroids = np.array([prop.centroid for prop in props]) # List of (y, x) coordinates
fig, ax = plt.subplots() ax.imshow(channel_3_image, cmap='gray') ax.scatter(centroids[:, 1], centroids[:, 0], color='red', s=20) # Note: centroids[:, 1] is x, centroids[:, 0] is y plt.title('Centroids in Channel 3') plt.show()