python判断图片长宽后删除数据集中的小图片

import os
from PIL import Image
path = r'C:\study_he\Nestle45'#数据集的地址
for root, dirs, files in os.walk(path):
    for name in files:
        fileName =os.path.join(root, name)
        fp = open(fileName, 'rb')
        im = Image.open(fp)
        fp.close()
        x, y = im.size
        if x < 60 or y < 60:#判断长宽所设的阈值
            os.remove(fileName)
        print("Delete File: " + os.path.join(root, name))

你可能感兴趣的:(python)