2 init gimp example

This commit is contained in:
tsuky_chen
2024-01-12 16:07:55 +08:00
parent b30d87bba8
commit e79235f568
4 changed files with 139 additions and 0 deletions

View File

@@ -9,3 +9,4 @@ from .table import check_sheet_list, check_xlsx_freeze, check_xlsx_zoom
from .table import compare_table
from .vlc import is_vlc_playing, is_vlc_recordings_folder, is_vlc_fullscreen, compare_images, compare_audios, \
compare_videos
from .gimp import increase_saturation, decrease_brightness

View File

@@ -20,3 +20,57 @@ def get_gimp_export_path():
# Handle the case where the configuration file is not found
print("GIMP configuration file not found")
return False
from PIL import Image, ImageChops, ImageStat
def calculate_saturation(image):
# convert the image to HSV mode
hsv_image = image.convert("HSV")
saturation_channel = hsv_image.split()[1]
# calculate the mean saturation level
stat = ImageStat.Stat(saturation_channel)
mean_saturation = stat.mean[0]
return mean_saturation
def increase_saturation(image1_path, image2_path):
image1 = Image.open(image1_path)
image2 = Image.open(image2_path)
# calculate the saturation level of each image
saturation1 = calculate_saturation(image1)
saturation2 = calculate_saturation(image2)
return 1 if saturation1 < saturation2 else 0
def calculate_brightness(image):
# Convert the image to grayscale mode
grayscale_image = image.convert("L")
# Get the image data
pixels = list(grayscale_image.getdata())
brightness = sum(pixels) / len(pixels)
return brightness
def decrease_brightness(image1_path, image2_path):
image1 = Image.open(image1_path)
image2 = Image.open(image2_path)
brightness1 = calculate_brightness(image1)
brightness2 = calculate_brightness(image2)
return 1 if brightness1 > brightness2 else 0
if __name__ == "__main__":
# 输入两张图片的路径
image1_path = "../Downloads/1.png"
image2_path = "../Downloads/edited_darker.png"
# 比较图片亮度
decrease_brightness(image1_path, image2_path)
# 比较图片饱和度
increase_saturation(image1_path, image2_path)