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

4 次查看(过去 30 天)
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?

采纳的回答

George Abrahams
George Abrahams 2024-1-23
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.

更多回答(1 个)

George Abrahams
George Abrahams 2024-2-10
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.

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by