jpg图像是目前常用的图像格式,每一个像素点都由三个分别代表r(红色),g(绿色),b(蓝色)的值组合而成。所以一个jpg图像应该是一个三维数组(这里是与gray图像的最大区别,也是为什么不能直接对jpg图像做二值化的原因坐在。)
下程序读取一个jpg图像,分离并显示其R、G、B分量。可以看出各个分量对其灰度图像的影响
clear all
clc;
img=imread('Cat.jpg');
s=size(img);
R=img(:,:,1);
G=img(:,:,2);
B=img(:,:,3);
R=reshape(R,[s(1),s(2)]);
G=reshape(G,[s(1),s(2)]);
B=reshape(B,[s(1),s(2)]);
subplot(221)
imshow(img)
subplot(222)
imshow(R)
subplot(223)
imshow(G)
subplot(224)
imshow(B)
M=rgb2gray(img);
figure,
imshow(M);