@@ -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 ,
0 commit comments