protected static float A_safe ( int x , int y , GrayF32 flow ) { float u0 = safe ( x - 1 , y , flow ) ; float u1 = safe ( x + 1 , y , flow ) ; float u2 = safe ( x , y - 1 , flow ) ; float u3 = safe ( x , y + 1 , flow ) ; float u4 = safe ( x - 1 , y - 1 , flow ) ; float u5 = safe ( x + 1 , y - 1 , flow ) ; float u6 = safe ( x - 1 , y + 1 , flow ) ; float u7 = safe ( x + 1 , y + 1 , flow ) ; return ( 1.0f / 6.0f ) * ( u0 + u1 + u2 + u3 ) + ( 1.0f / 12.0f ) * ( u4 + u5 + u6 + u7 ) ; }
See equation 25 . Safe version