Skip to content
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

Tile overlaps on subset regions. #781

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
## Version 1.11.0

### Improvements
- Release memory associated with a lazy tile if it has been loaded
- Release memory associated with a lazy tile if it has been loaded ([#780](../../pull/780))

### Bug Fixes
- Tile overlaps on subset regions could be wrong ([#781](../../pull/781))

## Version 1.11.0

Expand Down
14 changes: 10 additions & 4 deletions large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,12 +732,18 @@ def _tileIterator(self, iterInfo):
'left': max(0, x * tileSize['width'] + tileOverlap['offset_x'] - left - posX),
'top': max(0, y * tileSize['height'] + tileOverlap['offset_y'] - top - posY),
}
overlap['right'] = max(0, tileWidth - tileSize['width'] - overlap['left'])
overlap['bottom'] = max(0, tileHeight - tileSize['height'] - overlap['top'])
if tileOverlap['offset_x']:
overlap['right'] = (
max(0, tileWidth - tileSize['width'] - overlap['left'])
if x != xmin or not tileOverlap['range_x'] else
min(tileWidth, tileOverlap['range_x'] - tileOverlap['offset_x']))
overlap['bottom'] = (
max(0, tileHeight - tileSize['height'] - overlap['top'])
if y != ymin or not tileOverlap['range_y'] else
min(tileHeight, tileOverlap['range_y'] - tileOverlap['offset_y']))
if tileOverlap['range_x']:
overlap['left'] = 0 if x == tileOverlap['xmin'] else overlap['left']
overlap['right'] = 0 if x + 1 == tileOverlap['xmax'] else overlap['right']
if tileOverlap['offset_y']:
if tileOverlap['range_y']:
overlap['top'] = 0 if y == tileOverlap['ymin'] else overlap['top']
overlap['bottom'] = 0 if y + 1 == tileOverlap['ymax'] else overlap['bottom']
tile = LazyTileDict({
Expand Down
11 changes: 11 additions & 0 deletions test/test_source_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,14 @@ def testLazyTileRelease():
assert super(large_image.tilesource.tiledict.LazyTileDict, tiles[5]).__getitem__(
'tile') is None
assert tiles[5]['tile'] == data


def testTileOverlapWithRegionOffset():
imagePath = datastore.fetch('sample_image.ptif')
ts = large_image.open(imagePath)
tileIter = ts.tileIterator(
region=dict(left=10000, top=10000, width=6000, height=6000),
tile_size=dict(width=1936, height=1936),
tile_overlap=dict(x=400, y=400))
firstTile = next(tileIter)
assert firstTile['tile_overlap']['right'] == 200