Skip to content

Commit 89ab381

Browse files
Merge branch 'antoinemeyer5-feat/output-naming'
2 parents d557093 + f6df6a2 commit 89ab381

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

cellpose/__main__.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def main():
3131
"""
3232

3333
args = get_arg_parser().parse_args(
34-
) # this has to be in a seperate file for autodoc to work
34+
) # this has to be in a separate file for autodoc to work
3535

3636
if args.version:
3737
print(version_str)
@@ -148,6 +148,10 @@ def main():
148148
raise ValueError(f"ERROR: no file found at {args.image_path}")
149149
nimg = len(image_names)
150150

151+
if args.savedir:
152+
if not os.path.exists(args.savedir):
153+
raise FileExistsError("--savedir {args.savedir} does not exist")
154+
151155
cstr0 = ["GRAY", "RED", "GREEN", "BLUE"]
152156
cstr1 = ["NONE", "RED", "GREEN", "BLUE"]
153157
logger.info(
@@ -240,8 +244,17 @@ def main():
240244
diams=diams, restore_type=restore_type,
241245
ratio=1.)
242246
if saving_something:
243-
suffix = args.output_name if len(args.output_name) > 0 else "_cp_masks"
244-
io.save_masks(image, masks, flows, image_name,
247+
suffix = "_cp_masks"
248+
if args.output_name is not None:
249+
# (1) If `savedir` is not defined, then must have a non-zero `suffix`
250+
if args.savedir is None and len(args.output_name) > 0:
251+
suffix = args.output_name
252+
elif args.savedir is not None and not os.path.samefile(args.savedir, args.dir):
253+
# (2) If `savedir` is defined, and different from `dir` then
254+
# takes the value passed as a param. (which can be empty string)
255+
suffix = args.output_name
256+
257+
io.save_masks(image, masks, flows, image_name,
245258
suffix=suffix, png=args.save_png,
246259
tif=args.save_tif, save_flows=args.save_flows,
247260
save_outlines=args.save_outlines,

cellpose/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ def get_arg_parser():
142142
output_args = parser.add_argument_group("Output Arguments")
143143
output_args.add_argument(
144144
"--save_png", action="store_true",
145-
help="save masks as png and outlines as text file for ImageJ")
145+
help="save masks as png")
146146
output_args.add_argument(
147147
"--save_tif", action="store_true",
148-
help="save masks as tif and outlines as text file for ImageJ")
148+
help="save masks as tif")
149149
output_args.add_argument(
150-
"--output_name", default=[], type=str,
151-
help="suffix for saved masks, default is _cp_masks")
150+
"--output_name", default=None, type=str,
151+
help="suffix for saved masks, default is _cp_masks, can be empty if `savedir` used and different of `dir`")
152152
output_args.add_argument("--no_npy", action="store_true",
153153
help="suppress saving of npy")
154154
output_args.add_argument(

0 commit comments

Comments
 (0)