matlab实现颜色分布法

clear all;
clc;
Image_1=imread('G:\\壁纸\\高达UC\\gundam_uc-011.jpg');
Image_2=imread('G:\\壁纸\\高达UC\\gundam_uc-019.jpg');

%获得8*8*8的区间
temp_1=uint16(floor(double(Image_1)/32));
temp_2=uint16(floor(double(Image_2)/32));

%获得矩阵大小
[m1,n1,c1]=size(temp_1);
[m2,n2,c2]=size(temp_2);
%申明零矩阵
A=zeros(1,512);
B=zeros(1,512);


%计算向量
for i=1:m1
    for j=1:n1
        a=temp_1(i,j,1)*64+temp_1(i,j,2)*8+temp_1(i,j,3)+1;
        A(a)=A(a)+1;
    end
end

for i=1:m2
    for j=1:n2
        a=temp_2(i,j,1)*64+temp_2(i,j,2)*8+temp_2(i,j,3)+1;
        B(a)=B(a)+1;
    end
end

%进行向量归一化
A=A/sum(A);
B=B/sum(B);

%计算余弦相似度
p=sqrt(sum(A.^2));
q=sqrt(sum(B.^2));
s=(A*B');

%计算余弦相似度
cos1=s/(p*q)

     

猜你喜欢

转载自blog.csdn.net/coolsunxu/article/details/79987507