Add function to get scale/units from vanilla tiff tags#63
Add function to get scale/units from vanilla tiff tags#63psobolewskiPhD wants to merge 2 commits intonapari:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #63 +/- ##
==========================================
+ Coverage 81.87% 83.18% +1.31%
==========================================
Files 8 8
Lines 513 553 +40
==========================================
+ Hits 420 460 +40
Misses 93 93 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks @psobolewskiPhD, I think this would be worth adding a test for. From past experience |
|
As I noted in the OP, I'm not opposed to tests, I just don't have a reasonable test file. |
|
Added a set of simple tests that write tiffs with defined tiff tags for X,YResolution and ResolutionUnit and then check that we get the expected napari scale and units. |
| # XResolution = 100 | ||
| # YResolution = 200 | ||
| "resolution_unit, expected_units, expected_scale", | ||
| [ | ||
| (1, ("pixel", "pixel"), (1 / 200, 1 / 100)), | ||
| # ResolutionUnit 2 = inches | ||
| (2, ("µm", "µm"), (25400 / 200, 25400 / 100)), | ||
| # ResolutionUnit 3 = cm | ||
| (3, ("µm", "µm"), (10000 / 200, 10000 / 100)), |
There was a problem hiding this comment.
this is clear enough to me, and since not many people are reading the tests I think its ok. Just probably not clear to most people why 25400 might be used or something, but TBH I think its good enough
There was a problem hiding this comment.
do you want me to spell it out more, that X,YResolution are in pixels per Unit (inch or cm) and we need microns per pixel?
This PR uses
tifffileAPI to get the x, y resolution (and the resolution unit) and convert to micron per pixel.Tifffile is reading the tiff tags for this.
This was motivated by NDPI whole slide images (WSI), is based on looking at:
https://openslide.org/formats/hamamatsu/
https://www.loc.gov/preservation/digital/formats/content/tiff_tags.shtml
and tifffile API.
It should work for any tiff that uses tiff tags according to spec.
Added a set of simple tests that write tiffs with defined tiff tags for X,YResolution and ResolutionUnit and then check that we get the expected napari scale and units.
Edit: in practice, for ndpi, this PR benefits from #45