Skip to content

Add function to compare images #6478

@Yay295

Description

@Yay295

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions