From 00b633bc5c2f3ca17ec55fbf9a83d7b0670c9fbb Mon Sep 17 00:00:00 2001 From: Michael Rariden Date: Tue, 28 Apr 2026 13:27:59 -0400 Subject: [PATCH 1/3] add failing test per ##1434 --- tests/test_shape.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_shape.py b/tests/test_shape.py index d9eca338..0e42b99e 100644 --- a/tests/test_shape.py +++ b/tests/test_shape.py @@ -9,6 +9,12 @@ def test_shape_2D_grayscale(cellposemodel_fixture_24layer): assert masks.shape == (224, 224) +def test_shape_2D_grayscale_resample(cellposemodel_fixture_2layer): + img = np.zeros((224, 224)) + masks, _, _ = cellposemodel_fixture_2layer.eval(img, diameter=20, resample=False) + assert masks.shape == (224, 224) + + def test_shape_2D_chan_first_diam_resize(cellposemodel_fixture_24layer): img = np.zeros((1, 224, 224)) masks, flows, _ = cellposemodel_fixture_24layer.eval(img, diameter=50) From 72c3218416eb14e4f74a32b608b0e5adc342a671 Mon Sep 17 00:00:00 2001 From: Michael Rariden Date: Tue, 28 Apr 2026 13:29:30 -0400 Subject: [PATCH 2/3] fix: do mask resizing with resample --- cellpose/dynamics.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cellpose/dynamics.py b/cellpose/dynamics.py index 4176a5b3..50df8af7 100644 --- a/cellpose/dynamics.py +++ b/cellpose/dynamics.py @@ -2,6 +2,8 @@ Copyright © 2025 Howard Hughes Medical Institute, Authored by Carsen Stringer , Michael Rariden and Marius Pachitariu. """ import os +import cv2 +from cellpose import transforms from scipy.ndimage import find_objects, center_of_mass, mean import torch import numpy as np @@ -614,7 +616,22 @@ def resize_and_compute_masks(dP, cellprob, niter=200, cellprob_threshold=0.0, device=device) if resize is not None: - dynamics_logger.warning("Resizing is deprecated in v4.0.1+") + if len(resize) == 2: + mask = transforms.resize_image(mask, resize[0], resize[1], no_channels=True, + interpolation=cv2.INTER_NEAREST) + else: + Lz, Ly, Lx = resize + if mask.shape[0] != Lz or mask.shape[1] != Ly: + dynamics_logger.info("resizing 3D masks to original image size") + if mask.shape[1] != Ly: + mask = transforms.resize_image(mask, Ly=Ly, Lx=Lx, + no_channels=True, + interpolation=cv2.INTER_NEAREST) + if mask.shape[0] != Lz: + mask = transforms.resize_image(mask.transpose(1,0,2), + Ly=Lz, Lx=Lx, + no_channels=True, + interpolation=cv2.INTER_NEAREST).transpose(1,0,2) mask = utils.fill_holes_and_remove_small_masks(mask, min_size=min_size) From d69a662d315460462bd5de1eed0a3740b1dfeec1 Mon Sep 17 00:00:00 2001 From: Michael Rariden Date: Tue, 28 Apr 2026 17:18:46 -0400 Subject: [PATCH 3/3] remove eval() arg warnings --- cellpose/models.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cellpose/models.py b/cellpose/models.py index b63604ba..146f640d 100644 --- a/cellpose/models.py +++ b/cellpose/models.py @@ -212,12 +212,6 @@ def eval(self, x, batch_size=8, resample=True, channels=None, channel_axis=None, styles (list of 1D arrays of length 256 or single 1D array): Style vector containing only zeros. Retained for compaibility with CP3. """ - - if rescale is not None: - models_logger.warning("rescaling deprecated in v4.0.1+") - if channels is not None: - models_logger.warning("channels deprecated in v4.0.1+. If data contain more than 3 channels, only the first 3 channels will be used") - if isinstance(x, list) or x.squeeze().ndim == 5: self.timing = [] masks, styles, flows = [], [], []