@@ -170,7 +170,7 @@ def _initialize_images(parent, image, load_3D=False):
170170 load_3D = parent .load_3D if load_3D is False else load_3D
171171
172172 parent .stack = image
173- print (f"GUI_INFO : image shape: { image .shape } " )
173+ parent . logger . info (f" : image shape: { image .shape } " )
174174 if load_3D :
175175 parent .NZ = len (parent .stack )
176176 parent .scroll .setMaximum (parent .NZ - 1 )
@@ -187,7 +187,7 @@ def _initialize_images(parent, image, load_3D=False):
187187 parent .stack *= 255
188188
189189 if load_3D :
190- print ( "GUI_INFO : converted to float and normalized values to 0.0->255.0" )
190+ parent . logger . info ( " : converted to float and normalized values to 0.0->255.0" )
191191
192192 del image
193193 gc .collect ()
@@ -205,13 +205,15 @@ def _initialize_images(parent, image, load_3D=False):
205205 parent .Lyr , parent .Lxr = parent .Ly , parent .Lx
206206 parent .clear_all ()
207207
208+ if not hasattr (parent , "stack_filtered" ) and parent .restore :
209+ parent .logger .info (": no 'img_restore' found, applying current settings" )
210+ parent .compute_restore ()
211+
208212 if parent .autobtn .isChecked ():
209213 if parent .restore is None or parent .restore != "filter" :
210- print (
211- "GUI_INFO: normalization checked: computing saturation levels (and optionally filtered image)"
212- )
214+ parent .logger .info (": normalization checked: computing saturation levels (and optionally filtered image)" )
213215 parent .compute_saturation ()
214-
216+
215217 parent .compute_scale ()
216218 parent .track_changes = []
217219
@@ -312,7 +314,7 @@ def _load_seg(parent, filename=None, image=None, image_file=None, load_3D=False)
312314
313315 if "manual_changes" in dat :
314316 parent .track_changes = dat ["manual_changes" ]
315- print ( "GUI_INFO: loaded in previous changes" )
317+ parent . logger . info ( " loaded in previous changes" )
316318 if "zdraw" in dat :
317319 parent .zdraw = dat ["zdraw" ]
318320 else :
@@ -398,7 +400,7 @@ def _masks_to_gui(parent, masks, outlines=None, colors=None):
398400 # get unique values
399401 shape = masks .shape
400402 if len (fastremap .unique (masks )) != masks .max () + 1 :
401- print ( "GUI_INFO: renumbering masks" )
403+ parent . logger . info ( " renumbering masks" )
402404 fastremap .renumber (masks , in_place = True )
403405 outlines = None
404406 masks = masks .reshape (shape )
@@ -423,7 +425,7 @@ def _masks_to_gui(parent, masks, outlines=None, colors=None):
423425 if parent .cellpix_orig .ndim == 2 :
424426 parent .cellpix_orig = parent .cellpix_orig [np .newaxis , :, :]
425427
426- print (f"GUI_INFO: { masks .max ()} masks found" )
428+ parent . logger . info (f"{ masks .max ()} masks found" )
427429
428430 # get outlines
429431 if outlines is None : # parent.outlinesOn
@@ -437,7 +439,7 @@ def _masks_to_gui(parent, masks, outlines=None, colors=None):
437439 outlines = masks_to_outlines (parent .cellpix_orig [z ])
438440 parent .outpix_orig [z ] = outlines * parent .cellpix_orig [z ]
439441 if z % 50 == 0 and parent .NZ > 1 :
440- print ( "GUI_INFO: plane %d outlines processed" % z )
442+ parent . logger . info ( " plane %d outlines processed" % z )
441443 if parent .restore and "upsample" in parent .restore :
442444 parent .outpix_resize = parent .outpix .copy ()
443445 else :
@@ -449,7 +451,7 @@ def _masks_to_gui(parent, masks, outlines=None, colors=None):
449451 outlines = masks_to_outlines (parent .cellpix_orig [z ])
450452 parent .outpix_orig [z ] = outlines * parent .cellpix_orig [z ]
451453 if z % 50 == 0 and parent .NZ > 1 :
452- print ( "GUI_INFO: plane %d outlines processed" % z )
454+ parent . logger . info ( " plane %d outlines processed" % z )
453455
454456 if parent .outpix .ndim == 2 :
455457 parent .outpix = parent .outpix [np .newaxis , :, :]
@@ -461,7 +463,7 @@ def _masks_to_gui(parent, masks, outlines=None, colors=None):
461463
462464 parent .ncells .set (parent .cellpix .max ())
463465 colors = parent .colormap [:parent .ncells .get (), :3 ] if colors is None else colors
464- print ( "GUI_INFO: creating cellcolors and drawing masks" )
466+ parent . logger . info ( " creating cellcolors and drawing masks" )
465467 parent .cellcolors = np .concatenate ((np .array ([[255 , 255 , 255 ]]), colors ),
466468 axis = 0 ).astype (np .uint8 )
467469 if parent .ncells > 0 :
@@ -483,28 +485,28 @@ def _save_png(parent):
483485 base = os .path .splitext (filename )[0 ]
484486 if parent .NZ == 1 :
485487 if parent .cellpix [0 ].max () > 65534 :
486- print ( "GUI_INFO: saving 2D masks to tif (too many masks for PNG)" )
488+ parent . logger . info ( " saving 2D masks to tif (too many masks for PNG)" )
487489 imsave (base + "_cp_masks.tif" , parent .cellpix [0 ])
488490 else :
489- print ( "GUI_INFO: saving 2D masks to png" )
491+ parent . logger . info ( " saving 2D masks to png" )
490492 imsave (base + "_cp_masks.png" , parent .cellpix [0 ].astype (np .uint16 ))
491493 else :
492- print ( "GUI_INFO: saving 3D masks to tiff" )
494+ parent . logger . info ( " saving 3D masks to tiff" )
493495 imsave (base + "_cp_masks.tif" , parent .cellpix )
494496
495497
496498def _save_flows (parent ):
497499 """ save flows and cellprob to tiff """
498500 filename = parent .filename
499501 base = os .path .splitext (filename )[0 ]
500- print ( "GUI_INFO: saving flows and cellprob to tiff" )
502+ parent . logger . info ( " saving flows and cellprob to tiff" )
501503 if len (parent .flows ) > 0 :
502504 imsave (base + "_cp_cellprob.tif" , parent .flows [1 ])
503505 for i in range (3 ):
504506 imsave (base + f"_cp_flows_{ i } .tif" , parent .flows [0 ][..., i ])
505507 if len (parent .flows ) > 2 :
506508 imsave (base + "_cp_flows.tif" , parent .flows [2 ])
507- print ( "GUI_INFO: saved flows and cellprob" )
509+ parent . logger . info ( " saved flows and cellprob" )
508510 else :
509511 print ("ERROR: no flows or cellprob found" )
510512
@@ -620,7 +622,7 @@ def _save_sets(parent):
620622 dat ["img_restore" ] = parent .stack_filtered
621623 try :
622624 np .save (base + "_seg.npy" , dat )
623- print ( "GUI_INFO: %d ROIs saved to %s" % (parent .ncells .get (), base + "_seg.npy" ))
625+ parent . logger . info ( " %d ROIs saved to %s" % (parent .ncells .get (), base + "_seg.npy" ))
624626 except Exception as e :
625627 print (f"ERROR: { e } " )
626628 del dat
0 commit comments