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

Images with alpha channel being plotted incorrectly #406

Open
ivirshup opened this issue Jan 16, 2025 · 1 comment
Open

Images with alpha channel being plotted incorrectly #406

ivirshup opened this issue Jan 16, 2025 · 1 comment
Labels
bug Something isn't working images 🖼️ Anything related to Images priority: medium

Comments

@ivirshup
Copy link
Member

Hey! I've come across an issue when trying to plot some images where one of the channels is an alpha level. This is a visium image that was submitted to cellxgene.

sdata.pl.render_images().pl.show("d551b400-b2e5-454d-b5a9-ece03e6b4739")

Image

As you can see, this looks quite funny. I don't think it's an issue with the image, since plotting it through other routes appears normal:

Plotting with matplotlib

import matplotlib.pyplot as plt
img = sdata.images["d551b400-b2e5-454d-b5a9-ece03e6b4739_library"].compute()
plt.imshow(img.transpose("y", "x", "c"))

Image

Plotting with squidpy

from spatialdata_io.experimental import from_legacy_anndata, to_legacy_anndata
import squidpy as sq

adata = to_legacy_anndata(sdata, include_images=True)
sq.pl.spatial_scatter(adata)

Image

It seems to me like the alpha level is being misinterpreted in spatialdata_plot.

@LucaMarconato
Copy link
Member

Thanks for reporting. This is how rgba is dealt with in napari-spatialdata, the issue may be related: https://github.com/scverse/napari-spatialdata/pull/153/files; following the napari-spatialdata approach, the desired implementation may be the following:

  • if r, g, b (a) are the channel names of the image, then interpret it as RGB(A)
  • (optional) if not, let the user pass an explicit parameter to pl.render_images(), such as rgb=True (default false)

In napari-spatialdata, this approach replaced the previous method, which was based on a heuristic (checking if the channels were 3 or 4 and interpreting the image as RGB(A)).

@timtreis @Sonja-Stockhaus wdyt?

@timtreis timtreis added bug Something isn't working priority: medium images 🖼️ Anything related to Images labels Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working images 🖼️ Anything related to Images priority: medium
Projects
None yet
Development

No branches or pull requests

3 participants