Visualize 3D slices of an 3D image volume?

I’d like to visualize a 3D image volume, but did not find an example in Plots.jl and GLVisualize.jl.

one example is here

I found that there is an example in the tutorial of GLAbstraction, but it requires an existing fragment shadder file for the texture image.

I got this pretty result:


But I did not find a way to visualize other images.

Do we have this functionality ready? If not, could anyone give a hint to implement?

1 Like

It should be possible with glvisualise and GLPlot, see interactive volume plots on Vimeo . I cannot seem to find the example code, unfortunately :frowning:

I think the example code is: https://gist.github.com/SimonDanisch/7f700728485a4742ad3c0767fb573828#file-volume_example-jl, but only @sdanisch can tell us if that is still the correct way.

1 Like

Thanks for your note. The example did not show the lower right orthogonal visualization.

I can show single slices with sprites, but I did not find a way to rotate the images…

I don’t think there is a function to do that type of plot automatically. But you might try to make a copy of vol (from the example), then replacing all the points you want to be transparent with NaN, eg

vol2 = copy(vol)
for k in 1:size(vol,3)
  for j in 1:size(vol,2)
    for i in 1:size(vol,1)
      i == 75 | j == 75 | k == 75 | (vol2[i, j, k] = NaN)
    end
  end
end
plot(vol2)

Yes you can do this:

If this example doesn’t work for you, let me know;)

2 Likes

@sdanisch Thanks a lot for the examples!
the volome_slice.jl works after fixing a few small bugs.

  • manually build and precompile Plots.jl
  • change create_window to GLPlot.init()
  • add sleep(1000) after glplot to keep the window running

All of other examples do not work for me…
I have created a pull request to GLPlot.jl to fix a few known issues:


another question is that how can I control the RGB value? I would like to see gray scale image here, but it is bluish.
In other use cases, I would like to see RGB or RGBA image. where can I switch these? In the shader file of GLVisualize.jl?

You can pass a colormap like this to the plotting function:

glplot(
        slice,
        stroke_width = 0.0f0,
        color_norm = Vec2f0(0, 1), # normalize values to be between 0 and 1, before color lookup
        color_map = RGBA{Float32}[....] # you can pass an array of RGBA values as a colormap
    )

it works :slight_smile:

I used the gray scale colormap.
color_map = RGBA{Float32}[RGBA{Float32}(0,0,0,1), RGBA{Float32}(1,1,1,1)]

I have another format with RGBA images. If the slice image is already an Array{RGBA, 2}, GLPlot will display it directly without specifying colormap?

That should work pretty similar.
I adapted the volume slice example to work with volume of colors:
https://github.com/SimonDanisch/GLPlot.jl/blob/master/example/rgb_volume_slice.jl

Again, it works great :slight_smile:

Thanks a lot!

3 Likes