Direct code
% cosine similarity algorithm to find the similarity of two picturesPicture1 = Imread (' d:\\ bracelet. jpg ');p Icture2 = Imread (' d:\\ bracelet 2.jpg ');p Icture1 = Rgb2gray (picture1);p icture2 = Rgb2gray (picture2); t1=picture1;[A1,B1]=size(t1); T2=picture2;t2=imresize (T2,[A1 B1],' Bicubic ');% scaled to a consistent sizet1=round(t1); t2=round(T2); e1=Zeros(1, the); e2=Zeros(1, the);% get histogram distribution/ for I=1: A1 for J=1: B1 m1=t1 (I,J)+1; M2=t2 (I,J)+1; E1 (M1) =E1 (M1) +1; E2 (m2) =e2 (m2) +1;EndEndFigure;imhist (uint8 (t1)); Figure;imhist (Uint8 (T2));% divides the histogram into 64 zonesm1=Zeros(1, -); m2=Zeros(1, -); for I=0: theM1 (1,I+1) =e1 (4*I+1) +e1 (4*I+2) +e1 (4*I+3) +e1 (4*I+4); M2 (1,I+1) =e2 (4*I+1) +e2 (4*I+2) +e2 (4*I+3) +e2 (4*I+4);End% calculation of cosine similarityA=sqrt(Sum (SUM (M1.^2))); b=sqrt(Sum (SUM (m2.^2))); C=sum (SUM (M1.*M2)); cos1=c/(a*b);% compute cosine valueCos2=ACOs(COS1);% radiansv=cos2* the/Pi;% conversion into angleFigure;imshow (Uint8 ([T1,t2])); Title ([' cosine value: ', Num2str (COS1),',' cosine angle: ', Num2str (v),' ° ']);% End
"matlab": Image correlation recognition algorithm made by MATLAB