MATLAB Answers

Image changing to blue and yellow?

8 views (last 30 days)
Chris Gnam
Chris Gnam on 25 Sep 2017
Commented: Jan on 26 Sep 2017
I'm trying to render the moon in orbit around the Earth. I was able to get a decent map of the Moon, which I then want to wrap over a sphere. (This is the same process I did for the Earth, and it turned out perfectly). The only problem is, when I try to do that with the moon image, it changes all the colors around and suddenly becomes blue and yellow.
Here, I've included on the left hand side, the 3d model, and on the right hand side, the image itself.
I'm really at a loss as to why this would be happening... Here is my code if that is useful:
[x,y,z] = sphere(120);
Xmoon = RenderedLunarRadius*x;
Ymoon = RenderedLunarRadius*y;
Zmoon = RenderedLunarRadius*z;
Moon = imread('Moon Texture.jpg');
Moon = flip(Moon ,1);
Moon = surface(Xmoon + 2*Re,Ymoon,Zmoon, Moon,...
'FaceColor','texturemap','EdgeColor','none');
alpha(Moon,1);
material(Moon,'dull')

Answers (1)

Jan
Jan on 25 Sep 2017
Your image of the moon is treated as indexed color image and the current colormap is applied. Convert it to an RGB image instead:
[Moon, Map] = imread('Moon Texture.jpg');
if ~isempty(Map)
MoonRGB = ind2rgb(Moon, Map);
else
MoonRGB = im2double(Moon);
end
Does it work? Perhaps a double(Moon) / 255 is useful also.
  2 Comments
Jan
Jan on 26 Sep 2017
Give us a chance to test, what we suggest: Attach the image file. The solution will be trivial, but currently I need to guess.
Does this help:
MoonRGB = MoonRGB(:, :, ones(1,3));

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by