Skip to content

Instantly share code, notes, and snippets.

@navin-mohan
Created August 9, 2016 15:38
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navin-mohan/efbe081b2bde5662cc1e76db0e12289e to your computer and use it in GitHub Desktop.
Save navin-mohan/efbe081b2bde5662cc1e76db0e12289e to your computer and use it in GitHub Desktop.
Subtracting Two Images - OpenCV Python
import cv2
def diff(img,img1): # returns just the difference of the two images
return cv2.absdiff(img,img1)
def diff_remove_bg(img0,img,img1): # removes the background but requires three images
d1 = diff(img0,img)
d2 = diff(img,img1)
return cv2.bitwise_and(d1,d2)
@muralisb
Copy link

Can you please explain why 3 images are used and what are those images?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment