Skip to content

Images with alpha channel being plotted incorrectly #406

Closed

Description

@ivirshup

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.

Activity

  1. LucaMarconato commented on Jan 20, 2025

    @LucaMarconato
    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?

  2. added a commit that references this issue on Mar 27, 2026
    e1cb399
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions