Search code examples
imagematlabimage-processingfeature-extractionentropy

How to calculate the energy and correlation of an image


Could anyone help me how to calculate the energy and correlation of an image using MATLAB?


Solution

  • I think you are looking for graycomatrix and graycoprops. From the graycoprops documentation, two properties that can be computed:

    'Correlation'   statistical measure of how correlated a pixel is to its 
                    neighbor over the whole image. Range = [-1 1]. 
                    Correlation is 1 or -1 for a perfectly positively or
                    negatively correlated image. Correlation is NaN for a 
                    constant image.
    
    'Energy'        summation of squared elements in the GLCM. Range = [0 1].
                    Energy is 1 for a constant image.
    

    To compute these properties, first compute the graylevel co-occurrence matrix via graycomatrix, then call graycoprops. For example,

    I = imread('circuit.tif');
    GLCM = graycomatrix(I,'Offset',[2 0;0 2]);
    stats = graycoprops(GLCM,{'correlation','energy'})
    

    You just need to decide on the Offset parameter for graycomatrix. A thorough choice would be offset = [0 1; -1 1; -1 0; -1 -1];


    To compute entropy for the GLCMs, you can't use graycoprops, so you'll have to do it yourself:

    p = bsxfun(@rdivide,GLCM,sum(sum(GLCM,1),2)); % normalize each GLCM to probs
    
    numGLCMs = size(p,3);
    entropyVals = zeros(1,numGLCMs);
    for ii=1:numGLCMs,
        pi = p(:,:,ii);
        entropyVals(ii) = -sum(pi(pi>0).*log(pi(pi>0)));
    end