clear all;
close all;
clc;
img=imread('saber9.jpg');
img2=imread('saber2.jpg');
imshow(img)
figure,imshow(img2);

tmp=rgb2gray(img);
tmp2=rgb2gray(img2);

img_re=imresize(tmp,[8 8]);
img_re2=imresize(tmp2,[8 8]);

img_re=uint8(double(img_re)/4);
img_re2=uint8(double(img_re2)/4);

me=mean(mean(img_re));
me2=mean(mean(img_re2));

for i=1:8
    for j=1:8
        if img_re(i,j)>=me
            img_re(i,j)=1;
        else
            img_re(i,j)=0;
        end
        
        if img_re2(i,j)>=me2
            img_re2(i,j)=1;
        else
            img_re2(i,j)=0;
        end
                        
    end
end

re=uint8(double(img_re)-double(img_re2));

num=0;
for i=1:8
    for j=1:8
        if re(i,j)~=0
            num=num+1;
        end
    end
end
num

CSDN上看到的有意思的东西。

参考:

1.http://www.ruanyifeng.com/blog/2011/07/principle_of_similar_image_search.html