2012-01-20 2 views
0

Matlab에서 두 이미지를 비교하고 싶습니다. (이미지 비교 및 ​​처리를위한 더 많은 기능이 있다는 것을 배웠습니다). 누구나 똑같이하기위한 좋은 방법과 간단한 방법을 제안 할 수 있습니까? 그리고 이미지는 정확히 동일해야합니다. 따라서 이미지의 밝기와 위치를 고려할 필요가 없습니다.Matlab을 사용한 이미지 비교

아무리 좋은 알고리즘이나 방법으로 도움이된다면 2 달 안에 프로젝트를 완료해야합니다.

답변

2

이미지를 MATLAB에로드하면 매트릭스로 저장됩니다. 행렬을 비교하는 데 사용할 수있는 모든 것이 이미지를 비교할 수 있습니다 (예 : ISEQUAL). 그러나 이미지 처리의 의미에서 이미지를 더 비교하고 싶다면 Image Processing Toolbox의 데모를보고 here (해당되는 경우)의 "비교"정의에 맞는 데모가 있는지 확인하십시오.

+2

깨진 링크. 고쳐주세요. –

2
a = imread('image1.jpg'); %reading images as array to variable 'a' & 'b'. 
    b = imread('image2.jpg'); 
    c = corr2(a,b);   %finding the correlation btwn two images 
    if c==1 
    disp('The images are same')%output display 
    else 
    disp('the images are not same') 
    end; 
1

이미지가 정확히 같아야합니까?

a = imread('image1.jpg'); 
b = imread('image2.jpg'); 
result = all(size(a) == size(b)); 
if result 
    result = all(reshape(a,[],1)== reshape(b,[],1)); 
end 
3

EMD 알고리즘을 사용할 수 있습니다. 히스토그램에서 작동합니다. 계산

function[d] = hcompare_EMD(h1,h2) 
% This function calculates Earth Movers Distance between two normalized 
% histograms h1 and h2. Normalized histogram is histogram h, that has at 
% each i place in it, value: 
% (number of picture pixels with gray level i-1)/
% (total num of pixels in picture). 


% ALternative fast way: 
d = sum(abs(cumsum(h1) - cumsum(h2))); 
end 

두 이미지에 대한 히스토그램이 방법 :

function[h] = histImage(img) 
% This function calculates normalized histogram of image. 
% Normalized histogram is histogram h, that has at 
% each i place in it, value: 
% (number of picture pixels with gray level i-1)/
% (total num of pixels in picture). 
sum = 0; 
[y,x] = size(img); % getting sizes of image 
h = zeros(1,256); % creating output histogram array 
for i = 1:1: y  % runing on rows 
    for j = 1:1: x % running on colomns 
     % gray level is addtess to cell in output histogram array 
     % we add there 1 (bacause of current pixel (y,x) has this gray level 
     h(img(i,j)) = h(img(i,j)) + 1; 
     % pay attention to fact, that we use here pixel value as index! 
    end 
end 

h = h./(y*x); 
end 

두 이미지의 히스토그램 (histArray, histPattern) 사이의 거리를 계산하기 위해 여기시킬 수있는 몇몇 코드는 :

function[dmap] = patDistMAp(histArray, histPattern) 
% Given histograms of an image and pattern returns an array (image) 
% of distance values between 
% img windows and pattern. Distance values are computed between the histograms 
% of the windows and the pattern using the histogram distance function 

[y,x,z] = size(histArray); 
dmap = zeros(y,x);     % output array 

for i = 1:1: y  % runing on rows 
    for j = 1:1: x % running on colomns 
     hist = histArray(i,j,:); 
%   for k = 1:1:256    % making array 1x256 from 1x1x256 
%    h1(k) = hist(1,1,k); % there is a permute function, 
%   end       % but we will use it next time) 
     h1 = permute(squeeze(hist),[2,1]); 
     % Using temp variable, as MATLAB7 wants it: 
     temp = hcompare_EMD(histPattern,h1); 
     dmap(i,j) = temp; 
    end 
end 

end