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

Support a simple style for icc: true #1048

Merged
merged 1 commit into from
Feb 2, 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 1.20.0

### Features
- ICC color profile support ([#1037](../../pull/1037), [#1043](../../pull/1043), [#1046](../../pull/1046))
- ICC color profile support ([#1037](../../pull/1037), [#1043](../../pull/1043), [#1046](../../pull/1046), [#1048](../../pull/1048))

### Improvements
- Speed up generating tiles for some multi source files ([#1035](../../pull/1035), [#1047](../../pull/1047))
Expand Down
2 changes: 1 addition & 1 deletion docs/tilesource_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ A band definition is an object which can contain the following keys:

- ``axis``: if specified, keep on the specified axis (channel) of the intermediate numpy array. This is typically between 0 and 3 for the red, green, blue, and alpha channels. Only the first such value is used, and this can be specified as a base key if ``bands`` is specified.

- ``icc``: by default, sources that expose ICC color profiles will apply those profiles to the image data, converting the results to the sRGB profile. To use the raw image data without ICC profile adjustments, specify an ``icc`` value of ``false``. If the entire style is ``{"icc": false}``, the results will be the same as the default bands with only the adjustment being skipped. Note that not all tile sources expose ICC color profile information, even if the base file format contains it.
- ``icc``: by default, sources that expose ICC color profiles will apply those profiles to the image data, converting the results to the sRGB profile. To use the raw image data without ICC profile adjustments, specify an ``icc`` value of ``false``. If the entire style is ``{"icc": false}``, the results will be the same as the default bands with only the adjustment being skipped. Similarly, if the entire style is ``{"icc": true}``, this is the same as the default style with where the adjustment is applied. Note that not all tile sources expose ICC color profile information, even if the base file format contains it.

- ``function``: if specified, call a function to modify the resulting image. This can be specified as a base key and as a band key. Style functions can be called at multiple stages in the styling pipeline:

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 @@ -1280,7 +1280,7 @@ def _applyStyle(self, image, style, x, y, z, frame=None): # noqa
sc = types.SimpleNamespace(
image=image, originalStyle=style, x=x, y=y, z=z, frame=frame,
mainImage=image, mainFrame=frame, dtype=None, axis=None)
if style is None:
if style is None or style == {'icc': True}:
sc.style = {'bands': []}
else:
sc.style = style if 'bands' in style else {'bands': [style]}
Expand Down
12 changes: 12 additions & 0 deletions test/test_source_openslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,18 @@ def testGetPixel():
assert 'tile' in pixel


def testGetPixelWithICCCorrection():
imagePath = datastore.fetch(
'sample_jp2k_33003_TCGA-CV-7242-11A-01-TS1.1838afb1-9eee-'
'4a70-9ae3-50e3ab45e242.svs')
source = large_image_source_openslide.open(imagePath)
pixel = source.getPixel(region={'left': 12125, 'top': 10640})
assert pixel == {'r': 169, 'g': 99, 'b': 151, 'a': 255}
source = large_image_source_openslide.open(imagePath, style={'icc': True})
pixel2 = source.getPixel(region={'left': 12125, 'top': 10640})
assert pixel == pixel2


def testTilesFromPowerOf3Tiles():
imagePath = datastore.fetch('G10-3_pelvis_crop-powers-of-3.tif')
source = large_image_source_openslide.open(imagePath)
Expand Down