From e51768e4568aa03eaf4a8eef47a9a151c8e2586e Mon Sep 17 00:00:00 2001 From: David Manthey Date: Thu, 16 Feb 2023 15:58:25 -0500 Subject: [PATCH] Ignore bogus tifffile resolutions. --- CHANGELOG.md | 1 + .../large_image_source_tifffile/__init__.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4ebc3f33..1ef38218d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/sources/tifffile/large_image_source_tifffile/__init__.py b/sources/tifffile/large_image_source_tifffile/__init__.py index f97f30048..c4cc769c1 100644 --- a/sources/tifffile/large_image_source_tifffile/__init__.py +++ b/sources/tifffile/large_image_source_tifffile/__init__.py @@ -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))