MouseLand/cellpose

[Question] Change in cellpix id when reloaded

Closed this issue · 1 comments

I'm currently updating my add-on functions (originally built on v2.3.2) to be compatible with the latest version of Cellpose (v3.0.10 release) [https://github.com/MouseLand/cellpose/releases/tag/v3.0.10].

While reviewing the major differences, I noticed that in the latest version, the original cellpix IDs are changed when loading a previous seg.npy file.

In v2.3.2, when loading the seg.npy file, the data is loaded directly from the file:

cellpose/cellpose/gui/io.py

Lines 309 to 311 in 28ddc24

parent.cellpix = dat['masks']
parent.outpix = dat['outlines']
parent.cellcolors = np.append(parent.cellcolors, colors, axis=0)

However, in the new version, the masks_to_gui function is called instead, which alters the cellpix IDs due to the fastremap.renumber function:

_masks_to_gui(parent, dat["masks"], outlines=dat["outlines"], colors=colors)

I haven’t delved deeply into that function, but it seems like the cellpix IDs are remapped top-to-bottom and right-to-left. This could mean that if another mask is added in the top corner of the FOV, the IDs and corresponding colors of all masks would change.

I’m wondering if this is intended behavior.

thanks for noticing this yes here:

fastremap.renumber(masks, in_place=True)

I will turn this off unless there are missing mask ids - then we have to renumber