-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage_funcs.py
41 lines (36 loc) · 1.52 KB
/
image_funcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from PIL import Image, ImageEnhance
def resize_image_pixelsize(image, pixel_size):
# Resize the image to the desired pixel size
image = image.convert("RGB")
new_width = image.size[1] // round(pixel_size)
new_height = image.size[0] // round(pixel_size)
resized_img_pixelsize = image.resize((new_width,
new_height),
Image.LANCZOS)
return resized_img_pixelsize
def quantize_colors(image, color_palette):
# Reduce the color palette
image = image.convert("RGB")
quantized_image = image.quantize(colors=round(color_palette))
return quantized_image
def adjust_brightness(image, brightness_factor):
# Adjust the brightness of the image
image = image.convert("RGB")
brightness_float = brightness_factor / 100
enhancer = ImageEnhance.Brightness(image)
adjusted_image = enhancer.enhance(brightness_float)
return adjusted_image
def enhance_sharpness(image, sharpness_factor):
# Enhance the sharpness of the image
image = image.convert("RGB")
sharpness_factor = sharpness_factor / 10
enhancer = ImageEnhance.Sharpness(image)
enhanced_image = enhancer.enhance(sharpness_factor)
return enhanced_image
def adjust_vibrance(image, vibrance_factor):
# Adjust the vibrance of the image
image = image.convert("RGB")
vibrance_float = vibrance_factor / 100
enhancer = ImageEnhance.Color(image)
vibrant_image = enhancer.enhance(vibrance_float)
return vibrant_image