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图像’)