RGB-images on a 3D cube

25 visualizaciones (últimos 30 días)
Jakob Sørensen
Jakob Sørensen el 13 de Mzo. de 2012
Comentada: sana3 sal el 4 de Ag. de 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.

Respuesta aceptada

Patrick Kalita
Patrick Kalita el 14 de Mzo. de 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 comentarios
Yapo OBOUE
Yapo OBOUE el 21 de Mayo de 2019
Patrick Kalita your are a genuis ! its works perfect !
sana3 sal
sana3 sal el 4 de Ag. de 2019
Can I convert this cube to a real mesh? (set of faces and vertices)?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by