Adjacent Gray Level Dependency Matrix (NGLDM) in MATLAB

I would like to calculate a couple of texture features (namely: small / large accent, the number of unevenness, the second moment and entropy). They can be calculated from the adjacent gray level dependency matrix. I am struggling with understanding / implementing this. There is very little information about this method (publicly available).

According to this document :

This matrix takes the form of a two-dimensional array Q, where Q (i, j) can be considered as the frequency numbers of the grayness of the processed image. It has a similar meaning as a histogram of an image. This array is N g × N r , where N g is the number of possible gray levels, and N r is the number of possible neighbors to a pixel in the image.

If the image function f (i, j) is discrete, then it is easy to calculate the Q-matrix (for a positive integer d, a) by calculating the number of times the difference between each element in f (i, j), and its neighbors are equal to or less than a by some distance d.

Here is an example from the same work (d = 1, a = 0):

Input matrix (images) and output matrix Q:

Input (image) matrixenter image description here

, Q-. -?

C. Sun W. Wee : , , ( ).

+3
1

, , d=1 a=0. d=1, 8- . a=0, , , , .

:

  • NGLDM . / . 1. d=1, 8- 8 + 1 = 9. 4 (0,1,2,3), , 4 × 9. M.
  • . Ng.
  • , .
  • , , # 1. Nr.
  • # 1 2, 1.

: . , , , . , , 8- . d=1. , d=1. d=2, , 25- ..

, . :

  • Ng = 1, 1.
  • . , : 1, 1, 2, 0, 1, 0, 2, 2.
  • 1? . Nr = 3
  • M(Ng,Nr) += 1. Ng = 1 Nr = 3, 1.

, , ? . 0, Ng = 0. , , Ng = 0, Nr = 1, ... ! , , , ... . . , Ng = 1 Nr = 1, .


. M(Ng,Nr) = 4, Ng = 2, Nr = 4? , 2. , 8- , row=2, col=4, row=3, col=3, row=3, col=4, row=4, col=3 row=4, col=4. , , , Nr = 4. , Ng = 2, Nr = 4 , 4. row=3, col=4 Nr = 5, 2s . Ng = 2, Nr = 5, M(Ng,Nr) = 1.

. 2 smack dab (row=3, col=3):

  • Ng = 2
  • ? 1, 1, 2, 0, 2, 3, 2, 2 ( )
  • , 2. , Nr = 4
  • M(Ng,Nr) += 1. Ng = 2, Nr = 4 1.

2, , Nr = 4 , ​​ , Nr = 5.


, MATLAB? im2col, . , , - . . , , , Nr. Ng . , , . , :

% // Your example
A = [1 1 2 3 1; 0 1 1 2 2; 0 0 2 2 1; 3 3 2 2 1; 0 0 2 0 1];
B = im2col(A, [3 3]); %//Convert neighbourhoods to columns - 3 x 3 means d = 1
C = bsxfun(@eq, B, B(5,:)); %//Figure out a logical matrix where each column tells
                            %//you how many elements equals the one in each centre
D = sum(C, 1) - 1; %// Must subtract by 1 to discount centre pixel
Ng = B(5,:).' + 1; % // We must make this into a column vector, and we also must
                   % // offset by 1 as MATLAB starts indexing by 1.
                   %// Column vector is for accumarray input
Nr = D.' + 1; %// Do the same for Nr.  We could have simply left out the + 1 here and
              %// took out the subtraction of -1 for D, but I want to explicitly show
              %// the steps
Q = accumarray([Ng Nr], 1, [4 9]); %// 4 unique intensities, 9 possible locations (0-8)

... :

Q =

 0     0     1     0     0     0     0     0     0
 0     0     1     1     0     0     0     0     0
 0     0     0     0     4     1     0     0     0
 0     1     0     0     0     0     0     0     0

, , Q.


Bonus

, , d a, . . , <= a d. , 2*d + 1 x 2*d + 1, . . :

%// Set A up yourself, then use a and d as inputs
%// Precondition - a and d are both integers. a can be 0 and d is positive!
function [Q] = calculateGrayDepMatrix(A, a, d)
    neigh = 2*d + 1; % //Calculate rows/columns of neighbourhood
    numTotalNeigh = neigh*neigh; % //Calculate total number of pixels in neighbourhood
    middleRow = ceil(numTotalNeigh / 2); %// Figure out which index the middle row is
    B = im2col(A, [neigh neigh]);  %// Make into columns
    Cdiff = abs(bsxfun(@minus, B, B(middleRow,:))); %// For each neighbourhood, subtract with its centre
    C = Cdiff <= a; %// For each neighbourhood, figure out which differences are <= a
    D = sum(C, 1) - 1; % //For each neighbourhood, add them up
    Ng = B(middleRow,:).' + 1; % // Determine Ng and Nr, and find Q
    Nr = D.' + 1; 
    Q = accumarray([Ng Nr], 1, [max(Ng) numTotalNeigh]); 
end

, , :

A = [1 1 2 3 1; 0 1 1 2 2; 0 0 2 2 1; 3 3 2 2 1; 0 0 2 0 1];
Q = calculateGrayDepMatrix(A, 0, 1);

Q:

Q =

 0     0     1     0     0     0     0     0     0
 0     0     1     1     0     0     0     0     0
 0     0     0     0     4     1     0     0     0
 0     1     0     0     0     0     0     0     0

, !

+4

All Articles