get projection image without rendering to screen

5 views (last 30 days)
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.

Accepted Answer

Jonas Reber
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
Volkan
Volkan on 6 Jun 2011
Thank you Jonas,
I projected the point succesfully with the method you proposed. I used viewmtx function.
In the code which I wrote on my question, the texture data has rendered with trimesh function.
Now i projected the points on 2d space but i dont know how can i brush the area between points.(using my texture data). I have rgb color values for every vertex.
Thank you again for your support.
Jonas Reber
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')

Sign in to comment.

More Answers (1)

George Abrahams
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.

Community Treasure Hunt

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

Start Hunting!