2010-05-27 129 views
0

我想用MATLAB比較兩張圖像,並顯示一條消息'這是相同的圖像'。或「對不起,這是不一樣的圖像。」。我的程序總是顯示'這是相同的圖像'。使用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; 
+1

你做了什麼來診斷問題? – 2010-05-27 09:02:31

回答

4

您使用以下命令

i1=imread('001_1_1.fig'); 
i2=imread('001_1_1.fig'); 

這些圖像是在同一加載兩幅圖像,i1i2。因此,代碼會告訴你兩個圖像是相同的。

1

x = imread('first.jpg');

y = imread('seconda.jpg');

c = isequal(x,y);

``如果c == 1

的printf( '是等於'); else printf('Not');