Если вы знакомы с python, это довольно просто.
import numpy as np
img1 = #first grayscale image
img2 = #second grayscale image
diff = np.abs(img1.astype(np.uint) - img2.astype(np.uint)).astype(np.uint8)
#diff has the required difference data
#here is the code to save an image (simply chage the extension at "filename.***" to save in the required format)
cv2.imwrite("filename.jpg",diff)