-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add deepimagej config generation #151
Conversation
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
In the ZeroCostDL4Mic notebook for StarDist we directly ask the user for this value. By default the pixel size could be set to 1 pixel. In the rest of the notebooks, it's calculated using the following function: from PIL import Image
def getPixelSizeTIFFmetadata(TIFFpath, display=False):
with Image.open(TIFFpath) as img:
meta_dict = {TAGS[key] : img.tag[key] for key in img.tag.keys()}
# TIFF tags
# https://www.loc.gov/preservation/digital/formats/content/tiff_tags.shtml
# https://www.awaresystems.be/imaging/tiff/tifftags/resolutionunit.html
ResolutionUnit = meta_dict['ResolutionUnit'][0] # unit of resolution
width = meta_dict['ImageWidth'][0]
height = meta_dict['ImageLength'][0]
xResolution = meta_dict['XResolution'][0] # number of pixels / ResolutionUnit
if len(xResolution) == 1:
xResolution = xResolution[0]
elif len(xResolution) == 2:
xResolution = xResolution[0]/xResolution[1]
else:
print('Image resolution not defined.')
xResolution = 1
if ResolutionUnit == 2:
# Units given are in inches
pixel_size = 0.025*1e9/xResolution
elif ResolutionUnit == 3:
# Units given are in cm
pixel_size = 0.01*1e9/xResolution
else:
# ResolutionUnit is therefore 1
print('Resolution unit not defined. Assuming: um')
pixel_size = 1e3/xResolution
if display:
print('Pixel size obtained from metadata: '+str(pixel_size)+' nm')
print('Image size: '+str(width)+'x'+str(height))
return (pixel_size, width, height) |
Thanks for sharing the script @esgomezm, but I fear that this is not very useful for us because we can't rely on having tif files as inputs; the (mandatory) input data are numpy arrays here. |
incorporating pixel size into the spec (0.4.?) sounds like another hackathon item to me... |
Yes, def. a point to discuss |
Ok, I updated the deepimagej config function to include the pixel size and fix several issues.
Also, the tests are still failing due to some issues with sample inputs / outputs that I don't understand. But this may be fixed by #164, so we should merge that PR first and then merge main here. |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@FynnBe the tests for writing the deepimagej config is still failing with
although sample_inputs/outputs are treated exactly the same as test_inputs/outputs in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost there 👍
# (Pdb) model.test_inputs | ||
# [PosixPath('/tmp/bioimageio_cache/extracted_packages/efae734f36ff8634977c9174f01c854c4e2cfc799bc92751a4558a0edd963da6/test_input.npy')] | ||
# (Pdb) model.test_outputs | ||
# [PosixPath('/tmp/bioimageio_cache/extracted_packages/efae734f36ff8634977c9174f01c854c4e2cfc799bc92751a4558a0edd963da6/test_output.npy')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be fixed by #164 ; then this should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the tests for writing the deepimagej config is still failing with
... or not.. looking into it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem is that sample inputs/outputs are absolute and not relative paths...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but test inputs / outptus are also absolute paths. Why does it work for them and not for sample inputs/outputs?
1942df0 contains bugs! not ready yet... |
It's
It's in theory possible, but too complex for now; we will just throw an error for now and leave this for future iterations. |
locally for me there remains an issue with sample_inputs/outputs serialization. Not sure what's going on there... |
this turned out to be wrong... in the deepimagej they are treated differently... (this should be fixed now though |
needed to resolve relative paths
An update to bioimageio.spec should fix the remaining issue of serialization: bioimage-io/spec-bioimage-io#294 |
Thanks @FynnBe now it all works. |
Write the deepimagej config. Still need to get the pixel size information somehow.
cc @esgomezm