def prepare_image(image_fd):
"""Returns a PIL image from the given file descriptor. The image is
resized in order to filtrate dominant colors and ease k-means computation.
The contrast of the image is also enhanced to help find more saturated
colors.
"""
image = Image.open(image_fd)
image.thumbnail(THUMBNAIL_SIZE)
contrast = ImageEnhance.Contrast(image)
image_high_contrast = contrast.enhance(CONTRAST)
return image_high_contrast
评论列表
文章目录