jwu
January 3, 2017, 1:50am
1
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.
using ModernGL, GeometryTypes, GLAbstraction, GLFW, Images, FileIO, Reactive, LinearAlgebra
const GLA = GLAbstraction
kitten = load(GLAbstraction.dir("tutorials", "images", "kitten.png"))
puppy = load(GLAbstraction.dir("tutorials", "images", "puppy.png"))
# Create the window. This sets all the hints and makes the context current.
window = GLFW.Window(name="Depth and Stencils 1", resolution=(800,600),
windowhints=[(GLFW.DEPTH_BITS,32), (GLFW.STENCIL_BITS, 8)])
GLFW.MakeContextCurrent(window)
GLA.set_context!(window)
# The cube. This could be more efficiently represented using indexes,
# but the tutorial doesn't do it that way.
vertex_positions = Vec3f0[
(-0.5f0, -0.5f0, -0.5f0),
( 0.5f0, -0.5f0, -0.5f0),
( 0.5f0, 0.5f0, -0.5f0),
This file has been truncated. show original
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
jwu
January 3, 2017, 3:31pm
4
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:
Yeah you can use GLVisualize it
[Volume slicer]
Code:
Sorry for any inconveniences, I just right now fixed up GLPlot to work with the newest GLVisualize, so it might still act buggy.
It would be possible to add this code sample as a visualization style.
IJulia integration is not great right now, since the interactivity will mostly be missing
It’s implemented for the Plots.jl package, since it is quite static to begin with, but not for GLVisualize/GLPlo…
If this example doesn’t work for you, let me know;)
2 Likes
jwu
January 5, 2017, 7:07pm
7
@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:
SimonDanisch:master
← jingpengw:fixmaster
opened 06:31PM - 05 Jan 17 UTC
fix example errors, still not working.
- replaced `create_window` by GLPlot.i… nit()
- add typealias for Vec2/3/4 types.
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
)
jwu
January 5, 2017, 10:58pm
9
it works
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