fixed getting gradient of pixels in edge cases