From e79235f568187b41e0f2af393ce4eda3feaa49c0 Mon Sep 17 00:00:00 2001 From: tsuky_chen <3107760494@qq.com> Date: Fri, 12 Jan 2024 16:07:55 +0800 Subject: [PATCH] 2 init gimp example --- desktop_env/evaluators/metrics/__init__.py | 1 + desktop_env/evaluators/metrics/gimp.py | 54 +++++++++++++++++++ .../gimp/7a4deb26-d57d-4ea9-9a73-630f66a7b568 | 42 +++++++++++++++ .../7a4deb26-d57d-4ea9-9a73-630f66a7b568 copy | 42 +++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 evaluation_examples/examples/gimp/7a4deb26-d57d-4ea9-9a73-630f66a7b568 create mode 100644 evaluation_examples/examples/gimp/7a4deb26-d57d-4ea9-9a73-630f66a7b568 copy diff --git a/desktop_env/evaluators/metrics/__init__.py b/desktop_env/evaluators/metrics/__init__.py index f520afb..6f7759d 100644 --- a/desktop_env/evaluators/metrics/__init__.py +++ b/desktop_env/evaluators/metrics/__init__.py @@ -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 diff --git a/desktop_env/evaluators/metrics/gimp.py b/desktop_env/evaluators/metrics/gimp.py index fbc328c..9607ba6 100644 --- a/desktop_env/evaluators/metrics/gimp.py +++ b/desktop_env/evaluators/metrics/gimp.py @@ -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) diff --git a/evaluation_examples/examples/gimp/7a4deb26-d57d-4ea9-9a73-630f66a7b568 b/evaluation_examples/examples/gimp/7a4deb26-d57d-4ea9-9a73-630f66a7b568 new file mode 100644 index 0000000..ab644b2 --- /dev/null +++ b/evaluation_examples/examples/gimp/7a4deb26-d57d-4ea9-9a73-630f66a7b568 @@ -0,0 +1,42 @@ +{ + "id": "7a4deb26-d57d-4ea9-9a73-630f66a7b568", + "snapshot": "gimp", + "instruction": "Make my picture less bright, please.", + "source": "https://www.quora.com/How-do-I-edit-a-photo-in-GIMP", + "config": [ + { + "type": "download", + "parameters": { + "files": [ + { + "url": "https://drive.usercontent.google.com/download?id=1SIvX9Wimyw6i2UvnoLTNDHIObvDLAsIM&export=download&authuser=0&confirm=t&uuid=a48447ab-13a2-421f-9662-6ffff8f6f6d5&at=APZUnTVRxofs822XxgEv33WwYCkb:1705046264363", + "path": "Desktop/1.png" + } + ] + } + }, + { + "type": "open", + "parameters": { + "path": "Desktop/View_Person_Organizational_Summary.docx" + } + } + ], + "trajectory": "trajectories/", + "related_apps": [ + "gimp" + ], + "evaluator": { + "func": "decrease_brightness", + "result": { + "type": "vm_file", + "path": "Desktop/1.png", + "dest": "1.png" + }, + "expected": { + "type": "vm_file", + "path": "Desktop/edited_darker.png", + "dest": "edited_darker.png" + } + } +} \ No newline at end of file diff --git a/evaluation_examples/examples/gimp/7a4deb26-d57d-4ea9-9a73-630f66a7b568 copy b/evaluation_examples/examples/gimp/7a4deb26-d57d-4ea9-9a73-630f66a7b568 copy new file mode 100644 index 0000000..eb8862a --- /dev/null +++ b/evaluation_examples/examples/gimp/7a4deb26-d57d-4ea9-9a73-630f66a7b568 copy @@ -0,0 +1,42 @@ +{ + "id": "554785e9-4523-4e7a-b8e1-8016f565f56a", + "snapshot": "gimp", + "instruction": "Could you help me increase the saturation of my photo to make it more colorful?", + "source": "https://www.quora.com/How-do-I-edit-a-photo-in-GIMP", + "config": [ + { + "type": "download", + "parameters": { + "files": [ + { + "url": "https://drive.usercontent.google.com/download?id=1SIvX9Wimyw6i2UvnoLTNDHIObvDLAsIM&export=download&authuser=0&confirm=t&uuid=a48447ab-13a2-421f-9662-6ffff8f6f6d5&at=APZUnTVRxofs822XxgEv33WwYCkb:1705046264363", + "path": "Desktop/1.png" + } + ] + } + }, + { + "type": "open", + "parameters": { + "path": "Desktop/View_Person_Organizational_Summary.docx" + } + } + ], + "trajectory": "trajectories/", + "related_apps": [ + "gimp" + ], + "evaluator": { + "func": "increase_saturation", + "result": { + "type": "vm_file", + "path": "Desktop/1.png", + "dest": "1.png" + }, + "expected": { + "type": "vm_file", + "path": "Desktop/edited_colorful.png", + "dest": "edited_colorful.png" + } + } +} \ No newline at end of file