Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to compare images #6478

Open
Yay295 opened this issue Aug 4, 2022 · 0 comments
Open

Add function to compare images #6478

Yay295 opened this issue Aug 4, 2022 · 0 comments

Comments

@Yay295
Copy link

@Yay295 Yay295 commented Aug 4, 2022

I think it would be useful to have a function to check if two images are the same. I don't mean with a perceptual hash like #3120, or with the existing Image.__eq__ method, but something to check if two images are visually similar. By that I mean the images are the same size and have the same color pixels, after taking into account the EXIF Orientation tag and the images possibly having different modes. Something like

def same_image(img_a,img_b):
	img_a = ImageOps.exif_transpose(img_a)
	img_b = ImageOps.exif_transpose(img_b)
	if img_a.size != img_b.size:
		return False
	img_a = img_a.convert('RGBA')
	img_b = img_b.convert('RGBA')
	diff = ImageChops.difference(img_a,img_b)
	return diff.getbbox() is None and diff.convert('RGB').getbbox() is None

but more efficient. And also it needs to handle images with multiple frames. Or maybe just throw an exception for those for now.

@radarhere radarhere changed the title Add Function to Compare Images Add function to compare images Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants