update GIMP examples and eval

This commit is contained in:
Siheng Zhao
2024-01-12 16:36:02 +08:00
parent b3109bf856
commit d6f694da1c
3 changed files with 35 additions and 40 deletions

View File

@@ -1,5 +1,5 @@
import os
from PIL import Image, ImageChops, ImageStat
def get_gimp_export_path():
# Path to GIMP's configuration file. This example assumes GIMP version 2.10.
@@ -21,21 +21,19 @@ def get_gimp_export_path():
print("GIMP configuration file not found")
return False
from PIL import Image, ImageChops, ImageStat
def increase_saturation(image1_path: str, image2_path: str) -> float:
def calculate_saturation(image):
# convert the image to HSV mode
hsv_image = image.convert("HSV")
def calculate_saturation(image):
# convert the image to HSV mode
hsv_image = image.convert("HSV")
saturation_channel = hsv_image.split()[1]
saturation_channel = hsv_image.split()[1]
# calculate the mean saturation level
stat = ImageStat.Stat(saturation_channel)
mean_saturation = stat.mean[0]
# calculate the mean saturation level
stat = ImageStat.Stat(saturation_channel)
mean_saturation = stat.mean[0]
return mean_saturation
return mean_saturation
def increase_saturation(image1_path, image2_path):
image1 = Image.open(image1_path)
image2 = Image.open(image2_path)
@@ -45,17 +43,17 @@ def increase_saturation(image1_path, image2_path):
return 1 if saturation1 < saturation2 else 0
def calculate_brightness(image):
# Convert the image to grayscale mode
grayscale_image = image.convert("L")
def decrease_brightness(image1_path: str, image2_path: str) -> float:
def calculate_brightness(image):
# Convert the image to grayscale mode
grayscale_image = image.convert("L")
# Get the image data
pixels = list(grayscale_image.getdata())
# Get the image data
pixels = list(grayscale_image.getdata())
brightness = sum(pixels) / len(pixels)
return brightness
brightness = sum(pixels) / len(pixels)
return brightness
def decrease_brightness(image1_path, image2_path):
image1 = Image.open(image1_path)
image2 = Image.open(image2_path)
@@ -65,12 +63,9 @@ def decrease_brightness(image1_path, image2_path):
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)