使用MATLAB将任何图像类型转换为RGB
我有一个图像,我用这个代码得到它使用MATLAB将任何图像类型转换为RGB,matlab,Matlab,我有一个图像,我用这个代码得到它 [path,user_cance]=imgetfile(); im=imread(path); 现在我不知道这张图片是RGB还是索引或者 例如,如何将im转换为RGB?如果是索引图像,则可以轻松使用ind2rgb功能: 阅读图片: [X,map] = imread('imagefile.tif'); 验证颜色贴图map是否为空,并将X中的数据转换为RGB if ~isempty(map) Im = ind2rgb(X,map); end 最后,您可
[path,user_cance]=imgetfile();
im=imread(path);
现在我不知道这张图片是RGB还是索引或者
例如,如何将im转换为RGB?如果是索引图像,则可以轻松使用ind2rgb功能: 阅读图片:
[X,map] = imread('imagefile.tif');
验证颜色贴图map是否为空,并将X中的数据转换为RGB
if ~isempty(map)
Im = ind2rgb(X,map);
end
最后,您可以查看X的大小和类别
whos Im
ind2rgb将矩阵X和相应的彩色贴图转换为RGB(truecolor)格式。
X可以是uint8、uint16、单或双类RGB是双类的m-x-n-x-3数组
您可以找到可以使用MATLAB读取的图像格式。根据Mathworks文档(),
imread
可以从其内容推断数据类型
您可以测试colormap是否存在或是否为空:
[im, map] = imread(path_to_image);
if(isempty(map)) % image is RGB or grayscale
if(size(im, 3) == 1) % image is grayscale
im = cat(3, img, img, img);
end
else % image is indexed
im = ind2rgb(im, map);
end
% now 'im' is a RGB-image
非常感谢你。。。。你能给我写一个相同问题的代码,但是索引状态吗?我是一名matlab初学者(: