1111from pathlib import Path
1212
1313import numpy as np
14- from PIL import Image
14+ import tifffile
1515from rich .logging import RichHandler
1616
1717from fancylog .tools .git import (
@@ -591,22 +591,15 @@ def log_image(
591591 image_dir = output_dir / subfolder
592592 image_dir .mkdir (parents = True , exist_ok = True )
593593
594- if image .dtype != np .uint8 :
595- image = ((image - image .min ()) / (np .ptp (image ) + 1e-5 ) * 255 ).astype (
596- np .uint8
597- )
598-
599594 filepath = image_dir / f"{ name } .tiff"
600- Image . fromarray ( image ). save ( filepath , format = "TIFF" )
595+ tifffile . imwrite ( filepath , image )
601596
602597 if metadata :
603598 meta_path = image_dir / f"{ name } _meta.json"
604599 with open (meta_path , "w" ) as f :
605600 json .dump (metadata , f , indent = 2 )
606601
607- logging .getLogger (__name__ ).info (
608- f"[fancylog] Saved image: { filepath .relative_to (output_dir )} "
609- )
602+ logging .getLogger (__name__ ).info (f"[fancylog] Saved image: { filepath } " )
610603 return filepath
611604
612605
@@ -622,17 +615,17 @@ def log_data_object(
622615 data_dir = output_dir / subfolder
623616 data_dir .mkdir (parents = True , exist_ok = True )
624617
625- path = data_dir / f"{ name } .{ ext } "
618+ filepath = data_dir / f"{ name } .{ ext } "
626619
627620 if isinstance (data , (dict | list )):
628- with open (path , "w" ) as f :
621+ with open (filepath , "w" ) as f :
629622 json .dump (data , f , indent = 2 )
630623 elif isinstance (data , np .ndarray ):
631- np .save (path , data )
624+ np .save (filepath , data )
632625 else :
633626 raise ValueError ("Unsupported data type for logging" )
634627
635628 logging .getLogger (__name__ ).info (
636- f"[fancylog] Saved data object: { path . relative_to ( output_dir ) } "
629+ f"[fancylog] Saved data object: { filepath } "
637630 )
638- return path
631+ return filepath
0 commit comments