How can I get the image plane of a rendered 3D mesh?
4 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
George Abrahams
on 23 Jan 2024
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.
0 Comments
More Answers (1)
George Abrahams
on 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.
0 Comments
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!