通过Alheistogram比较两个图像

时间:2015-12-22 17:30:49

标签: database matlab image-processing histogram

我的项目是关于图像的查询,我是你首先通过每个图像比较两个图像直方图如果给我的相似的图片是相似的,但问题是每当他告诉我输入两个不是相似

A=imread('C:\Users\saba\Desktop\images\q4.jpg');%reading images as array to variable 'a'&'b' 
B = imread('C:\Users\saba\Desktop\images\q1.jpg');
j=rgb2gray(A);
i=rgb2gray(B);
subplot(2,2,1);imshow(A);
subplot(2,2,2);imshow(B);
subplot(2,2,3);imshow(j);
subplot(2,2,4);imshow(i);

if  histeq(j)==histeq(i)
   disp('The images are same')%output display 
else 
   disp('the images are not same') 
end 

1 个答案:

答案 0 :(得分:0)

为了直接与==运算符进行比较,图像必须是相同的图像。如果您想要这样做,只需检查i==j是否为maxColumnDifference = max(abs(sum(j, 1) - sum(i, 1))); maxRowDifference = max(abs(sum(j, 2) - sum(i, 2))); ,只要它们的大小相同。

据我所知,没有内置函数或工具箱可以检查两个图像是否相似。您可以使用的一种粗略方法是查看每个行和列的像素值总和有多么不同:

maxColumnDifference = max(abs(sum(j, 1)/size(j,1) - sum(i, 1)/size(i,1)));
maxRowDifference = max(abs(sum(j, 2)/size(j,2) - sum(i, 2)/size(i,2)));

然后你可以有一些总和必须在其中的容差,应该是图像大小的函数。要给出行或列的不同程度的标准化答案(0-255),只需将每个总和除以像素数。

tolerance = 50;
if (maxRowDifference < tolerance) && (maxColumnDifference < tolerance)
    disp('Images are similarish');
else
    disp('Images are not similar enough for this poor tool to recognise');
end

然后,您可以确定它们是否类似于:

USER ~/projects/loopback/places-api $ slc deploy  http://IPADDRESS deploy

    Counting objects: 5215, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (4781/4781), done.
    Writing objects: 100% (5215/5215), 7.06 MiB | 4.27 MiB/s, done.
    Total 5215 (delta 1130), reused 0 (delta 0)
    To http://104.131.66.124:8701/api/services/1/deploy/default
     * [new branch]      deploy -> deploy
    Deployed `deploy` as `placesAPI` to `http://IPADDRESS:8701/`

请注意,这是所有推测,根本没有经过测试,并且可能有更好的方法。

相关问题