www.pudn.com > fusion-evaluation.rar > AverageGradent.m, change:2011-05-23,size:422b


%ƽݶ 
clear all 
[filename,pathname]=uigetfile('*.*','ͼ'); 
A=imread([pathname,filename]); 
%s=size(size(A)); 
 
%if s(2)==3 
%    A=rgb2gray(A); 
%end 
A=double(A); 
[M,N,K]=size(A); 
sum=0; 
 
for i=1:M-1 
    for j=1:N-1 
        diffX(i,j)=A(i,j)-A(i+1,j); 
        diffY(i,j)=A(i,j)-A(i,j+1); 
        w=sqrt(((diffX(i,j))^2+(diffY(i,j))^2)/2); 
        sum=sum+w; 
    end 
end 
AVEGRAD=sum/((M-1)*(N-1))