之彩色图像的读取及RGB的数值读取

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=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');  
%取原图像部分数据
partdate(:,:,:)=image(1:10,1:10,:);%取最左上角10X10的原始图像数据
通过查看变量数据进行验证:
partdata中可以看到分别用val(:,:,1),val(:,:,2),val(:,:,3)来显示R,G,B的值。

我们再查看image_r左上10X10的值来验证val(:,:,1)


同样对比image_g,image_b的左上10X10与partdata中val(:,:,2),val(:,:,3)



















發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章