I have many images in a folder and I am want to delete images of the same size. My code below, using PIL, works but I want to know if there is a more efficient way to achieve this.
import os
from PIL import Image
def checkImages(dirs):
image_list = os.listdir(dirs)
for i in range(len(image_list)):
for j in range(i + 1, len(image_list)):
im_a = Image.open(dirs + '/' + image_list[i])
im_b = Image.open(dirs + '/' + image_list[j])
if im_a.size == im_b.size:
os.remove(dirs + '/' + image_list[j])
del image_list[j]
checkImages('/content/gdrive/MyDrive/testdata')