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

Band order could matter in styles #1284

Merged
merged 1 commit into from
Aug 31, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

### Bug Fixes
- Closing some styled sources could lead to prematurely closing file handles ([#1283](../../pull/1283))
- Band order could matter in styles ([#1284](../../pull/1284))

## 1.23.5

Expand Down
2 changes: 1 addition & 1 deletion large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ def _applyStyle(self, image, style, x, y, z, frame=None): # noqa
sc.bandidx = 0 if image.shape[2] <= 2 else 1
sc.band = None
if ((entry.get('frame') is None and not entry.get('framedelta')) or
entry.get('frame') == frame):
entry.get('frame') == sc.mainFrame):
image = sc.mainImage
frame = sc.mainFrame
else:
Expand Down
42 changes: 42 additions & 0 deletions test/test_source_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,3 +764,45 @@ def testStyleFunctionsWarnings():
output=dict(maxWidth=50),
format=large_image.constants.TILE_FORMAT_NUMPY)
assert source._styleFunctionWarnings


@pytest.mark.skipif(sys.version_info < (3, 7), reason='requires python >= 3.7 for the source')
@pytest.mark.singular()
def testStyleRepeatedFrame():
imagePath = datastore.fetch('ITGA3Hi_export_crop2.nd2')
ts1 = large_image.open(imagePath, style={'bands': [
{'frame': 0, 'min': 'min', 'max': 'max', 'palette': 'R'},
{'frame': 0, 'min': 'min', 'max': 'max', 'palette': 'G'},
{'frame': 1, 'min': 'min', 'max': 'max', 'palette': 'B'},
]})
ts2 = large_image.open(imagePath, style={'bands': [
{'frame': 0, 'min': 'min', 'max': 'max', 'palette': 'G'},
{'frame': 1, 'min': 'min', 'max': 'max', 'palette': 'B'},
{'frame': 0, 'min': 'min', 'max': 'max', 'palette': 'R'},
]})
ts3 = large_image.open(imagePath, style={'bands': [
{'frame': 1, 'min': 'min', 'max': 'max', 'palette': 'B'},
{'frame': 0, 'min': 'min', 'max': 'max', 'palette': 'R'},
{'frame': 0, 'min': 'min', 'max': 'max', 'palette': 'G'},
]})
ts4 = large_image.open(imagePath, style={'bands': [
{'frame': 0, 'min': 'min', 'max': 'max', 'palette': 'R'},
{'frame': 1, 'min': 'min', 'max': 'max', 'palette': 'B'},
{'frame': 0, 'min': 'min', 'max': 'max', 'palette': 'G'},
]})
ts5 = large_image.open(imagePath, style={'bands': [
{'frame': 0, 'min': 'min', 'max': 'max', 'palette': 'G'},
{'frame': 0, 'min': 'min', 'max': 'max', 'palette': 'R'},
{'frame': 1, 'min': 'min', 'max': 'max', 'palette': 'B'},
]})
ts6 = large_image.open(imagePath, style={'bands': [
{'frame': 1, 'min': 'min', 'max': 'max', 'palette': 'B'},
{'frame': 0, 'min': 'min', 'max': 'max', 'palette': 'G'},
{'frame': 0, 'min': 'min', 'max': 'max', 'palette': 'R'},
]})
tile1 = ts1.getTile(0, 0, 0)
assert ts2.getTile(0, 0, 0) == tile1
assert ts3.getTile(0, 0, 0) == tile1
assert ts4.getTile(0, 0, 0) == tile1
assert ts5.getTile(0, 0, 0) == tile1
assert ts6.getTile(0, 0, 0) == tile1