多通道图像直方图程序

clear  
I=imread('info_surf01.jpg');%读取图像  
Imatch=imread('info_surf09.jpg');%读取匹配图像  
R=I(:,:,1);%获取原图像R通道  
G=I(:,:,2);%获取原图像G通道  
B=I(:,:,3);%获取原图像B通道  
Rmatch=Imatch(:,:,1);%获取匹配图像R通道  
Gmatch=Imatch(:,:,2);%获取匹配图像G通道  
Bmatch=Imatch(:,:,3);%获取匹配图像B通道  
Rmatch_hist=imhist(Rmatch);%获取匹配图像R通道直方图  
Gmatch_hist=imhist(Gmatch);%获取匹配图像G通道直方图  
Bmatch_hist=imhist(Bmatch);%获取匹配图像B通道直方图  
Rout=histeq(R,Rmatch_hist);%R通道直方图匹配  
Gout=histeq(G,Gmatch_hist);%G通道直方图匹配  
Bout=histeq(B,Bmatch_hist);%B通道直方图匹配  
J(:,:,1)=Rout;  
J(:,:,2)=Gout;  
J(:,:,3)=Bout;  
figure;%显示原图像、匹配图像和匹配后的图像  
subplot(1,3,1),imshow(I);title('原图像');  
subplot(1,3,2),imshow(Imatch);title('匹配图像');  
subplot(1,3,3),imshow(J);title('匹配之后图像');  
figure;%显示原图像、匹配图像和匹配后图像的直方图  
subplot(3,3,1),imhist(R,64);ylabel('原图像R通道直方图');  
subplot(3,3,2),imhist(G,64);ylabel('原图像G通道直方图');  
subplot(3,3,3),imhist(B,64);ylabel('原图像B通道直方图');  
 
subplot(3,3,4),imhist(Rmatch,64);ylabel('匹配图像R通道直方图');  
subplot(3,3,5),imhist(Gmatch,64);ylabel('匹配图像G通道直方图');  
subplot(3,3,6),imhist(Bmatch,64);ylabel('匹配图像B通道直方图');  
 
subplot(3,3,7),imhist(Rout,64);ylabel('匹配之后图像R通道直方图');  
subplot(3,3,8),imhist(Gout,64);ylabel('匹配之后图像G通道直方图');  
subplot(3,3,9),imhist(Bout,64);ylabel('匹配之后图像B通道直方图'); 

posted on 2017-10-10 21:53  悟江居士  阅读(277)  评论(0编辑  收藏  举报

导航