Codes for computing X and Y gradient images