Matlab 读取彩色图像是三维数组,图像的坐标是以左上角为(0,0)点,彩色图像形成的三维数组中前两位表示图像的像素点的坐标,第三位为1时表示是图像中R的值,为2时表示G的值,为3时表示B的值。故若要对一个彩色图像分别读取R,G,B时,采用下述代码即可。
% 2017-3-14
% write by Mr.Han
clc;
clear;
%读入原图像及获取大小
image = imread('1.jpg');
% 分别读取RGB
image_r=image(:,:,1);
image_g=image(:,:,2);
image_b=image(:,:,3);
% 测试RGB输出
subplot(2,2,1),imshow(image_r),title('Red component');
subplot(2,2,2),imshow(image_g),title('green component');
subplot(2,2,3),imshow(image_g),title('blue component');
subplot(2,2,4),imshow(image),title('original image');
对上述结果进行验证,分别读取图像的RGB的值,并取原图像左上角10X10的值。代码如下:
% 2017-3-14
% write by Mr.Han
clc;
clear;
%读入原图像
image = imread('1.jpg');
% 分别读取RGB
image_r=image(:,:,1);
image_g=image(:,:,2);
image_b=