Skip to content

Commit

Permalink
Better ignore tiff directories that aren't part of the pyramid.
Browse files Browse the repository at this point in the history
We had one test file with a "thumbnail" image that was tiled but at a
different resolution than expected.  This was mistakenly used as a level
of the image.
  • Loading branch information
manthey committed Aug 24, 2022
1 parent b536d4d commit 7a8ef96
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Bug Fixes
- Fix iterating tiles where the overlap larger than the tile size ([940](../../pull/940))
- Better ignore tiff directories that aren't part of the pyramid ([943](../../pull/943))

## 1.16.1

Expand Down
14 changes: 13 additions & 1 deletion sources/tiff/large_image_source_tiff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):

_maxAssociatedImageSize = 8192

def __init__(self, path, **kwargs):
def __init__(self, path, **kwargs): # noqa
"""
Initialize the tile class. See the base class for other available
parameters.
Expand Down Expand Up @@ -141,6 +141,18 @@ def __init__(self, path, **kwargs):
((td.imageHeight % td.tileHeight) and
not nearPowerOfTwo(td.imageHeight, highest.imageHeight))):
continue
# If a layer is a multiple of the tile size, the number of tiles
# should be a power of two rounded up from the primary.
if (not (td.imageWidth % td.tileWidth) and not (td.imageHeight % td.tileHeight)):
htw = highest.imageWidth // td.tileWidth
hth = highest.imageHeight // td.tileHeight
ttw = td.imageWidth // td.tileWidth
tth = td.imageHeight // td.tileHeight
while (htw > ttw and htw > 1) or (hth > tth and hth > 1):
htw = (htw + 1) // 2
hth = (hth + 1) // 2
if htw != ttw or hth != tth:
continue
directories[level] = td
if not len(directories) or (len(directories) < 2 and max(directories.keys()) + 1 > 4):
raise TileSourceError(
Expand Down
5 changes: 4 additions & 1 deletion test/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
'TC_NG_SFBay_US_Geo.tif': 'sha512:da2e66528f77a5e10af5de9e496074b77277c3da81dafc69790189510e5a7e18dba9e966329d36c979f1b547f0d36a82fbc4cfccc65ae9ef9e2747b5a9ee77b0', # noqa
# Geospatial tiff - cloud optimized
'TC_NG_SFBay_US_Geo_COG.tif': 'sha512:5e56cdb8fb1a02615698a153862c10d5292b1ad42836a6e8bce5627e93a387dc0d3c9b6cfbd539796500bc2d3e23eafd07550f8c214e9348880bbbc6b3b0ea0c', # noqa

# Tiff with extra overview that was originally misinterpreted as a layer
# Source: generated from a tifftools dump with the image descriptions and
# topmost layer removed.
'extraoverview.tiff': 'sha512:22793cc6285ad11fbb47927c3d546d35e531a73852b79a9248ba489b421792e3a55da61e00079372bcf72a7e11b12e1ee69d553620edf46ff8d86ad2a9da9fc5', # noqa
}


Expand Down
9 changes: 4 additions & 5 deletions test/test_source_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
'openjpeg': {'read': r'\.(jp2)$'},
'openslide': {
'read': r'\.(ptif|svs|tif.*)$',
'noread': r'(oahu|DDX58_AXL|huron\.image2_jpeg2k|landcover_sample|d042-353\.crop|US_Geo\.)',
'noread': r'(oahu|DDX58_AXL|huron\.image2_jpeg2k|landcover_sample|d042-353\.crop|US_Geo\.|extraoverview)', # noqa
'skipTiles': r'one_layer_missing'},
'pil': {
'read': r'\.(jpeg|png|tif.*)$',
'noread': r'(G10-3|JK-kidney|d042-353|huron|one_layer_missing|US_Geo)'},
'noread': r'(G10-3|JK-kidney|d042-353|huron|one_layer_missing|US_Geo|extraoverview)'},
'test': {'any': True, 'skipTiles': r''},
'tiff': {
'read': r'\.(ptif|scn|svs|tif.*)$',
Expand All @@ -57,7 +57,7 @@
'vips': {
'read': r'',
'noread': r'\.(nc|nd2|yml|yaml|json|czi|png|svs|scn)$',
'skipTiles': r'(sample_image\.ptif|one_layer_missing_tiles|JK-kidney_B-gal_H3_4C_1-500sec\.jp2)'}, # noqa
'skipTiles': r'(sample_image\.ptif|one_layer_missing_tiles|JK-kidney_B-gal_H3_4C_1-500sec\.jp2|extraoverview)'}, # noqa
}
if sys.version_info >= (3, 7):
SourceAndFiles.update({
Expand All @@ -70,8 +70,7 @@
else:
# Python 3.6 has an older version of PIL that won't read some of the
# ome.tif files.
SourceAndFiles['pil']['noread'] = \
r'(G10-3|JK-kidney|d042-353|huron|sample.*ome|one_layer_missing|US_Geo)'
SourceAndFiles['pil']['noread'] = SourceAndFiles['pil']['noread'][:-1] + '|sample.*ome)'


def testNearPowerOfTwo():
Expand Down
6 changes: 6 additions & 0 deletions test/test_source_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,3 +868,9 @@ def testTileFrames():
info = tifftools.read_tiff(image)
assert len(info['ifds']) == 3
os.unlink(image)


def testExtraOverview():
imagePath = datastore.fetch('extraoverview.tiff')
source = large_image_source_tiff.open(imagePath)
assert len([d for d in source._tiffDirectories if d is not None]) == 3

0 comments on commit 7a8ef96

Please sign in to comment.