我从 GitHub获得了以下代码片段,用于通过 OpenCV 计算灰度共现矩阵 (GLCM):
float energy=0,contrast=0,homogenity=0,IDM=0,entropy=0,mean1=0;
int row=img.rows,col=img.cols;
Mat gl=Mat::zeros(256,256,CV_32FC1);
//creating glcm matrix with 256 levels,radius=1 and in the horizontal direction
for(int i=0;i<row;i++)
for(int j=0;j<col-1;j++)
gl.at<float>(img.at<uchar>(i,j),img.at<uchar>(i,j+1))=gl.at<float>(img.at<uchar>(i,j),img.at<uchar>(i,j+1))+1;
// normalizing glcm matrix for parameter determination
gl=gl+gl.t();
gl=gl/sum(gl)[0];
上面的代码是用 C++ 编写的。我需要将其转换为 Java,但我被困在这一行:
gl.at<float>(img.at<uchar>(i,j),img.at<uchar>(i,j+1))=gl.at<float>(img.at<uchar>(i,j),img.at<uchar>(i,j+1))+1;
有人可以帮我解决这个问题吗?