get projection image without rendering to screen

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

采纳的回答

Jonas Reber
Jonas Reber 2011-6-3
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 个评论
Volkan
Volkan 2011-6-6
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 2011-6-7
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')

请先登录,再进行评论。

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by