2012-01-20 9 views
0

私はMatlabの2つの画像を比較したいと思います(私は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 

は、2枚の画像のヒストグラムは、このように計算される:

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