Problems in submission ¶
By: danifranco on Feb. 17, 2025, 6:32 p.m.
Hello,
I found an error in the in the inference.py
provided. Specifically in the read_image()
function. Seems that the metadata is not in tif.shaped_metadata
attribute (or at least not for all images). I'm trying locally with a example image (image_90_nucleus_angle.tif
) and seems that the image has the metadata inside the imagej_metadata
attribute. This is a loop over all the attributes I made trying to find where was the metadata:
--> Predict image_90_nucleus_angle.tif andor_metadata is None astrotiff_metadata is None avs_metadata is None eer_metadata is None epics_metadata is None fei_metadata is None fluoview_metadata is None gdal_metadata is None gdal_structural_metadata is None geotiff_metadata is None imagej_metadata: {'ImageJ': '1.11a', 'images': 204, 'slices': 204, 'hyperstack': True, 'mode': 'grayscale', 'spacing': 1.0, 'physicalsizex': 0.19500001, 'physical_size_x': 0.19500001, 'physicalsizey': 0.19500001, 'physical_size_y': 0.19500001, 'physicalsizez': 1.0, 'physical_size_z': 1.0, 'xresolution': 0.19500001, 'yresolution': 0.19500001, 'zresolution': 1.0, 'unit': 'um', 'study': 1, 'channel': 'nucleus'} indica_metadata is None lsm_metadata is None mdgel_metadata is None metaseries_metadata is None micromanager_metadata is None nih_metadata is None ome_metadata is None philips_metadata is None pilatus_metadata is None scanimage_metadata is None scn_metadata is None sem_metadata is None shaped_metadata is None sis_metadata is None stk_metadata is None streak_metadata is None tvips_metadata is None
The read_function can be changed as follows:
def read_image(location): # WARNING IMAGE DATA EN ZYX # Read the TIFF file and get the image and metadata with tifffile.TiffFile(location) as tif: image_data = tif.asarray() # Extract image data # metadata = tif.shaped_metadata # Get the existing metadata in a DICT metadata = None for x in dir(tif): if "metadata" in x: if getattr(tif,x) is not None and 'physicalsizex' in getattr(tif,x).keys(): metadata = getattr(tif,x) break if metadata is None: raise ValueError(f"Metadata not found in image {location}") return image_data, metadata
Also you need to change the following lines:
PhysicalSizeX = metadata['PhysicalSizeX'] PhysicalSizeY = metadata['PhysicalSizeY']
Into these:
PhysicalSizeX = metadata['physicalsizex'] PhysicalSizeY = metadata['physicalsizey']
Cause seems that the attribute names are in lowercase.
I don't know also how critical is the metadata in the process of saving the image, but so everyone is aware of this error. Maybe I did something wrong at some point and that's why this was happening (maybe the organizers can shed a bit of light on this). Anyway, this message is for all who are trying to create the submission so you don't waste the same time as me ;)
Cheers and good luck,
Dani