Skip to content

Instantly share code, notes, and snippets.

@aleksas
Created April 5, 2019 13:46
Show Gist options
  • Save aleksas/9bceae94e197345b02c2e24f325a5130 to your computer and use it in GitHub Desktop.
Save aleksas/9bceae94e197345b02c2e24f325a5130 to your computer and use it in GitHub Desktop.
Python script to output image of difference between two images
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)
opencv-python
numpy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment