Skip to content

Commit b4c7608

Browse files
committed
use resizing inside of _run_net() and _compute_masks()
1 parent 30503c9 commit b4c7608

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

cellpose/models.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,9 @@ def eval(self, x, batch_size=8, resample=True, channels=None, channel_axis=None,
268268
x = x[np.newaxis, ...]
269269
nimg = x.shape[0]
270270

271-
image_scaling = None
272-
Ly_0 = x.shape[1]
273-
Lx_0 = x.shape[2]
274-
Lz_0 = None
275-
if do_3D or stitch_threshold > 0:
276-
Lz_0 = x.shape[0]
277-
if diameter is not None:
271+
image_scaling = 1.0
272+
if diameter is not None and diameter > 0:
278273
image_scaling = 30. / diameter
279-
x = transforms.resize_image(x,
280-
Ly=int(x.shape[1] * image_scaling),
281-
Lx=int(x.shape[2] * image_scaling))
282274

283275

284276
# normalize image
@@ -306,13 +298,10 @@ def eval(self, x, batch_size=8, resample=True, channels=None, channel_axis=None,
306298
if do_normalization:
307299
x = transforms.normalize_img(x, **normalize_params)
308300

309-
# ajust the anisotropy when diameter is specified and images are resized:
310-
if isinstance(anisotropy, (float, int)) and image_scaling:
311-
anisotropy = image_scaling * anisotropy
312-
313301
dP, cellprob, styles = self._run_net(
314302
x,
315303
resample=resample,
304+
rescale=image_scaling,
316305
augment=augment,
317306
batch_size=batch_size,
318307
tile_overlap=tile_overlap,
@@ -337,10 +326,14 @@ def eval(self, x, batch_size=8, resample=True, channels=None, channel_axis=None,
337326
# use user niter if specified, otherwise scale niter (200) with diameter
338327
niter_scale = 1 if image_scaling is None else image_scaling
339328
niter = int(200/niter_scale) if niter is None or niter == 0 else niter
340-
masks = self._compute_masks((Lz_0 or nimg, Ly_0, Lx_0), dP, cellprob, flow_threshold=flow_threshold,
341-
cellprob_threshold=cellprob_threshold, min_size=min_size,
342-
max_size_fraction=max_size_fraction, niter=niter,
343-
stitch_threshold=stitch_threshold, do_3D=do_3D)
329+
masks = self._compute_masks(x.shape, dP, cellprob,
330+
flow_threshold=flow_threshold,
331+
cellprob_threshold=cellprob_threshold,
332+
min_size=min_size,
333+
max_size_fraction=max_size_fraction,
334+
niter=niter,
335+
stitch_threshold=stitch_threshold,
336+
do_3D=do_3D)
344337
else:
345338
masks = np.zeros(0) #pass back zeros if not compute_masks
346339

0 commit comments

Comments
 (0)