MouseLand / cellpose

a generalist algorithm for cellular segmentation with human-in-the-loop capabilities
https://www.cellpose.org/
BSD 3-Clause "New" or "Revised" License
1.4k stars 403 forks source link

[Question] Change in cellpix id when reloaded #1029

Closed knowblesse closed 1 month ago

knowblesse commented 1 month ago

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: https://github.com/MouseLand/cellpose/blob/28ddc24fa36f57b20932b842f4210e0caa3ea4e5/cellpose/gui/io.py#L309-L311

However, in the new version, the masks_to_gui function is called instead, which alters the cellpix IDs due to the fastremap.renumber function: https://github.com/MouseLand/cellpose/blob/9a0d61f6381308400cafd3b2088d13bbfc497ae6/cellpose/gui/io.py#L382

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.

carsen-stringer commented 1 month ago

thanks for noticing this yes here: https://github.com/MouseLand/cellpose/blob/9a0d61f6381308400cafd3b2088d13bbfc497ae6/cellpose/gui/io.py#L481

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