First, you need to define what you mean by the "difference between 2 images". It is important to notice that cv2.subtract
performs saturation, which means that, if you images are in e.g. np.uint8
, all negative values will be clipped to 0 (see more details in this answer). Maybe that's not what you want. But let's say it is what you want. Then, you can do what @Tilman said in the comments (you need to subtract the min too, see below). If you do not understand why, more details can be seen in this answer. Basically, your code would be like this (I did it step-by-step so that you could understand):
import cv2
img1 = cv2.imread("lko.png")
img2 = cv2.imread("jum.png")
diff = cv2.subtract(img1, img2) # range [a, b]
diff = diff - np.min(diff) # range [0, b-a]
diff /= np.max(diff) # range [0, 1]
diff *= 255 # range [0, 255]