RGB-images on a 3D cube

22 Ansichten (letzte 30 Tage)
Jakob Sørensen
Jakob Sørensen am 13 Mär. 2012
Kommentiert: sana3 sal am 4 Aug. 2019
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.

Akzeptierte Antwort

Patrick Kalita
Patrick Kalita am 14 Mär. 2012
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 Kommentare
Yapo OBOUE
Yapo OBOUE am 21 Mai 2019
Patrick Kalita your are a genuis ! its works perfect !
sana3 sal
sana3 sal am 4 Aug. 2019
Can I convert this cube to a real mesh? (set of faces and vertices)?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by