2013-12-19 57 views
1

我想比較使用corr2的多個圖像來查看相關性的相似性。比較2個不同的圖像

for i=1:2 
    first_img = imread(sprintf('%g.jpg',i)); 
    first_size = size(first_img); 
    size_temp = size(first_size); 
    max_size = max(size_temp); 
    if max_size == 3 
     first_img = rgb2gray(first_img); 
     first_size = size(first_img); 
    end 
    for j=i+1:2 
     second_img = imread(sprintf('%g.jpg',j)); 
     second_size = size(second_img); 
     size_temp = size(second_size); 
     max_size = max(size_temp); 
     if max_size == 3 
      second_img = rgb2gray(second_img); 
      second_size = size(second_img); 
     end 
     if i == j 
      continue;end 
     if first_size ~= second_size 
      continue;end 
     if first_size == second_size 
      correlation_fs = corr2(first_img,second_img); 
      if correlation_fs == 1 
       fprintf('%g is the same as %g\n',first_img,second_img); 
      end 
     end 
    end 
end 

現在,第一張圖像與第三張圖像相比,第一張圖像與第一張圖像完全相同時出現問題。

219 is the same as 219 
220 is the same as 220 
221 is the same as 221 
221 is the same as 222 
224 is the same as 223 
222 is the same as 221 
221 is the same as 222 
223 is the same as 224 
218 is the same as 236 
242 is the same as 232 
217 is the same as 219 
226 is the same as 228 
220 is the same as 229 
241 is the same as 251 
254 is the same as 253 
250 is the same as 247 
253 is the same as 253 
252 is the same as 248 
237 is the same as 224 
217 is the same as 218 
225 is the same as 219 
219 is the same as 223 
219 is the same as 214 
222 is the same as 237 

我不知道這是爲什麼顯示,它應該打印該圖像1是相同的圖像3,至少是我想要它。

回答

0

您正在打印出整個圖像矩陣而不是圖像編號。嘗試:

fprintf('%g is the same as %g\n',i,j) 

想一下first_img是什麼,它是一個像素強度矩陣。所以你打印出所有的像素值。

0
fprintf('%g is the same as %g\n',first_img,second_img); 

在這裏,您傳遞兩個圖像作爲參數。您應該已經傳遞了圖片編號。

fprintf('%g is the same as %g\n', i, j);