How to show 3D volume image

Hi, everyone. I am a totally newer to plotly. Now I am struggling on how to show 3D volume image with plotly (more specifically Dash). The data is a 3D volume with each pixel labelled with different class value (such as 0, 1, 2…). Here is a app similar to my target, however, it is time-consuming to covert a volume into a triangular surface. Therefore, I hope to draw 3D image from the volume data directly. Any suggestions are welcome. Thanks


Welcome @Jeff! We have two volume rendering trace types in plotly.js - isosurface and volume, which is newer so doesn’t have as many examples out yet but it works very similarly to isosurface, full reference is here

Hi, @alexcjohnson. Thank you so much for your reply. I have tried to use the Volume to show my data. However, the result seems unpromising, where the volume is composed of multiple slices instead of dense volume. It seems to connect points into planes. After checking the reference document, I still cannot find the way to solve this problem. Could you please help me out?
BTW, one sample of my data is listed as following (a 2D slice view for 3D).

Oh interesting, I hadn’t seen volume data like that before but it makes sense. Not quite sure what’s going on in your attempt to use volume but I don’t think that’s quite what you want anyway, that trace type is meant for semi-opaque rendering of the strength of some quantity across a volume.

I’d suggest an isosurface for each region, ie turn the array of indices into N bitmask arrays, something like:

bitmasks = [
    [[[1 if v==region else 0 for v in row] for row in slice] for slice in data]
    for region in range(1, n_regions + 1)

(or a more performant version with typed arrays and fewer loops but you get the idea :sweat_smile:) then create one isosurface trace for each of the regions, with an isomin somewhere between 0 and 1.