# How to calculate the value of the glcm feature?

My code just arrived at matrix normalization, how to calculate the value of glcm features such as entropy, energy, contrast, correlation, and homogeneity. Here is the code

private void Classification() {

Mat gl = Mat.zeros(256, 256, CvType.CV_64F);
Mat glt = gl.clone();

//Create GLCM d= 1 , angle = 0
for (int y = 0; y < finalResult.rows(); y++) {
for (int x = 0; x < finalResult.cols()-1; x++) {

int i = (int) finalResult.get(y, x);
int j = (int) finalResult.get(y, x + 1);

double[] count = gl.get(i, j);
count++;
gl.put(i, j, count);
}
}

//GLCM Transpose
Core.transpose(gl, glt);

//Symmetric Matrix

//Matrix Normalization
Scalar sum = Core.sumElems(gl);
Core.divide(gl, sum, gl);

edit retag close merge delete

Sort by » oldest newest most voted

if you look e.g. here, we got: Mat squared;
Core.multiply(gl, gl, squared);
Scalar sum = Core.sumElems(squared);
double energy = sum.val; Mat ln;
Core.log(gl, ln);
Mat squared;
Core.multiply(ln, gl, squared, -1);
Scalar sum = Core.sumElems(squared);
double entropy = sum.val;


... and so on ...

more

1

Sorry before, the above code still occurs error. The error is "Cannot resolve metode sum"

1

apologies, you're right, it should have been sumElems in java.

thank you, the code above works fine. Then how to calculate contrast, correlation, homogeneity? how do you get the value from each pixel?

Official site

GitHub

Wiki

Documentation