Skip to content

Commit

Permalink
Merge branch 'main' into feature/progress_bars
Browse files Browse the repository at this point in the history
  • Loading branch information
psobolewskiPhD authored Sep 25, 2024
2 parents 5f95e78 + c129834 commit e3c8921
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions cellpose_napari/_dock_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,16 @@ def compute_diameter(image, channels, model_type):

@thread_worker(progress=True)
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

0 comments on commit e3c8921

Please sign in to comment.