I tried to get the difference of two images. Here are my two images.
However, I only got a blank image like this
I use OpenCV package in python. The code I use is:
image3 = image1 - image2
plt.imshow(image3)
plt.show()
The backgrounds of the two images are not the same. I don't understand why the difference of the two images is just blank. Can someone help me with this?
Thank you in advance.
CodePudding user response:
This works fine for me in Python/OpenCV using cv2.absdiff(). I suggest you use cv2.imshow() to view your results and cv2.imwrite() to save your results.
import cv2
import numpy as np
image1 = cv2.imread('image1.png')
image2 = cv2.imread('image2.png')
diff = cv2.absdiff(image1, image2)
print(np.amin(diff), np.amax(diff))
cv2.imwrite('diff.png', diff)
cv2.imshow('diff', diff)
cv2.waitKey(0)
Result:
Min and Max Values In Diff:
0 91