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

Non-transparent outside bounds with getTile for tifs without style #1186

Open
banesullivan opened this issue May 30, 2023 · 7 comments
Open

Comments

@banesullivan
Copy link
Contributor

banesullivan commented May 30, 2023

I noticed that TIF files with the TiffFileTileSource and OMETiffFileTileSource sources (at least), if the image is opened without a style, the areas outside the bounds of the image for getTile() are black/opaque but the encoding is PNG and these areas should be transparent

import large_image

path = 'test/test_files/test_orient0.tif'
source = large_image.open(
    path,
    encoding="PNG",
)
>>> img_bytes = source.getTile(0, 0, 0)
>>> img_bytes.mimetype
'image/png'
>>> img_bytes
<PNG below>

download

Or with an OME file:

path = 'HTA9_1_BA_F_ROI02.ome.tif'
source = large_image.open(
    path,
    encoding="PNG",
)
source.getTile(0, 0, 0)

download

However, with the OME source, if I open with a style, the region becomes transparent:

source = large_image.open(
    path,
    encoding="PNG",
    style = {"bands": [
      {"band": 1, "palette": ["#000", "#fff"]},
    ]}
)
source.getTile(0, 0, 0)

download

@banesullivan
Copy link
Contributor Author

Nevermind. Adding a style does not solve it:

source.getTile(1, 1, 1)

download

@banesullivan
Copy link
Contributor Author

Why is this an issue? It has significant impacts when using the new viewer in #1065:

Screen.Recording.2023-05-30.at.1.22.33.PM.mov

@manthey
Copy link
Member

manthey commented May 30, 2023

Does adding edge=#0000 (or any other transparent color) work?

Some viewers automatically crop to the maximum extent of the tiles; other viewers expect short tiles at the right and bottom edges (add edge=crop as a parameter). The edge color should only affect viewers that neither crop nor expect short tiles.

@banesullivan
Copy link
Contributor Author

Setting an edge color changes it, but I still cannot get it to be transparent

Unfortunately, it looks like the ipyleaflet viewer cannot handle edge="crop"

edge="#00FFFFFF" and .getTile(1, 1, 1):

download

@manthey
Copy link
Member

manthey commented May 31, 2023

Do you mean edge=#FFFFFF00 (since the fourth octet is alpha)?

@banesullivan
Copy link
Contributor Author

Yes I did mean that but still the problem I mentioned about not getting any transparency: Same tile with #FFFFFF00 (note white, not transparent border)

download

@banesullivan
Copy link
Contributor Author

Turns out the issue is specific to greyscale images loaded without a style. If the images is greyscale, then the edge color remapped to the grayscale space. You have to apply a style to get out of the greyscale space:

import large_image

path = 'HTA9_1_BA_F_ROI02.ome.tif'

source = large_image.open(
    path,
    encoding="PNG",
    edge="#0F02",
)
source.getTile(1, 1, 1)

download

source = large_image.open(
    path,
    encoding="PNG",
    edge="#0F02",
    style = {"bands": [
      {"band": 1, "palette": ["#000", "#fff"]}
    ]}
)
source.getTile(1, 1, 1)

download

This is not a high priority

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants