Reputation: 1744
I have a jpg image file of the surface of Neptune. My intention is to build a texture mapping (see Matlab help about this topic). I have used the command imread with the file but jpg files have not a colormap (in general, the command imread produces an MxNx3 matrix and a colormap is a Mx3 matrix). I would like to know how I could do it.
Like an image is more valuable than 1000 words (sometimes), my purpose is doing something like that example but for Neptune.
Upvotes: 4
Views: 8605
Reputation: 1744
Here is the solution for my question based on the answer of Jonas:
[X, map] = rgb2ind(imread('neptune.jpg'),128);
[x,y,z] = sphere(50);
x = 24764*x;
y = 24764*y;
z = 24764*z;
props.FaceColor= 'texture';
props.EdgeColor = 'none';
props.Cdata = flipud(X); % it is necessary to do this for getting the
% appropiate image on the sphere
surface(x,y,z,props);
colormap(map);
axis equal;
view([71 14]);
Upvotes: 2
Reputation: 74940
The MxNx3 array is a RGB array, i.e. at position (x,y), the third dimension corresponds to a triplet of red, green, and blue values.
To change from an RGB image to a indexed image with a colormap, you use the function RGB2IND
[indexedImage,colorMap] = rgb2ind(rgbImage, nColors); %# set nColors to e.g. 128
Upvotes: 7