public static < T extends ImageGray < T > > void naiveGradient ( T ii , double tl_x , double tl_y , double samplePeriod , int regionSize , double kernelSize , boolean useHaar , double [ ] derivX , double derivY [ ] ) { SparseScaleGradient < T , ? > gg = SurfDescribeOps . createGradient ( useHaar , ( Class < T > ) ii . getClass ( ) ) ; gg . setWidth ( kernelSize ) ; gg . setImage ( ii ) ; SparseGradientSafe g = new SparseGradientSafe ( gg ) ; // add 0.5 to c_x and c_y to have it round when converted to an integer pixel // this is faster than the straight forward method tl_x += 0.5 ; tl_y += 0.5 ; int i = 0 ; for ( int y = 0 ; y < regionSize ; y ++ ) { for ( int x = 0 ; x < regionSize ; x ++ , i ++ ) { int xx = ( int ) ( tl_x + x * samplePeriod ) ; int yy = ( int ) ( tl_y + y * samplePeriod ) ; GradientValue deriv = g . compute ( xx , yy ) ; derivX [ i ] = deriv . getX ( ) ; derivY [ i ] = deriv . getY ( ) ; // System.out.printf("%2d %2d %2d %2d dx = %6.2f dy = %6.2f\n",x,y,xx,yy,derivX[i],derivY[i]); } } }
Simple algorithm for computing the gradient of a region . Can handle image borders