'Check if pictures are similar in Python

I'm facing the following problem: I have N pictures (300x300pixels, anchor is always top left). Of these N pictures, some are are the same, just mirrored and/or rotated.

Part one

Part two, similar to one

Part 3, not similar to any of the others

As you see, the first 2 parts are nearly the same, just mirrored, while part 3 is completely different.

def compare_Image(sourceIMGPath, compareIMGPath):
    sourceIMG = Image.open(sourceIMGPath, "r")
    compareIMG = Image.open(compareIMGPath, "r")
    for rotation in [0, 1]:
        if rotation == 1: compareIMG = ImageOps.mirror(compareIMG)
        for angle in [0, 90, 180, 270]:
            compareIMG = compareIMG.rotate(angle)
            imgDiff =ImageChops.difference(sourceIMG, compareIMG)                         
            if not imgDiff.getbbox():
                compareIMG.show()
                sourceIMG.show()
                print(str(Path(sourceIMGPath).stem) + " " + str(Path(compareIMGPath).stem))
                return True
    return False

I tried to mirror and rotate the picture, but surely this doesn't work, since the picture will move to the side/bottom of the picture which will move the anchor and so the picture will never be the same.

So I need to find a way, in which I maybe can reset the anchor or something similar. Maybe someone has an idea.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source