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

7 views (last 30 days)
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

Accepted Answer

Mike Garrity
Mike Garrity on 16 Mar 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?

More Answers (0)

Community Treasure Hunt

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

Start Hunting!