0

I am currently working on a project in which I need to check the similarity between images... I have started of trying the cosine similarity.. the formula available online needed to be modified since it was only for text and in images the 1st pixel of one image will have to be checked with every pixel of the next. I tried the following code in matlab but it gives no output.. i have no idea if i am even remotely correct..

x1=imread('C:\Program Files\MATLAB\R2009a\image classes\flowers\f1.jpg');
x2=imread('C:\Program Files\MATLAB\R2009a\image classes\flowers\f2.jpg');
%[m1 n1]=size(x1);
%[m2 n2]=size(x2);
for i=1:256
    for j=1:256
        if(x1(i,j)==0)
            x1(i,j)=1;
        end
        if(x2(i,j)==0)
            x2(i,j)=1;
        end
    end
end

y1=0;
y2=0;
y3=0;
for i=1:256
    for k=1:256
        z1=x1(i,k);
       for j=1:256
           for l=1:256
            y1=y1+z1*x2(j,l);
           end
       end
    end
end

for i=1:256
    for j=1:256
        y2=y2+x1(i,j)*x1(i,j);
    end
end


for i=1:256
    for j=1:256
        y3=y3+x2(i,j)*x2(i,j);
    end
end

sim=y1/(y2*y3);
[m n]=size(sim);
imshow(sim);
display(sim);
2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by JamesCherrill
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.