clc
close all
clear
%本程序基于图像的色彩特征和纹理特征值对图像进行相似度度量,分别采用HSV色彩空间取特征量和LBP算法取特征值来计算
%相似性度量采用欧氏距离来度量,参考度量方式为巴士系数计算法
%读取图像源文件,为方便计算和检验,请规定图像大小为512*512像素
image1=imread('test3.jpg');
image2=imread('test33.jpg');
%显示源图片
figure(1);
set(figure(1),'NumberTitle','off','Name','图片显示') ;
subplot(211),imshow(image1);
subplot(212),imshow(image2);
image1g = rgb2gray(image1);
image2g = rgb2gray(image2);
imagelbp=LBP(image1g);
imagelbp1=LBP(image2g);
%对图像进行处理,使之转化为HSV空间
[H1,S1,V1]=GetHSV(image1);
[H2,S2,V2]=GetHSV(image2);
%对图像H,S, V进行量化,结合人类对七种光源红橙黄绿青蓝紫的敏感度,将HSV分化为36维向量
%量化化函数为Quantificate
[H1,S1,V1]=Quantificate(H1,S1,V1);
[H2,S2,V2]=Quantificate(H2,S2,V2);
%归一化处理图像使之转化为36维的灰度图像以便运算
% [m,n]=size(image1);
% [M,N]=size(image2);
% G=zeros(m,n);
% G1=zeros(M,N);
G=Normalize(H1,S1,V1);
G1=Normalize(H2,S2,V2);
COUNT1=count(G);
COUNT2=count(G1);
y=zeros(36,1);
for pp=1:36
y(pp,1)=pp;
end
figure;
set(figure(2),'NumberTitle','off','Name','色彩直方图') ;
subplot(211),bar(y,COUNT1);
subplot(212),bar(y,COUNT2);
COUNT=COUNT1-COUNT2;
od=COUNT.*COUNT;
m=size(COUNT);
odist=0;
for i=1:m
odist=odist+od(i,1);
end
odist=sqrt(odist);
% [COUNT3,x]=imhist(imagelbp);
% [COUNT4,x]=imhist(imagelbp1);
temp = 0:255;
imagelbpt = reshape(imagelbp,1,[]); %降维方便histc统计出现次数
imagelbp1t = reshape(imagelbp1,1,[]);
[COUNT3]=histc(imagelbpt,temp);
[COUNT4]=histc(imagelbp1t,temp);
COUNT0=COUNT3-COUNT4;
odlbp=COUNT0.*COUNT0;
m=size(COUNT0);
odistlbp=0;
for i=1:m
odistlbp=odistlbp+odlbp(i,1);
end
odistlbp=sqrt(odistlbp);
figure;
set(figure(3),'NumberTitle','off','Name','LBP处理') ;
subplot(2,2,1);imshow(imagelbp,[])
subplot(2,2,2);imshow(imagelbp1,[]);
subplot(2,2,3);hist(imagelbpt,temp);
subplot(2,2,4);hist(imagelbp1t,temp);
Odistance=sqrt(odist^2+odistlbp^2);
Odistance=log(sqrt(Odistance))