Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 18 additions & 1 deletion cellpose/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block was removed when I purged all resample/rescale code from CP4. It's verbatim cp3, and now actually does what the function name implies.

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)

Expand Down
6 changes: 0 additions & 6 deletions cellpose/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [], [], []
Expand Down
6 changes: 6 additions & 0 deletions tests/test_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading