Hello everyone! I have a program that allows you to do 4 things by typing in the corresponding letter for each: (r) read a .pgm file, (S) smooth the file, (E) use edge detection on the file, (s) save the file, or (q) quit the program. In this program, I just had to fill in the code for saving a file (done) and writing the edge detection. Here's the code I have so far for the sobel operator:
case 'E': boolean[][] bo = Sobel(pictureArray, 3); for(int i = 0; i<height; i++) { for(int j = 0; i<width; j++) { if(bo[i][j] ==true) { System.out.print("(" + i + "," + j + ") "); } } } break; public static boolean[][] Sobel(int[][] pictureArray, int threshold) { threshold=3; int c = 1; double Gx=0, Gy=0, G; boolean[][] b = new boolean[width][height]; int[][] array = new int[3][3]; int[][] sobel = {{-1,-2,-1},{0,0,0},{1,2,1}}; for(int i=0; i<height; i++) { for(int j=0; j<width; j++) { for (int k=0; k<3; k++) { for (int l=0; l<3; l++) { Gx += (sobel[k][l] * pictureArray[B][i][j][/B]); Gy += (sobel[l][k] * pictureArray[I][k][l][/I]); } } G = Math.sqrt(Math.pow(Gx,2)+Math.pow(Gy,2)); if (G > threshold) { b[i][j] = true; } else { b[i][j] = false; } } } return b; }
The italicized and bold sections of code you see is where my professor said I was wrong. I get an ArrayOutOfBounds Exception and I'm not sure how to fix it. Can anyone help with this?