Skip to main content

ImageGLCM

ImageGLCM [/Z /FREE /D=distance /E=structure /P=plane /HTFP /DEST=destGLCM /DETP=destParamWave] srcWave

The ImageGLCM operation calculates the gray-level co-occurrence matrix for an 8-bit grayscale image and optionally evaluates Haralick's texture parameters.

The ImageGLCM operation was added in Igor Pro 7.00.

Flags

/D=distanceSets the offset in pixels for which the co-occurrence matrix is calculated. The default value is 1.
/DEST=destGLCM
Specifies the wave to hold the co-occurrence matrix. If you omit /DEST the operation stores the matrix in the wave M_GLCM in the current data folder.
/DETP=destParamWave
Specifies the wave to hold the computed texture parameters. If you omit /DETP the operation stores the texture parameters in the wave W_TextureParams in the current data folder.
If the destination wave already exists it is overwritten. Note that you must specify the /HTFP flag to compute the texture parameters.
/E=structureBits
structureBits is a bitwise setting that lets you control the combination of co-occurrences that you want to compute.
Consider a wave displayed in a table and a pixel at position x
0351x6247\displaystyle \begin{array}{lll} 0 & 3 & 5 \\ 1 & x & 6 \\ 2 & 4 & 7 \end{array}
The structureBits corresponding to co-occurrence between x and any direction is simply 2^direction. By default the operation computes all combinations. This is equivalent to structureBits=255.
Note that the structureBits only define directions. The combination of the distance (/D) and the the structureBits define the full co-occurrence calculation.
See Setting Bit Parameters for details about bit settings.
/FREECreates output waves as free waves.
/FREE is permitted in user-defined functions only, not from the command line or in macros.
If you use /FREE then destGLCM and destParamWave must be simple names, not paths.
See Free Waves for details on free waves.
/HTFPComputes Haralick's texture parameters. See the discussion in the Details section below for more information about the texture parameters.
/P=planeIf the image consists of more than one plane you can use this flag to determine which plane in srcWave is analysed. By default it is plane zero.
/ZNo error reporting.

Details

ImageGLCM computes the co-occurrence matrix for the image in srcWave and optionally evaluates Haralick's texture parameters. The operation supports 8-bit grayscale images and generates a 256x256 single-precision floating point co-occurrence matrix.

The elements of the matrix P[i][j] are defined as the normalized number of pixels that have a spatial relationship defined by the distance (/D) and the structure (/E) such that the first pixel has gray-level i and the second pixel has gray-level j. The matrix is normalized so that the sum of all its elements is 1.

If you specify the /HTFP flag the operation computes the 13 Haralick texture parameters and stores them sequentially in the destination wave (see /DETP). The wave is saved with dimension labels defining each element. The expressions for the texture parameters are:

f1=ij(p[i][j])2,\displaystyle f_{1}=\sum_{i} \sum_{j}(p[i][j])^{2}, f2=n=0254n2{i=0255j=0ij=n255p[i][j]},\displaystyle f_{2}=\sum_{n=0}^{254} n^{2}\left\{\sum_{i=0}^{255} \sum_{\substack{j=0 \\\quad|i-j|=n}}^{255} p[i][j]\right\}, f3=ij(iμx)(jμy)p[i][j]σxσy,\displaystyle f_{3}=\sum_{i} \sum_{j} \frac{\left(i-\mu_{x}\right)\left(j-\mu_{y}\right) p[i][j]}{\sigma_{x} \sigma_{y}}, f4=ij(iμ)2p[i][j],\displaystyle f_{4}=\sum_{i} \sum_{j}(i-\mu)^{2} p[i][j], f5=ij11+(ij)2p[i][j],\displaystyle f_{5}=\sum_{i} \sum_{j} \frac{1}{1+(i-j)^{2}} p[i][j], f6=iipx+y(i),\displaystyle f_{6}=\sum_{i} i p_{x+y}(i), f7=i(if6)2px+y(i),\displaystyle f_{7}=\sum_{i}\left(i-f_{6}\right)^{2} p_{x+y}(i), f8=ipx+y(i)log(px+y(i)),\displaystyle f_{8}=-\sum_{i} p_{x+y}(i) \log \left(p_{x+y}(i)\right), f9=ijp[i][j]log(p[i][j]),\displaystyle f_{9}=-\sum_{i} \sum_{j} p[i][j] \log (p[i][j]), f10=Variance(pxy),\displaystyle f_{10}=\operatorname{Variance}\left(p_{x-y}\right), f11=ipxy(i)log(pxy(i)),\displaystyle f_{11}=\sum_{i} p_{x-y}(i) \log \left(p_{x-y}(i)\right), f12=f9HXY1max(HX,HY),\displaystyle f_{12}=\frac{f_{9}-H X Y 1}{\max (H X, H Y)}, f13=1exp(2(HXY2f9)).\displaystyle f_{13}=\sqrt{1-\exp (-2(H X Y 2-f 9))} .

Here

px(i)=jp[i][j],py(j)=ip[i][j],\displaystyle p_{x}(i)=\sum_{j} p[i][j], \quad p_{y}(j)=\sum_{i} p[i][j], μx=iipx(i),μy=iipy(i),μ=(μx+μy)/2.\displaystyle \mu_{x}=\sum_{i} i p_{x}(i), \quad \mu_{y}=\sum_{i} i p_{y}(i), \quad \mu=\left(\mu_{x}+\mu_{y}\right) / 2 . σx=i(1μx)2px(i),σy=i(1μy)2py(i),\displaystyle \sigma_{x}=\sqrt{\sum_{i}\left(1-\mu_{x}\right)^{2} p_{x}(i)}, \quad \sigma_{y}=\sqrt{\sum_{i}\left(1-\mu_{y}\right)^{2} p_{y}(i)}, px+y(k)=iji+j=kp[i][j],\displaystyle p_{x+y}(k)=\sum_{i} \sum_{\substack{j \\ \quad i+j=k}} p[i][j], pxy(k)=ijij=kp[i][j],\displaystyle p_{x-y}(k)=\sum_{i} \sum_{\substack{j \\\quad \quad |i-j|=k}} p[i][j], HXY1=ijp[i][j]log(px(i)py(j)),\displaystyle H X Y 1=-\sum_{i} \sum_{j} p[i][j] \log \left(p_{x}(i) p_{y}(j)\right), HXY2=ijpx(i)py(j)log(px(i)py(j)),\displaystyle H X Y 2=-\sum_{i} \sum_{j} p_{x}(i) p_{y}(j) \log \left(p_{x}(i) p_{y}(j)\right), HX=ipx(i)log(px(i)),HY=ipy(i)log(py(i)).\displaystyle H X=-\sum_{i} p_{x}(i) \log \left(p_{x}(i)\right), \quad H Y=-\sum_{i} p_{y}(i) \log \left(p_{y}(i)\right) .

There are at least two versions of f7 used in the literature and in software. We know of at least three versions of f14 so ImageGLCM does not compute it.

References

R.M. Haralick, K. Shanmugam and Itshak Dinstein, "Textural Features for Image Classification", IEEE Transactions on Systems, Man, and Cybernetics, 1973.