Matab 灰度图 生成 伪彩色 图像 gray convert to pseudo color

Matab 灰度图 生成 伪彩色 图像  gray convert to pseudo color


原文出处: http://www.alecjacobson.com/weblog/?p=1655


In matlab you can view a grayscale image with:


imshow(im)

Which for my image im shows:
matlab imshow grayscale
And you can also view this grayscale image using pseudocolors from a given colormap with something like:


imshow(im,'Colormap',jet(255))

Which shows:
matlab imshow colormap jet 255
But it’s not obvious how to use the colormap to actually retrieve the RGB values we see in the plot. Here’s a simple way to convert a grayscale image to a red, green, blue color image using a given colormap:


rgb = ind2rgb(gray2ind(im,255),jet(255));

Replace the 255 with the number of colors in your grayscale image. If you don’t know the number of colors in your grayscale image you can easily find out with:


n = size(unique(reshape(im,size(im,1)*size(im,2),size(im,3))),1);

It’s a little overly complicated to handle if im is already a RGB image.

If you don’t mind if the rgb image comes out as a uint8 rather than double you can use the following which is an order of magnitude faster:


rgb = label2rgb(gray2ind(im,255),jet(255));

Then with your colormaped image stored in rgb you can do anything you normally would with a rgb color image, like view it:


imshow(rgb);

which shows the same as above:
matlab imshow colormap jet 255


I = imread('G:\H1.png');
I = rgb2gray(I);
rgb = label2rgb(gray2ind(I, 255), jet(255));
imshow(rgb);




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值