holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.7k stars 402 forks source link

Add support for alpha channels to Image and HSV Elements #833

Open jbednar opened 8 years ago

jbednar commented 8 years ago

Right now, the RGB Element supports an optional Alpha channel, but other Raster types do not. It would be very handy to be able to control the alpha (opacity) from a data source, and it seems straightforward to add this functionality.

@philippjfr suggests that we should first unify the GridImage and Image classes (with RGB and HSV subclasses), which are currently separate for historical reasons (GridImage being added to support the new multidimensional gridded data interfaces). There is no semantic reason why these should be separate objects, and the extra work required to add support for alpha channels to both versions can be avoided if the two are merged into a single class with different data backends.

philippjfr commented 8 years ago

The main problem is that if we implement it for Image now, then we have to go through the additional effort of making that code compatible with GridImage later. I could technically already support it for GridImage though, would look like this:

hv.GridImage({'x': x_coords, 'y': y_coords, 'z': val_array, 'alpha': alpha_array}, vdims=['z', 'alpha'])

The other question I have is whether you can imagine any alternative interpretation for an Image with two channels?

philippjfr commented 8 years ago

Another issue is that I'm not sure the plotting calls for matplotlib and bokeh support an additional alpha channel on images, which means I might have to implement colormapping to RGBA myself. If this is the case it may be better to implement this as an operation, which converts an overlay of images to RGBA.

jbednar commented 8 years ago

Well, an HSV+A image would have four channels if you count alpha, so there are definitely cases needing alpha that have more than two channels. But no, I don't know of any two-channel images that make sense as anything but array-to-colormap + array-for-alpha-channel.

Bokeh has image_rgba, but I don't know whether the non-_rgba version supports alpha.