java - Sobel Operator not working -
i've been spending last 2 hours on , didn't realize problem is, me out?
public static void sobel(img img) { int[][][] myarray = img.getmyarray(); int[][][] sobelx = img.copymyarray(); int[][][] sobely = img.copymyarray(); //itearates through matrix apply sobel operator (int line = 1; line < myarray.length -2; line++) (int column = 1; column < myarray[line].length -2; column++) for(int color = 0; color < 3; color++){ sobelx[line][column][color] = -1 * myarray[line-1][column-1][color] + -2 * myarray[line-1][column][color] + -1 * myarray[line-1][column+1][color] + 0 * myarray[line][column-1][color] + 0 * myarray[line][column][color] + 0 * myarray[line][column+1][color] + 1 * myarray[line+1][column-1][color] + 2 * myarray[line+1][column][color] + 1 * myarray[line+1][column+1][color]; sobely[line][column][color] = -1 * myarray[line-1][column-1][color] + 0 * myarray[line-1][column][color] + 1 * myarray[line-1][column+1][color] + -2 * myarray[line][column-1][color] + 0 * myarray[line][column][color] + 2 * myarray[line][column+1][color] + -1 * myarray[line+1][column-1][color] + 0 * myarray[line+1][column][color] + 1 * myarray[line+1][column+1][color]; //final calculation myarray[line][column][color] = check_0_255_limit((int)math.sqrt( sobelx[line][column][color] * sobelx[line][column][color] + sobely[line][column][color] * sobely[line][column][color] )); }// end loop }
no error messages, code compiling , running, i'm getting bad output, not expected..
you calculating gradients each channel independently; need to, output isn't in colour? output of operator, given 0..255 channel value inputs, -1020..1020 need scale before or after getting magnitude sqrt, 0..255 range.
but main problem "final calculation" output overwrites array looping on (i.e. filter reprocessing already-processed values) put in own array. gives cool dithering effect!
Comments
Post a Comment