Fixed typo with indexes in getGradient(x/y) functions.

Fixed error with out of bound index. Replaced this function with filter2D equivalent..