How to convert C++ implementation of GLCM into Java?

你离开我真会死。 提交于 2019-12-04 23:32:20

The calculation of a 256x256 symmetric gray level co-occurrence matrix of image img (of class Mat) corresponding to an offset "one pixel to the right" may be implemented in Java through OpenCV as follows:

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

for (int y = 0; y < img.rows(); y++) {
    for (int x = 0; x < img.cols()-1; x++) {

        int i = (int) img.get(y, x)[0];
        int j = (int) img.get(y, x + 1)[0];

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

Core.transpose(gl, glt);
Core.add(gl, glt, gl);
Scalar sum = Core.sumElems(gl);
Core.divide(gl, sum, gl);

There is a good bunch of publicly available libraries to compute GLCMs and extract Haralick features from them in Java, for example GLCM2, JFeatureLib, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!