Skip to content

Commit 0577880

Browse files
Merge pull request #1438 from MouseLand/resample_fix
Resample fix
2 parents 71e7e88 + d69a662 commit 0577880

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

cellpose/dynamics.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Copyright © 2025 Howard Hughes Medical Institute, Authored by Carsen Stringer , Michael Rariden and Marius Pachitariu.
33
"""
44
import os
5+
import cv2
6+
from cellpose import transforms
57
from scipy.ndimage import find_objects, center_of_mass, mean
68
import torch
79
import numpy as np
@@ -614,7 +616,22 @@ def resize_and_compute_masks(dP, cellprob, niter=200, cellprob_threshold=0.0,
614616
device=device)
615617

616618
if resize is not None:
617-
dynamics_logger.warning("Resizing is deprecated in v4.0.1+")
619+
if len(resize) == 2:
620+
mask = transforms.resize_image(mask, resize[0], resize[1], no_channels=True,
621+
interpolation=cv2.INTER_NEAREST)
622+
else:
623+
Lz, Ly, Lx = resize
624+
if mask.shape[0] != Lz or mask.shape[1] != Ly:
625+
dynamics_logger.info("resizing 3D masks to original image size")
626+
if mask.shape[1] != Ly:
627+
mask = transforms.resize_image(mask, Ly=Ly, Lx=Lx,
628+
no_channels=True,
629+
interpolation=cv2.INTER_NEAREST)
630+
if mask.shape[0] != Lz:
631+
mask = transforms.resize_image(mask.transpose(1,0,2),
632+
Ly=Lz, Lx=Lx,
633+
no_channels=True,
634+
interpolation=cv2.INTER_NEAREST).transpose(1,0,2)
618635

619636
mask = utils.fill_holes_and_remove_small_masks(mask, min_size=min_size)
620637

cellpose/models.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,6 @@ def eval(self, x, batch_size=8, resample=True, channels=None, channel_axis=None,
212212
styles (list of 1D arrays of length 256 or single 1D array): Style vector containing only zeros. Retained for compaibility with CP3.
213213
214214
"""
215-
216-
if rescale is not None:
217-
models_logger.warning("rescaling deprecated in v4.0.1+")
218-
if channels is not None:
219-
models_logger.warning("channels deprecated in v4.0.1+. If data contain more than 3 channels, only the first 3 channels will be used")
220-
221215
if isinstance(x, list) or x.squeeze().ndim == 5:
222216
self.timing = []
223217
masks, styles, flows = [], [], []

tests/test_shape.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ def test_shape_2D_grayscale(cellposemodel_fixture_24layer):
99
assert masks.shape == (224, 224)
1010

1111

12+
def test_shape_2D_grayscale_resample(cellposemodel_fixture_2layer):
13+
img = np.zeros((224, 224))
14+
masks, _, _ = cellposemodel_fixture_2layer.eval(img, diameter=20, resample=False)
15+
assert masks.shape == (224, 224)
16+
17+
1218
def test_shape_2D_chan_first_diam_resize(cellposemodel_fixture_24layer):
1319
img = np.zeros((1, 224, 224))
1420
masks, flows, _ = cellposemodel_fixture_24layer.eval(img, diameter=50)

0 commit comments

Comments
 (0)