Why is the difference of my two images blank?

Issue

I tried to get the difference of two images. Here are my two images.

enter image description here

enter image description here

However, I only got a blank image like this

enter image description here

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.

Solution

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:

enter image description here

Min and Max Values In Diff:
0 91

Answered By – fmw42

Answer Checked By – Jay B. (AngularFixing Admin)

Leave a Reply

Your email address will not be published.