Ask Your Question
0

How to calculate the value of the glcm feature?

asked 2019-11-25 20:39:13 -0600

Fandi gravatar image

updated 2019-11-26 01:25:14 -0600

berak gravatar image

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)[0];
            int j = (int) finalResult.get(y, x + 1)[0];

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

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

    //Symmetric Matrix
    Core.add(gl, glt, gl);

    //Matrix Normalization
    Scalar sum = Core.sumElems(gl);
    Core.divide(gl, sum, gl);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-11-27 05:55:01 -0600

berak gravatar image

updated 2019-12-08 07:24:50 -0600

if you look e.g. here, we got:

image description

Mat squared; 
Core.multiply(gl, gl, squared);
Scalar sum = Core.sumElems(squared);
double energy = sum.val[0];

image description

Mat ln; 
Core.log(gl, ln);
Mat squared; 
Core.multiply(ln, gl, squared, -1);
Scalar sum = Core.sumElems(squared);
double entropy = sum.val[0];

... and so on ...

edit flag offensive delete link more

Comments

Thanks for helping

Fandi gravatar imageFandi ( 2019-11-28 01:25:33 -0600 )edit
1

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

Fandi gravatar imageFandi ( 2019-12-08 06:33:41 -0600 )edit
1

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

please take a look at the corrected answer ;)

berak gravatar imageberak ( 2019-12-08 07:24:01 -0600 )edit

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

Fandi gravatar imageFandi ( 2019-12-09 03:54:45 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-11-25 20:39:13 -0600

Seen: 510 times

Last updated: Dec 08 '19