用MATLAB比较图像

时间:2010-05-27 08:51:28

标签: matlab image-processing

我想使用MATLAB比较两张图片,并显示一条消息“这是同一张图片”。或者'抱歉,这不是同一个图像。'我的程序始终显示“它是相同的图像。”。

我的代码是:

i1 = imread('001_1_1.fig');
i2 = imread('001_1_1.fig');
x1 = edge(i1,'canny');
j1 = imcrop(x1,[135 90 100 95]);
x2 = edge(i2,'canny');
g = 0;
xxx = 1;
yyy = 1;

for n = 1:1:2
    g1 = imrotate(j1,n,'bilinear','crop');
    r1 = corr2(j1,g1);
    if(xxx<r1)
    else
        xxx = r1;
    end;
end;

for n = 180:-1:178
    g1 = imrotate(j1,n,'bilinear','crop');
    r1 = corr2(j1,g1);
    if(yyy<r1)
    else
        yyy = r1;
    end;
end;

if(xxx <= yyy)
    r_corr = xxx;
else
    r_corr = yyy;
end;

j2 = imcrop(x2,[135 90 100 95]);
r = corr2(j1,j2);
if (r==1)
    disp('it is the same image')
    return;
elseif (r >= r_corr)
    disp('it is the same image')
    return;
else
    g = 1;
end;

if(g==1)
    disp('sorry, it is not the same image')
end;

2 个答案:

答案 0 :(得分:4)

您正在使用以下命令

加载两个图像,i1i2
i1=imread('001_1_1.fig');
i2=imread('001_1_1.fig');

这些图像是相同的。因此,代码会告诉您两个图像是相同的。

答案 1 :(得分:1)

X = imread( 'first.jpg');

Y = imread( 'seconda.jpg');

C = ISEQUAL(X,Y);

``如果c == 1

printf('是等于');  else printf('不');