How can I get the image plane of a rendered 3D mesh?

1 Ansicht (letzte 30 Tage)
Aura Munoz
Aura Munoz am 31 Mär. 2015
Bearbeitet: Matt J am 10 Feb. 2024
I need to get the pixel value of a specific (x,y) 2D coordinate after rendering a 3D mesh into the image plane/ axes plot box.
I'm using the trimesh function to create the mesh based on the vertices and the faces and rendering using opengl and a perspective projection by setting the axis as
set(gca, ...
'DataAspectRatio', [ 1 1 1 ], ...
'PlotBoxAspectRatio', [ 1 1 1 ], ...
'Units', 'pixels', ...
'Position', [ 0 0 width height ], ... 'Projection', 'perspective');
and using
view(az,el);
Is there another way instead of calculating the perspective projection and all the matrices multiplications inside the my code?

Akzeptierte Antwort

George Abrahams
George Abrahams am 23 Jan. 2024
The most literal answer to your question is getframe. For example:
surf( peaks )
% Convert the plot to an image.
F = getframe;
% Show the image and the colour value of a sample point.
close
imshow( F.cdata )
center = ceil( size( F.cdata, 1:2 ) / 2 );
text( center(2), center(1), ...
"(" + strjoin( string( F.cdata(center(1),center(2),:) ), "," ) + ")", ...
"BackgroundColor", "w" )
Without more information, however, it's impossible to know if this meets your requirements.

Weitere Antworten (1)

George Abrahams
George Abrahams am 10 Feb. 2024
Me again. The alternative is to, like you said, render it yourself with perspective projection etc. This will give you full control over the camera, for example, so that you can set the image resolution, limit what's rendered according to field-of-view, and have no other graphic elements on the screen, such as the axes.
Thankfully people have already released code for this so you wouldn't be going from scratch. One option is my 3D Rendering Toolbox, but a few other options also exist on File Exchange.

Kategorien

Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by