I have two images and would like to make it obvious where the differences are. I want to add color to the two images such that a user can clearly spot all the differences within a second or two.
For example, here are two images with a few differences:
leftImage.jpg:
rightImage.jpg:
My current approach to make the differences obvious, is to create a mask (difference between the two images), color it red, and then add it to the images. The goal is to clearly mark all differences with a strong red color. Here is my current code:
import cv2
# load images
image1 = cv2.imread("leftImage.jpg")
image2 = cv2.imread("rightImage.jpg")
# compute difference
difference = cv2.subtract(image1, image2)
# try to color the mask red
Conv_hsv_Gray = cv2.cvtColor(difference, cv2.COLOR_BGR2GRAY)
ret, mask = cv2.threshold(Conv_hsv_Gray, 0, 255,cv2.THRESH_BINARY_INV |cv2.THRESH_OTSU)
difference[mask != 255] = [0, 0, 255]
# try to add the red mask to the images to make the differences obvious
diffOverImage1 = image1 + difference
diffOverImage2 = image2 + difference
# store images
cv2.imwrite('diffOverImage1.png', diffOverImage1)
cv2.imwrite('diffOverImage2.png', diffOverImage2)
cv2.imwrite('diff.png', difference)
Problem with the current code: The computed mask shows some differences but also contains irrelevant noise. When I add the mask to the image, the differences are not shown in red. How do I remove the irrelevant noise and clearly highlight all the differences in a strong red color?
diff.png:
diffOverImage1.png
diffOverImage2.png