简体   繁体   English

如何在MATLAB中从JPEG文件中获取色彩映射?

[英]How do I get a colormap from JPEG file in MATLAB?

I have a jpg image file of the surface of Neptune. 我有一个海王星表面的jpg图像文件。 My intention is to build a texture mapping (see Matlab help about this topic ). 我的目的是构建纹理映射(请参阅有关此主题的Matlab帮助 )。 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). 我已经使用命令imread和文件,但jpg文件没有colormap(一般来说,命令imread产生MxNx3矩阵,色图是Mx3矩阵)。 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. 就像一个图像比1000个单词(有时)更有价值,我的目的是做一些类似于海王星的例子

The MxNx3 array is a RGB array, ie at position (x,y), the third dimension corresponds to a triplet of red, green, and blue values. MxNx3阵列是RGB阵列,即在位置(x,y),第三维对应于红色,绿色和蓝色值的三元组。

To change from an RGB image to a indexed image with a colormap, you use the function RGB2IND 要使用色彩映射从RGB图像更改为索引图像,请使用RGB2IND函数

[indexedImage,colorMap] = rgb2ind(rgbImage, nColors); %# set nColors to e.g. 128 

Here is the solution for my question based on the answer of Jonas: 根据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]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM