47
47
48
48
io_logger = logging .getLogger (__name__ )
49
49
50
-
51
- def logger_setup ():
52
- cp_dir = pathlib .Path .home ().joinpath (".cellpose" )
50
+ def logger_setup (cp_path = ".cellpose" , logfile_name = "run.log" ):
51
+ cp_dir = pathlib .Path .home ().joinpath (cp_path )
53
52
cp_dir .mkdir (exist_ok = True )
54
- log_file = cp_dir .joinpath ("run.log" )
53
+ log_file = cp_dir .joinpath (logfile_name )
55
54
try :
56
55
log_file .unlink ()
57
56
except :
@@ -70,8 +69,7 @@ def logger_setup():
70
69
71
70
from . import utils , plot , transforms
72
71
73
-
74
- # helper function to check for a path; if it doesn"t exist, make it
72
+ # helper function to check for a path; if it doesn't exist, make it
75
73
def check_dir (path ):
76
74
if not os .path .isdir (path ):
77
75
os .mkdir (path )
@@ -156,7 +154,7 @@ def imread(filename):
156
154
"""
157
155
# ensure that extension check is not case sensitive
158
156
ext = os .path .splitext (filename )[- 1 ].lower ()
159
- if ext == ".tif" or ext == ".tiff" :
157
+ if ext == ".tif" or ext == ".tiff" or ext == ".flex" :
160
158
with tifffile .TiffFile (filename ) as tif :
161
159
ltif = len (tif .pages )
162
160
try :
@@ -295,7 +293,7 @@ def get_image_files(folder, mask_filter, imf=None, look_one_level_down=False):
295
293
if look_one_level_down :
296
294
folders = natsorted (glob .glob (os .path .join (folder , "*/" )))
297
295
folders .append (folder )
298
- exts = [".png" , ".jpg" , ".jpeg" , ".tif" , ".tiff" , ".dax" , ".nd2" , ".nrrd" ]
296
+ exts = [".png" , ".jpg" , ".jpeg" , ".tif" , ".tiff" , ".flex" , ". dax" , ".nd2" , ".nrrd" ]
299
297
l0 = 0
300
298
al = 0
301
299
for folder in folders :
@@ -311,7 +309,7 @@ def get_image_files(folder, mask_filter, imf=None, look_one_level_down=False):
311
309
raise ValueError ("ERROR: no files in --dir folder " )
312
310
elif l0 == 0 :
313
311
raise ValueError (
314
- "ERROR: no images in --dir folder with extensions .png, .jpg, .jpeg, .tif, .tiff"
312
+ "ERROR: no images in --dir folder with extensions .png, .jpg, .jpeg, .tif, .tiff, .flex "
315
313
)
316
314
317
315
image_names = natsorted (image_names )
@@ -338,7 +336,6 @@ def get_image_files(folder, mask_filter, imf=None, look_one_level_down=False):
338
336
339
337
return image_names
340
338
341
-
342
339
def get_label_files (image_names , mask_filter , imf = None ):
343
340
"""
344
341
Get the label files corresponding to the given image names and mask filter.
@@ -440,7 +437,6 @@ def load_images_labels(tdir, mask_filter="_masks", image_filter=None,
440
437
io_logger .info (f"{ k } / { nimg } images in { tdir } folder have labels" )
441
438
return images , labels , image_names
442
439
443
-
444
440
def load_train_test_data (train_dir , test_dir = None , image_filter = None ,
445
441
mask_filter = "_masks" , look_one_level_down = False ):
446
442
"""
@@ -463,7 +459,6 @@ def load_train_test_data(train_dir, test_dir=None, image_filter=None,
463
459
"""
464
460
images , labels , image_names = load_images_labels (train_dir , mask_filter ,
465
461
image_filter , look_one_level_down )
466
-
467
462
# testing data
468
463
test_images , test_labels , test_image_names = None , None , None
469
464
if test_dir is not None :
@@ -568,12 +563,11 @@ def masks_flows_to_seg(images, masks, flows, file_names, diams=30., channels=Non
568
563
569
564
np .save (base + "_seg.npy" , dat )
570
565
571
-
572
566
def save_to_png (images , masks , flows , file_names ):
573
- """ deprecated (runs io.save_masks with png=True)
574
-
567
+ """ deprecated (runs io.save_masks with png=True)
568
+
575
569
does not work for 3D images
576
-
570
+
577
571
"""
578
572
save_masks (images , masks , flows , file_names , png = True )
579
573
0 commit comments