python-3.ximage-comparison

Image Comparison with a updating comparison image (PIL)


I need to compare the 1st image from a folder, deleting duplicates, until it finds one that doesn't match. Then it compares the new image with the rest of the picture, repeating the first process. I don't know if I'm forgetting something obvious but how to I set the new image as the comparison. Below is my first attempt at it, the idea that first_image for im1 would be updated after the loop. Any advice would be appreciated.

def add():
    for image in files:
        im1 = Image.open(path+ "/"+first_image).histogram() #the image to be compared too
        im = Image.open(path+ "/" +image).histogram() #the image to be compared
    if im == im1:
        os.rename(path + "/" + file, path + "/delete")
    else: 
        os.rename(path + "/" + file, path + "/save") ```

Solution

  • The answer was so simple, was overthinking it a lot. just defined the image before the for loop then have the for loop update it as necessary