Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Answers - Cellpose

First run the main notebook

Exercise: What happens when you change the diameter?

diameter  30 ->  55 objects
diameter  60 ->  37 objects
diameter  80 ->  35 objects
diameter 120 ->  31 objects
diameter 160 ->  26 objects
diameter 200 ->  21 objects
diameter 240 ->  10 objects
<Figure size 640x480 with 1 Axes>
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[5], line 5
      1 # We can plot it like this
      2 fig, axs = plt.subplots(1, 4, figsize=(20, 5))
      3 for ax, d in zip(axs, diameters):
      4     _ = ax.imshow(img_nuclei, cmap="gray")
----> 5     _ = ax.imshow(masks_per_diameter[d], cmap=lbl_cmap, alpha=0.5)
      6     _ = ax.set_title(f"diameter={d}: {masks_per_diameter[d].max()} objects")
      7     _ = ax.axis("off")

NameError: name 'lbl_cmap' is not defined
<Figure size 2000x500 with 4 Axes>
  • Too small (30, which is also the default): nuclei are cut into pieces, just like StarDist at scale=1.

  • Too large (120): fewer objects, because small nuclei are missed or neighbours merge.

  • Between 60 and 80 the result is stable.

The two parameters work in opposite directions: a larger Cellpose diameter and a smaller StarDist scale both mean the image is shrunk more before it reaches the network.

Exercise: Do StarDist and Cellpose find the same nuclei?

We redo the StarDist prediction here and put the two results next to each other.

The two methods find nearly the same nuclei, and the outlines differ by a few pixels. StarDist finds a few more objects than Cellpose: some of those are nuclei that Cellpose missed, and a few are small objects that are not nuclei. Those could be filtered out.

For counting foci per nucleus these shape differences do not matter much. For measuring nuclear area or intensity they can, so it is worth looking at the overlays before choosing one.