Skip to content

Commit 36bcae0

Browse files
renaming dP_smooth to flow3D_smooth so that it is more clear what it does
1 parent 7943957 commit 36bcae0

File tree

8 files changed

+29
-28
lines changed

8 files changed

+29
-28
lines changed

cellpose/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def main():
219219
interp=(not args.no_interp), normalize=normalize,
220220
channel_axis=args.channel_axis, z_axis=args.z_axis,
221221
anisotropy=args.anisotropy, niter=args.niter,
222-
dP_smooth=args.dP_smooth)
222+
flow3D_smooth=args.flow3D_smooth)
223223
masks, flows = out[:2]
224224
if len(out) > 3 and restore_type is None:
225225
diams = out[-1]

cellpose/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def get_arg_parser():
115115
"--min_size", required=False, default=15, type=int,
116116
help="minimum number of pixels per mask, can turn off with -1")
117117
algorithm_args.add_argument(
118-
"--dP_smooth", required=False, default=0, type=float,
118+
"--flow3D_smooth", required=False, default=0, type=float,
119119
help="stddev of gaussian for smoothing of dP for dynamics in 3D, default of 0 means no smoothing")
120120

121121
algorithm_args.add_argument(

cellpose/denoise.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
if ctype != "cyto3":
2929
for ltype in ["per", "seg", "rec"]:
3030
MODEL_NAMES.append(f"{ntype}_{ltype}_{ctype}")
31+
if ctype != "cyto3":
32+
MODEL_NAMES.append(f"aniso_{ctype}")
3133

3234
criterion = nn.MSELoss(reduction="mean")
3335
criterion2 = nn.BCEWithLogitsLoss(reduction="mean")
@@ -505,7 +507,7 @@ def eval(self, x, batch_size=8, channels=None, channel_axis=None, z_axis=None,
505507
normalize=True, rescale=None, diameter=None, tile_overlap=0.1,
506508
augment=False, resample=True, invert=False, flow_threshold=0.4,
507509
cellprob_threshold=0.0, do_3D=False, anisotropy=None, stitch_threshold=0.0,
508-
min_size=15, niter=None, interp=True, bsize=224, dP_smooth=0):
510+
min_size=15, niter=None, interp=True, bsize=224, flow3D_smooth=0):
509511
"""
510512
Restore array or list of images using the image restoration model, and then segment.
511513
@@ -547,7 +549,7 @@ def eval(self, x, batch_size=8, channels=None, channel_axis=None, z_axis=None,
547549
anisotropy (float, optional): for 3D segmentation, optional rescaling factor (e.g. set to 2.0 if Z is sampled half as dense as X or Y). Defaults to None.
548550
stitch_threshold (float, optional): if stitch_threshold>0.0 and not do_3D, masks are stitched in 3D to return volume segmentation. Defaults to 0.0.
549551
min_size (int, optional): all ROIs below this size, in pixels, will be discarded. Defaults to 15.
550-
dP_smooth (int, optional): if do_3D and dP_smooth>0, smooth flows with gaussian filter of this stddev. Defaults to 0.
552+
flow3D_smooth (int, optional): if do_3D and flow3D_smooth>0, smooth flows with gaussian filter of this stddev. Defaults to 0.
551553
niter (int, optional): number of iterations for dynamics computation. if None, it is set proportional to the diameter. Defaults to None.
552554
interp (bool, optional): interpolate during 2D dynamics (not available in 3D) . Defaults to True.
553555

cellpose/gui/gui.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def __init__(self, image=None, logger=None):
301301

302302
self.load_3D = False
303303
self.stitch_threshold = 0.
304-
self.dP_smooth = 0.
304+
self.flow3D_smooth = 0.
305305
self.anisotropy = 1.
306306
self.min_size = 15
307307
self.resample = True
@@ -2420,8 +2420,8 @@ def compute_segmentation(self, custom=False, model_name=None, load_model=True):
24202420
self.stitch_threshold, float) else self.stitch_threshold
24212421
anisotropy = float(self.anisotropy.text()) if not isinstance(
24222422
self.anisotropy, float) else self.anisotropy
2423-
dP_smooth = float(self.dP_smooth.text()) if not isinstance(
2424-
self.dP_smooth, float) else self.dP_smooth
2423+
flow3D_smooth = float(self.flow3D_smooth.text()) if not isinstance(
2424+
self.flow3D_smooth, float) else self.flow3D_smooth
24252425
min_size = int(self.min_size.text()) if not isinstance(
24262426
self.min_size, int) else self.min_size
24272427
resample = self.resample.isChecked() if not isinstance(
@@ -2446,7 +2446,7 @@ def compute_segmentation(self, custom=False, model_name=None, load_model=True):
24462446
cellprob_threshold=cellprob_threshold,
24472447
flow_threshold=flow_threshold, do_3D=do_3D, niter=niter,
24482448
normalize=normalize_params, stitch_threshold=stitch_threshold,
2449-
anisotropy=anisotropy, resample=resample, dP_smooth=dP_smooth,
2449+
anisotropy=anisotropy, resample=resample, flow3D_smooth=flow3D_smooth,
24502450
min_size=min_size,
24512451
progress=self.progress, z_axis=0 if self.NZ > 1 else None)[:2]
24522452
except Exception as e:

cellpose/gui/gui3d.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,20 @@ def __init__(self, image=None, logger=None):
165165
)
166166
self.segBoxG.addWidget(self.stitch_threshold, b, 4, 1, 1)
167167

168-
label = QLabel("dP_smooth:")
168+
label = QLabel("flow3D_smooth:")
169169
label.setToolTip(
170-
"for 3D volumes, smooth flows by a Gaussian with standard deviation dP_smooth (see docs for details)"
170+
"for 3D volumes, smooth flows by a Gaussian with standard deviation flow3D_smooth (see docs for details)"
171171
)
172172
label.setFont(self.medfont)
173173
self.segBoxG.addWidget(label, b, 5, 1, 3)
174-
self.dP_smooth = QLineEdit()
175-
self.dP_smooth.setText("0.0")
176-
self.dP_smooth.setFixedWidth(30)
177-
self.dP_smooth.setFont(self.medfont)
178-
self.dP_smooth.setToolTip(
179-
"for 3D volumes, smooth flows by a Gaussian with standard deviation dP_smooth (see docs for details)"
174+
self.flow3D_smooth = QLineEdit()
175+
self.flow3D_smooth.setText("0.0")
176+
self.flow3D_smooth.setFixedWidth(30)
177+
self.flow3D_smooth.setFont(self.medfont)
178+
self.flow3D_smooth.setToolTip(
179+
"for 3D volumes, smooth flows by a Gaussian with standard deviation flow3D_smooth (see docs for details)"
180180
)
181-
self.segBoxG.addWidget(self.dP_smooth, b, 8, 1, 1)
181+
self.segBoxG.addWidget(self.flow3D_smooth, b, 8, 1, 1)
182182

183183
b+=1
184184
label = QLabel("anisotropy:")

cellpose/io.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ def save_rois(masks, file_name, multiprocessing=None):
608608

609609

610610
def save_masks(images, masks, flows, file_names, png=True, tif=False, channels=[0, 0],
611-
suffix="", save_flows=False, save_outlines=False, dir_above=False,
611+
suffix="_cp_masks", save_flows=False, save_outlines=False, dir_above=False,
612612
in_folders=False, savedir=None, save_txt=False, save_mpl=False):
613613
""" Save masks + nicely plotted segmentation image to png and/or tiff.
614614
@@ -630,7 +630,7 @@ def save_masks(images, masks, flows, file_names, png=True, tif=False, channels=[
630630
png (bool, optional): Save masks to PNG. Defaults to True.
631631
tif (bool, optional): Save masks to TIF. Defaults to False.
632632
channels (list, int, optional): Channels used to run Cellpose. Defaults to [0,0].
633-
suffix (str, optional): Add name to saved masks. Defaults to "".
633+
suffix (str, optional): Add name to saved masks. Defaults to "_cp_masks".
634634
save_flows (bool, optional): Save flows output from Cellpose.eval. Defaults to False.
635635
save_outlines (bool, optional): Save outlines of masks. Defaults to False.
636636
dir_above (bool, optional): Save masks/flows in directory above. Defaults to False.
@@ -709,8 +709,7 @@ def save_masks(images, masks, flows, file_names, png=True, tif=False, channels=[
709709
with warnings.catch_warnings():
710710
warnings.simplefilter("ignore")
711711
for ext in exts:
712-
713-
imsave(os.path.join(maskdir, basename + "_cp_masks" + suffix + ext), masks)
712+
imsave(os.path.join(maskdir, basename + suffix + ext), masks)
714713

715714
if save_mpl and png and MATPLOTLIB and not min(images.shape) > 3:
716715
# Make and save original/segmentation/flows image

cellpose/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def __init__(self, gpu=False, pretrained_model=False, model_type=None,
381381
def eval(self, x, batch_size=8, resample=True, channels=None, channel_axis=None,
382382
z_axis=None, normalize=True, invert=False, rescale=None, diameter=None,
383383
flow_threshold=0.4, cellprob_threshold=0.0, do_3D=False, anisotropy=None,
384-
dP_smooth=0, stitch_threshold=0.0,
384+
flow3D_smooth=0, stitch_threshold=0.0,
385385
min_size=15, max_size_fraction=0.4, niter=None,
386386
augment=False, tile_overlap=0.1, bsize=224,
387387
interp=True, compute_masks=True, progress=None):
@@ -420,7 +420,7 @@ def eval(self, x, batch_size=8, resample=True, channels=None, channel_axis=None,
420420
flow_threshold (float, optional): flow error threshold (all cells with errors below threshold are kept) (not used for 3D). Defaults to 0.4.
421421
cellprob_threshold (float, optional): all pixels with value above threshold kept for masks, decrease to find more and larger masks. Defaults to 0.0.
422422
do_3D (bool, optional): set to True to run 3D segmentation on 3D/4D image input. Defaults to False.
423-
dP_smooth (int, optional): if do_3D and dP_smooth>0, smooth flows with gaussian filter of this stddev. Defaults to 0.
423+
flow3D_smooth (int, optional): if do_3D and flow3D_smooth>0, smooth flows with gaussian filter of this stddev. Defaults to 0.
424424
anisotropy (float, optional): for 3D segmentation, optional rescaling factor (e.g. set to 2.0 if Z is sampled half as dense as X or Y). Defaults to None.
425425
stitch_threshold (float, optional): if stitch_threshold>0.0 and not do_3D, masks are stitched in 3D to return volume segmentation. Defaults to 0.0.
426426
min_size (int, optional): all ROIs below this size, in pixels, will be discarded. Defaults to 15.
@@ -467,7 +467,7 @@ def eval(self, x, batch_size=8, resample=True, channels=None, channel_axis=None,
467467
interp=interp, flow_threshold=flow_threshold,
468468
cellprob_threshold=cellprob_threshold, compute_masks=compute_masks,
469469
min_size=min_size, max_size_fraction=max_size_fraction,
470-
stitch_threshold=stitch_threshold, dP_smooth=dP_smooth,
470+
stitch_threshold=stitch_threshold, flow3D_smooth=flow3D_smooth,
471471
progress=progress, niter=niter)
472472
masks.append(maski)
473473
flows.append(flowi)
@@ -522,9 +522,9 @@ def eval(self, x, batch_size=8, resample=True, channels=None, channel_axis=None,
522522
resample=resample, do_3D=do_3D, anisotropy=anisotropy)
523523

524524
if do_3D:
525-
if dP_smooth > 0:
526-
models_logger.info(f"smoothing flows with sigma={dP_smooth}")
527-
dP = gaussian_filter(dP, (0, dP_smooth, dP_smooth, dP_smooth))
525+
if flow3D_smooth > 0:
526+
models_logger.info(f"smoothing flows with sigma={flow3D_smooth}")
527+
dP = gaussian_filter(dP, (0, flow3D_smooth, flow3D_smooth, flow3D_smooth))
528528
torch.cuda.empty_cache()
529529
gc.collect()
530530

docs/do3d.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Specify this segmentation format in the notebook with ``do_3D=True`` or in the C
4949
(with the CLI it will segment all tiffs in the folder as 3D tiffs if possible).
5050

5151
If you see many cells that are fragmented, you can smooth the flows before the dynamics
52-
are run in 3D using the ``dP_smooth`` parameter, which specifies the standard deviation of
52+
are run in 3D using the ``flow3D_smooth`` parameter, which specifies the standard deviation of
5353
a Gaussian for smoothing the flows. The default is 0.0, which means no smoothing. Alternatively/additionally,
5454
you may want to train a model on 2D slices from your 3D data to improve the segmentation (see below).
5555

0 commit comments

Comments
 (0)