You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import os
from PIL import Image , ImageFile
# ImageFile.LOAD_TRUNCATED_IMAGES = True #如果图片太大报错可以使用这个
def pixel ( ) :
b = 0
dir = r ' C: \ Users \ xinluo \ PycharmProjects \ pythonProject \ Camera Roll ' # 需要处理的图片目录
files = os . listdir ( dir ) # 得到需要处理的所有图片
files . sort ( ) # 对图片进行排序
for each_bmp in files : # 遍历图片,进行筛选
each_bmp_root = os . path . join ( dir , each_bmp ) # 得到每个图片路径
image = Image . open ( each_bmp_root ) # 打开每个图片
img = image . convert ( ' RGB ' ) # 转化成RGB, 其实图片大多都是RGB, 即使灰度图也不一定转RGB, 看需求
width = img . size [ 0 ] # 获取图像的宽和长
height = img . size [ 1 ]
if ( width < 650 ) or ( height < 650 ) : # 判断图形尺寸有一条边小于600像素的直接删除
os . remove ( each_bmp_root )