Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] use resize_and_compute_masks in compute_masks #57

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions cellpose_napari/_dock_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def run_cellpose(image, model_type, custom_model, channels, channel_axis, diamet
CP = models.CellposeModel(pretrained_model=custom_model, gpu=True)
else:
CP = models.CellposeModel(model_type=model_type, gpu=True)

print(cellprob_threshold, flow_threshold)
masks, flows_orig, _ = CP.eval(image,
channels=channels,
channel_axis=channel_axis,
Expand Down Expand Up @@ -105,22 +107,16 @@ def compute_diameter(image, channels, model_type):

@thread_worker
def compute_masks(masks_orig, flows_orig, cellprob_threshold, flow_threshold):
import cv2
from cellpose.utils import fill_holes_and_remove_small_masks
from cellpose.dynamics import get_masks
from cellpose.transforms import resize_image
from cellpose.dynamics import resize_and_compute_masks

#print(flows_orig[3].shape, flows_orig[2].shape, masks_orig.shape)
flow_threshold = (31.0 - flow_threshold) / 10.
if flow_threshold==0.0:
flow_threshold = 0.0
logger.debug('flow_threshold=0 => no masks thrown out due to model mismatch')
logger.debug(f'computing masks with cellprob_threshold={cellprob_threshold}, flow_threshold={flow_threshold}')
maski = get_masks(flows_orig[3].copy(), iscell=(flows_orig[2] > cellprob_threshold),
flows=flows_orig[1], threshold=flow_threshold*(masks_orig.ndim<3))
maski = fill_holes_and_remove_small_masks(maski)
maski = resize_image(maski, masks_orig.shape[-2], masks_orig.shape[-1],
interpolation=cv2.INTER_NEAREST)
maski, _ = resize_and_compute_masks(flows_orig[1], cellprob=flows_orig[2], cellprob_threshold=cellprob_threshold,
flow_threshold=flow_threshold, resize=(masks_orig.shape[-2], masks_orig.shape[-1]))

return maski

@magicgui(
Expand Down
Loading