Gradient function consistent with Canny

needs to be cleaned up a lot.