Skip to content

Commit

Permalink
Merge pull request #1062 from girder/tifffile-resolution
Browse files Browse the repository at this point in the history
Ignore bogus tifffile resolutions.
  • Loading branch information
manthey authored Feb 17, 2023
2 parents 1e92b45 + e51768e commit 6620f6c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Better pick the largest image from bioformats ([#1039](../../pull/1039), [#1040](../../pull/1040))
- Cache histogram thresholds ([#1042](../../pull/1042))
- Add `_repr_png_` for Jupyter ([#1058](../../pull/1058))
- Ignore bogus tifffile resolutions ([#1062](../../pull/1062))

## 1.19.3

Expand Down
13 changes: 8 additions & 5 deletions sources/tifffile/large_image_source_tifffile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,18 @@ def __init__(self, path, **kwargs):
self._iccprofiles = [page.tags['InterColorProfile'].value]
self.sizeX = s.shape[s.axes.index('X')]
self.sizeY = s.shape[s.axes.index('Y')]
self._mm_x = self._mm_y = None
try:
unit = {2: 25.4, 3: 10}[page.tags['ResolutionUnit'].value.real]

self._mm_x = (unit * page.tags['XResolution'].value[1] /
page.tags['XResolution'].value[0])
self._mm_y = (unit * page.tags['YResolution'].value[1] /
page.tags['YResolution'].value[0])
if page.tags['XResolution'].value[1] >= 100:
self._mm_x = (unit * page.tags['XResolution'].value[1] /
page.tags['XResolution'].value[0])
if page.tags['YResolution'].value[1] >= 100:
self._mm_y = (unit * page.tags['YResolution'].value[1] /
page.tags['YResolution'].value[0])
except Exception:
self._mm_x = self._mm_y = None
pass
self._findMatchingSeries()
self.levels = int(max(1, math.ceil(math.log(
float(max(self.sizeX, self.sizeY)) / self.tileWidth) / math.log(2)) + 1))
Expand Down

0 comments on commit 6620f6c

Please sign in to comment.