Created
April 5, 2019 13:46
-
-
Save aleksas/9bceae94e197345b02c2e24f325a5130 to your computer and use it in GitHub Desktop.
Python script to output image of difference between two images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
img0 = cv2.imread(r'in1.jpg', 0) | |
img1 = cv2.imread(r'in2.jpg', 0) | |
np_subtr = np.subtract(img0, img1) | |
np_mean = np.mean(np_subtr) | |
np_double_mean = np.mean(np_subtr) | |
np_half_mean = np_mean / 2 | |
np_subtr[np_subtr < np_half_mean] = 0 | |
np_subtr[np_subtr > np_double_mean] = 0 | |
cv2.imwrite(r'out.png', np_subtr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
opencv-python | |
numpy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment