R2 = r2(:,:,1); %比较图的通道分离
G2 = r2(:,:,2);
B2 = r2(:,:,3);
H_R2=imhist(R2);% 对比较图的每个通道计算直方图
H_G2=imhist(G2);
H_B2=imhist(B2);
subplot(231);imshow(r1);title('原图');
subplot(232);imshow(r2);title('比较图');
subplot(233);text(0.5,.5,{'相似度
为',num2str(fin)},'FontSize',24,'HorizontalAlignment','center');
subplot(234);plot(x,H_R1,'b',x,H_R2,'r:');title('R 直方图比
较');legend('原图','比较图');
subplot(235);plot(x,H_G1,'b',x,H_G2,'r:');title('G 直方图比
较');legend('原图','比较图');
subplot(236);plot(x,H_B1,'b',x,H_B2,'r:');title('B 直方图比
较');legend('原图','比较图');
t1=0;n1=0;m1=0;%赋初始值
t2=0;n2=0;m2=0;
t3=0;n3=0;m3=0;
for i=1:length(H_R1)
y1=[]; %对 R 通道的算法分析
if H_R1(i)~=H_R2(i)
y1=min([H_R1(i),H_R2(i)]);
else
y1=H_R1(i);
end
L1(i)=y1;
t1=t1+L1(i);
n1=n1+H_R1(i);
m1=m1+H_R2(i);
y2=[]; %对 G 通道的算法分析
if H_G1(i)~=H_G2(i)
y2=min([H_G1(i),H_G2(i)]);
else
y2=H_G1(i);
end
L2(i)=y2;
t2=t2+L2(i);
n2=n2+H_G1(i);
m2=m2+H_G2(i);