I have a question about the co-occurrence formula. How can I implement in Java the calculation of the GLCM of an image?
Concretely, I'm trying to figure out how to compute the number of times a pixel has intensity x
and the pixel at its immediate right has intensity y
. I also need to store the obtained value in the x
-th row and y
-th column of the resulting co-occurrence matrix.
The expected behavior is shown below:
Here's what I got so far:
CODE (NOT complete yet)
public class MainClass {
final static int[][] matrix= {
{2,4,1,3},
{7,2,1,6},
{1,1,2,2},
{1,2,5,8}
};
static int i;
static int j;
static int x;
static int y;
static int c;
static int d;
static int maxValue = matrix[0][0];
static int minValue = matrix[0][0];
public static void main(String[] args) {
// TODO Auto-generated method stub
for(i = 0; i< matrix.length; i++) {
for(j=0; j < matrix[i].length; j++) {
System.out.print(matrix[i][j] + "");
if(matrix[i][j] > maxValue) {
maxValue=matrix[i][j];
}
else if(matrix[i][j] < minValue) {
minValue=matrix[i][j];
}
}
System.out.println();
}
System.out.println("maxValue = "+ maxValue);
int count = 0;
for(int i=0; i< matrix.length; i++) {
for (int j=0; j<matrix[i].length; j++) {
int x = i;
int y = j;
if(matrix[x][y] == 1 & matrix[x][y+1] ==1) {
count ++;
}
System.out.println(matrix[x][y+1]);
}
}
}
OUTPUT (ERROR)
2413
7216
1122
1258
maxValue = 8
4
1
3
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at main.MainClass.main(MainClass.java:45)
I would prefer not to use third-party libraries such as OpenCV or jfeaturelib.