RGB-images on a 3D cube

조회 수: 22 (최근 30일)
Jakob Sørensen
Jakob Sørensen 2012년 3월 13일
댓글: sana3 sal 2019년 8월 4일
Hey,
For a a presentation, I would like to make a 3D cube in Matlab (that's pretty simple I know), but I would also like for the surface of it to be an RGB image (the image repeats on each of the 3 visible sides), and this, I can't figure out how to do. So can anyone help me? Converting it to some sort of indexed colorscale would be fine as well, but it should preferably stay in roughly the same colors.

채택된 답변

Patrick Kalita
Patrick Kalita 2012년 3월 14일
This is an application for texture mapping. You can create six surfaces -- one for each face of the cube -- and apply your RGB image(s) as the texture map for each. You just have to make sure you flip around the RGB image data so that you're looking at it from the "right side", when assembled into a cube.
Here's a full example:
cdata = flipdim( imread('peppers.png'), 1 );
cdatar = flipdim( cdata, 2 );
% bottom
surface([-1 1; -1 1], [-1 -1; 1 1], [-1 -1; -1 -1], ...
'FaceColor', 'texturemap', 'CData', cdatar );
% top
surface([-1 1; -1 1], [-1 -1; 1 1], [1 1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdata );
% font
surface([-1 1; -1 1], [-1 -1; -1 -1], [-1 -1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdata );
% back
surface([-1 1; -1 1], [1 1; 1 1], [-1 -1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdatar );
% left
surface([-1 -1; -1 -1], [-1 1; -1 1], [-1 -1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdatar );
% right
surface([1 1; 1 1], [-1 1; -1 1], [-1 -1; 1 1], ...
'FaceColor', 'texturemap', 'CData', cdata );
view(3);
If you're not sure how it all works, try adding one surface at a time -- it might be more clear that way.
  댓글 수: 3
Yapo OBOUE
Yapo OBOUE 2019년 5월 21일
Patrick Kalita your are a genuis ! its works perfect !
sana3 sal
sana3 sal 2019년 8월 4일
Can I convert this cube to a real mesh? (set of faces and vertices)?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by