MATLAB(完备)之图像.tif到真彩色图像、索引色图像、灰度图像、 真彩色图像RGB、YIQ图像、HSV图像、YCbCr图像转换代码

I=imread(‘flower.tif’);%读入图片
whos I
imfinfo(‘flower.tif’)
imshow(I);title(‘原始tif图像’)

%%真彩图像、转索图像、灰度图像、二值图像的相互转换
imwrite(I,‘flower.jpg’,‘quality’,10)%tif转化rgb
I1=imread(‘flower.jpg’);
figure;imshow(I1);title(‘真彩色图像’)
[X,map] = rgb2ind(I1,32);%真彩转索引
figure;imshow(X,map),colorbar,title(‘索引图像’)
rgb=ind2rgb(X,map);%索引转rgb
figure;imshow(rgb);title(‘rgb图像’)
G=rgb2gray(I1);
figure;imshow(G);title(‘rgb转灰度图像’)
G1=ind2gray(X,map);%索引转灰度
figure;imshow(G1);title(‘索引转灰度图像’)
G3=im2bw(I1);%图像转二值图像
figure;imshow(G3);title(‘二值图像’)

%%RGB/YIQ/HSV/YCbCr之间的转换
image = imread(‘lena.jpg’);
figure;subplot(331);imshow(image);title(‘原始图像’)
%RGB&YIQ
YIQ=rgb2ntsc(image);
subplot(332);imshow(YIQ);title(‘YIQ图像’)
rgb=ntsc2rgb(YIQ);
subplot(333);imshow(rgb);title(‘rgb图像’)
%RGB&HSV
HSV=rgb2hsv(image);
subplot(334);imshow(image);title(‘原始图像’)
subplot(335);imshow(HSV);title(‘HSV图像’)
RGB1=hsv2rgb(HSV);
subplot(336);imshow(RGB1);title(‘RGB图像’)
%RGB&YCbCr
yc=rgb2ycbcr(image);
subplot(337);imshow(image);title(‘原始图像’)
subplot(338);imshow(yc);title(‘ycbcr图像’)
rgb2=ycbcr2rgb(yc);
subplot(339);imshow(rgb2);title(‘RGB图像’)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值