Skip to content

Commit

Permalink
Merge branch 'antoinemeyer5-feat/output-naming'
Browse files Browse the repository at this point in the history
  • Loading branch information
carsen-stringer committed Feb 11, 2025
2 parents d557093 + f6df6a2 commit 89ab381
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
19 changes: 16 additions & 3 deletions cellpose/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main():
"""

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

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

if args.savedir:
if not os.path.exists(args.savedir):
raise FileExistsError("--savedir {args.savedir} does not exist")

cstr0 = ["GRAY", "RED", "GREEN", "BLUE"]
cstr1 = ["NONE", "RED", "GREEN", "BLUE"]
logger.info(
Expand Down Expand Up @@ -240,8 +244,17 @@ def main():
diams=diams, restore_type=restore_type,
ratio=1.)
if saving_something:
suffix = args.output_name if len(args.output_name) > 0 else "_cp_masks"
io.save_masks(image, masks, flows, image_name,
suffix = "_cp_masks"
if args.output_name is not None:
# (1) If `savedir` is not defined, then must have a non-zero `suffix`
if args.savedir is None and len(args.output_name) > 0:
suffix = args.output_name
elif args.savedir is not None and not os.path.samefile(args.savedir, args.dir):
# (2) If `savedir` is defined, and different from `dir` then
# takes the value passed as a param. (which can be empty string)
suffix = args.output_name

io.save_masks(image, masks, flows, image_name,
suffix=suffix, png=args.save_png,
tif=args.save_tif, save_flows=args.save_flows,
save_outlines=args.save_outlines,
Expand Down
8 changes: 4 additions & 4 deletions cellpose/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ def get_arg_parser():
output_args = parser.add_argument_group("Output Arguments")
output_args.add_argument(
"--save_png", action="store_true",
help="save masks as png and outlines as text file for ImageJ")
help="save masks as png")
output_args.add_argument(
"--save_tif", action="store_true",
help="save masks as tif and outlines as text file for ImageJ")
help="save masks as tif")
output_args.add_argument(
"--output_name", default=[], type=str,
help="suffix for saved masks, default is _cp_masks")
"--output_name", default=None, type=str,
help="suffix for saved masks, default is _cp_masks, can be empty if `savedir` used and different of `dir`")
output_args.add_argument("--no_npy", action="store_true",
help="suppress saving of npy")
output_args.add_argument(
Expand Down

0 comments on commit 89ab381

Please sign in to comment.