%%RGB三通道颜色展示
clc,clear,close all
a=imread('./000t50.bmp');%读图
figure(1);imshow(a);%建立窗口画图,显示原图
b=rgb2gray(a);%转化为灰度图像
figure(2);imshow(b);%建立窗口画图,显示灰度图像
a1=a(:,:,1);%选择R通道
figure(3);imshow(a1);%建立窗口画图,显示R通道图像
a2=a(:,:,2);%选择R通道
figure(4);imshow(a2);%建立窗口画图,显示G通道图像
a3=a(:,:,3);%选择R通道
figure(5);imshow(a3);%建立窗口画图,显示B通道图像
说明:1.“000t50.bmp”是图片名
2.“./000t50.bmp“,该路劲为相对路径。使用 ”./“则需图片和该m文件在同一文件夹下。
结果:
从左至右分别是RGB原图、灰度图像、R通道图像、G通道图像、B通道图像
![](https://img-blog.csdnimg.cn/img_convert/02a2779132726bec7e3766e51174b5fe.png)
![](https://img-blog.csdnimg.cn/img_convert/c4857dce17429b83fa25e81a5f5a65f6.png)
![](https://img-blog.csdnimg.cn/img_convert/1726b8791505387fe2c12caa586f6243.png)
![](https://img-blog.csdnimg.cn/img_convert/97fdaab5c9e115435bb8a4c37a5198fd.png)