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

5 次查看(过去 30 天)
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

采纳的回答

Mike Garrity
Mike Garrity 2016-3-16
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?

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Blue 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by