处理RGB图像(转YCbCr、灰度化、二值化)
思路:
1、读取系统图片
2、调用相关函数
3、输出转换后图片
RGB=imread('D:\matlab\image\image2.jpg'); //读入系统图片
subplot(2,2,1) //建立2x2的图像,在第一个位置显示
set(gcf,'position',[100,100,1000,700]) //调整figure位置与大小
imshow(RGB) //显示RGB图片
title('原图') //标题为“原图”
yc=rgb2ycbcr(RGB); //调用rgb2ycbcr()转化为YCbCr格式
subplot(2,2,2) //在第二个位置显示
imshow(yc) //显示YCbCr图像
title('YCBCR')
gray=rgb2gray(RGB); //调用rgb2gray()转化为灰度格式
subplot(2,2,3) //在第三个位置显示
imshow(gray)
title('gray')
Threshold=graythresh(gray); //调用graythresh()函数,输出为灰度阀值
bw=im2bw(gray,Threshold); //将灰度图像按阀值二值化
subplot(2,2,4)
imshow(bw)