RGB-images on a 3D cube

25 ビュー (過去 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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by