1 图片预处理
使用jupyter notebook对图片统一图片格式,等比例缩小图片尺寸。
import os,datetime
starttime = datetime.datetime.now()
from PIL import Image
from PIL import ImageFile
Image.MAX_IMAGE_PIXELS = 23000000000000
ImageFile.LOAD_TRUNCATED_IMAGES = True
dirPath = r"图片地址"
save_d = r"缩小后图片存放地址"
allFile = os.listdir(dirPath)
for i in allFile:
file = dirPath +"\\" + i
print(file)
img = Image.open(file)
img = img.convert('RGB')
w,h = img.size
newWidth = 200 #缩小后的宽度
newHeight = round(newWidth / w * h)
img = img.resize((newWidth,newHeight), Image.ANTIALIAS)
img.save(save_d +"/" + i, optimize=True, quality=100)
endtime = datetime.datetime.now()
print(u'本次处理共耗费 {}S '.format((endtime - starttime).seconds))
2 提取图片相关数据(RGB值、HSV值等)
下载与安装color-summarizer。官网