RGBA image not displaying

Below code is showing only blank (white) page. Not even the grids are showing.
Am I doing anything wrong?

It works when I convert to grayscale with .convert('L') and figure.image(...).
Different images from other datasets also produce same results.

sample_img = np.asarray(Image.open('bbbc021/Week1_22141_wB02_s03_rgb.png').convert('RGBA'))

tools_sel = ['pan, box_zoom, wheel_zoom, reset']
p = figure( title='Selected images',
            x_range=[0, 1],
            y_range=[0, 1],

p.image_rgba(image=[image], x=0, y=0, dw=1, dh=1)

Probably the shape and/or dtype of the array is incompatible with ImageRGBA. You may have to .reshape((N, M, 4)) and set dtype="uint8". There should be errors in JS console giving at least some indication what’s happening. Note also that currently inputs to .image_rgba() are not validated in Python (per [BUG] `Figure.image` not working with "vanilla" Python data structures · Issue #12615 · bokeh/bokeh · GitHub), so bokeh will happily accept arrays in any shape and type regardless if it works in bokehjs or not.

With @mateusz 's answer, I was able to fix my problem:

from skimage import io

# Used float64, so there is no overflow when changing range
image = io.imread(path).astype('float64') 
# Fix range between [0,255] and convert to uint8
image = change_range(image)
image = image.astype('uint8')
# Convert to RGBA
image = gray2rgba(image) 
# image_rgba seems to accept only uint32 images
image = image.view("uint32").reshape(image.shape[:2])
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.