[Python] Plotly Image ignores alpha channel

Discussão em 'Python' iniciado por Stack, Setembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I'm attempting to display a (semi) transparent image using plotly's go.Image object. I use cv2 to load the image from disk and convert it to rgba format. Following this issue, I manually set colormodel='rgba' but the resulting image still ignores the alpha value.

    Example code:

    import cv2
    import plotly.graph_objects as go

    original = cv2.imread(<path_to_image>)
    original = cv2.cvtColor(original, cv2.COLOR_BGR2RGB)

    transparent = cv2.cvtColor(original , cv2.COLOR_RGB2RGBA)
    transparent[:, :, 3] = 127 # set to 255 // 2 for half-transparency

    fig1 = go.Figure(go.Image(z=original))
    fig1.show()

    fig2 = go.Figure(go.Image(z=img2, colormodel='rgba'))
    fig2.show()


    Both fig1 and fig2 present the same image, but fig2 displays 4-channel pixels: [​IMG]

    Seems like plotly cannot display transparent images. Is there a way to display the image with the alpha channel?

    Continue reading...

Compartilhe esta Página