www.pudn.com > duge.rar > ave_grad.m, change:2015-06-01,size:838b


function [ value ] = ave_grad( I ) 
%AVE_GRAD Summary of this function goes here 
%   清晰度,也称平均梯度,值越大表明图像越清晰 
 
 
    [M,N,color]=size(I); 
    if color==3 
        I=double(rgb2gray(I)); 
    else 
        I=double(I); 
    end 
    gradval=zeros(M,N); %%% save the gradient value of single pixel 
    diffX=zeros(M,N); %%% save the differential value of X orient 
    diffY=zeros(M,N); %%% save the differential value of Y orient 
    tempX=zeros(M,N); 
    tempY=zeros(M,N); 
    tempX(1:M,1:(N-1))=I(1:M,2:N); 
    tempY(1:(M-1),1:N)=I(2:M,1:N); 
    diffX=tempX-I; 
    diffY=tempY-I; 
    diffX(1:M,N)=0; %%% the boundery set to 0 
    diffY(M,1:N)=0; 
    diffX=diffX.*diffX; 
    diffY=diffY.*diffY; 
    AVEGRAD=(diffX+diffY)/2; 
    AVEGRAD=sum(sum(sqrt(AVEGRAD))); 
    value=AVEGRAD/((M-1)*(N-1)); 
end