What function other than colormap can display an image as a texture-mapped surface?

6 visualizaciones (últimos 30 días)
I already know how to wrap one image around a sphere, but once I introduce a second image into my code, I lose the first one. I believe it's because the colormap command is using the map from my second image (earth) instead of holding on to the first (sun). I've been told that trying to have multiple colormaps would be unnecessarily complicated and that there is another function that I can use instead, but I haven't been able to figure out which function I'm supposed to use.
for n = 1:numberOfPlanets
if n == 1
image = imread('sun.jpg');
else
image = imread('earth.jpg');
end
[indexed_image,map] = rgb2ind(image,256);
hold on
[x,y,z] = sphere;
planets = surf(x*Planet(n).Radius.r+Planet(n).Position.x,...
y*Planet(n).Radius.r+Planet(n).Position.y,...
z*Planet(n).Radius.r+Planet(n).Position.z,...
flipud(indexed_image),...
'FaceColor','texturemap',...
'EdgeColor','none',...
'CDataMapping','direct');
colormap (map)
hold off
end

Respuesta aceptada

Mike Garrity
Mike Garrity el 16 de Mzo. de 2016
In this example, you don't need colormaps at all. Just use the RGB images as the textures.
for n = 1:numberOfPlanets
if n == 1
image = imread('sun.jpg');
else
image = imread('earth.jpg');
end
hold on
[x,y,z] = sphere;
planets = surf(x*Planet(n).Radius.r+Planet(n).Position.x,...
y*Planet(n).Radius.r+Planet(n).Position.y,...
z*Planet(n).Radius.r+Planet(n).Position.z,...
flipud(image),...
'FaceColor','texturemap',...
'EdgeColor','none');
hold off
end
Is that because this has been overly simplified, or is your original code starting with RGB images?

Más respuestas (0)

Categorías

Más información sobre Blue en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by