Skip to content

Fix neighbouring cell gradient contamination in _extend_centers_gpu - #1487

Open
remi-pigache wants to merge 1 commit into
MouseLand:mainfrom
remi-pigache:fix/flow_neighbor_contamination
Open

Fix neighbouring cell gradient contamination in _extend_centers_gpu#1487
remi-pigache wants to merge 1 commit into
MouseLand:mainfrom
remi-pigache:fix/flow_neighbor_contamination

Conversation

@remi-pigache

Copy link
Copy Markdown

Fixes #1486
By using the already defined isneighbor array, the 'grad' values concerning pixels outside of the cell can be filtered out. It effectively makes the gradient generation independant of whether the pixels outside of the cell are background or belonging to another cell. Please find attached a single 3D slice of the input masks, the flows before and after the fix and the masks before and after the fix using the following script :

from cellpose.dynamics import masks_to_flows_gpu_3d, follow_flows, get_masks_torch
import tifffile
import numpy as np
masks = tifffile.imread("masks.tif")
inds = np.nonzero(masks>0)
flows = masks_to_flows_gpu_3d(masks)
p = follow_flows(flows, inds)
regenerated_masks = get_masks_torch(p.int(), inds, masks.shape)
tifffile.imwrite("masks_regenerated.tif", regenerated_masks)
tifffile.imwrite("flows.tif", flows)
input masks input image current flows current masks

current ZYX flows | current masks reconstruction

fixed flows fixed masks

fixed ZYX flows | fixed masks reconstruction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Flow generation is perturbed by neighboring cells

1 participant