提取RGB三个通道并显示,其中P为原始图像
P=imread('picture1.png'); subplot(1,4,1),imshow(P),title('原图像'); subplot(1,4,2),imshow(P(:,:,1)),title('r'); subplot(1,4,3),imshow(P(:,:,2)),title('g'); subplot(1,4,4),imshow(P(:,:,3)),title('b');matlab运行结果
绿色和蓝色通道互换
利用公式来将彩色图像转化为灰度图像
Y=0.299R+0.587G+0.114B
I=(R+G+B)/3;*
利用MATLAB自带函数来转化灰度图像
gray=rgb2gray(P);figure;imshow(gray),titile('函数灰度图像');