get projection image without rendering to screen
3 views (last 30 days)
Show older comments
Hi,
I have an 3d model and ı want to take its 2d projection.
I can get it from rendered projection from figure with the method below succesfully.
trimesh(...
tl, shp(:, 1), shp(:, 3), shp(:, 2), ...
'EdgeColor', 'none', ...
'FaceVertexCData', tex/255, 'FaceColor', 'interp', ...
'FaceLighting', 'phong' ...
set(gca, ...
'DataAspectRatio', [ 1 1 1 ], ...
'PlotBoxAspectRatio', [ 1 1 1 ], ...
'Units', 'pixels', ...
'GridLineStyle', 'none', ...
'Position', [ 0 0 fig_pos(3) fig_pos(4) ], ...
'Visible', 'off', 'box', 'off', ...
'Projection', 'perspective' ...
);
h=gca;
F=getframe(h);
im=F.cdata;
Now, I wanna take projection image without the need of rendered to screen. Because ı used the method on an optimization process and rendering process costs so much to me.
Thanks for your time.
0 Comments
Accepted Answer
Jonas Reber
on 3 Jun 2011
you could calculate the perspective projection of your model yourself as you have all the information on camera position, look at point, etc. this ends up to a matrix multiplication (see Shirleys "Fundamentals of Computer Graphics" or Wikipedia: http://en.wikipedia.org/wiki/3D_projection#Perspective_projection)
but what you probably are looking for is the matlab function "viewmtx" (<http://www.mathworks.com/help/techdoc/ref/viewmtx.html)>?
2 Comments
Jonas Reber
on 7 Jun 2011
Hi Volkan,
once you have your 2D points you can use patch (http://www.mathworks.com/help/techdoc/ref/patch.html) to draw things.
Take a look at the explanation given in the documentation - it is quite good. (i.e. you need to set the 'FaceVertexCData')
More Answers (1)
George Abrahams
on 10 Feb 2024
My 3D Rendering Toolbox on File Exchange is one option for doing this. The world2image function performs the perspective projection you've calculated yourself, and a bit more.
If you're okay with 2D vector graphics (composed of polygons), i.e., you don't need a rastered image (composed of pixels), that right there is enough. Otherwise, the projection is only the first step, as you've discovered.
My toolbox also contains a rasterize function. However, given that you need interpolated face colors (from vertex colors) and face lighting, Patch Software Render or Rendering Pipeline may suit better, although I have no experience with them.
0 Comments
See Also
Categories
Find more on Convert Image Type 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!