Change the bool into float for printing; add path check in gimp
This commit is contained in:
@@ -197,6 +197,9 @@ def check_brightness_decrease_and_structure_sim(src_path, tgt_path):
|
|||||||
Check the brightness of src is lower than tgt and the structures are similar
|
Check the brightness of src is lower than tgt and the structures are similar
|
||||||
gimp:7a4deb26-d57d-4ea9-9a73-630f66a7b568
|
gimp:7a4deb26-d57d-4ea9-9a73-630f66a7b568
|
||||||
"""
|
"""
|
||||||
|
if src_path is None or tgt_path is None:
|
||||||
|
return 0.
|
||||||
|
|
||||||
img_src = Image.open(src_path)
|
img_src = Image.open(src_path)
|
||||||
img_tgt = Image.open(tgt_path)
|
img_tgt = Image.open(tgt_path)
|
||||||
|
|
||||||
@@ -222,6 +225,9 @@ def check_saturation_increase_and_structure_sim(src_path, tgt_path):
|
|||||||
Check the saturation of src is higher than tgt and the structures are similar
|
Check the saturation of src is higher than tgt and the structures are similar
|
||||||
gimp:554785e9-4523-4e7a-b8e1-8016f565f56a
|
gimp:554785e9-4523-4e7a-b8e1-8016f565f56a
|
||||||
"""
|
"""
|
||||||
|
if src_path is None or tgt_path is None:
|
||||||
|
return 0.
|
||||||
|
|
||||||
img_src = Image.open(src_path)
|
img_src = Image.open(src_path)
|
||||||
hsv_img_src = img_src.convert('HSV')
|
hsv_img_src = img_src.convert('HSV')
|
||||||
img_tgt = Image.open(tgt_path)
|
img_tgt = Image.open(tgt_path)
|
||||||
@@ -254,17 +260,23 @@ def check_file_exists_and_structure_sim(src_path, tgt_path):
|
|||||||
Check if the image has been exported to the desktop
|
Check if the image has been exported to the desktop
|
||||||
gimp:77b8ab4d-994f-43ac-8930-8ca087d7c4b4
|
gimp:77b8ab4d-994f-43ac-8930-8ca087d7c4b4
|
||||||
"""
|
"""
|
||||||
|
if src_path is None or tgt_path is None:
|
||||||
|
return 0.
|
||||||
|
|
||||||
# Check if the file exists
|
# Check if the file exists
|
||||||
export_file_exists = os.path.isfile(src_path)
|
export_file_exists = os.path.isfile(src_path)
|
||||||
if not export_file_exists:
|
if not export_file_exists:
|
||||||
return False
|
return 0.
|
||||||
|
|
||||||
# Check whether the target image is the same as the source image
|
# Check whether the target image is the same as the source image
|
||||||
img_src = Image.open(src_path)
|
img_src = Image.open(src_path)
|
||||||
img_tgt = Image.open(tgt_path)
|
img_tgt = Image.open(tgt_path)
|
||||||
structure_same = structure_check_by_ssim(img_src, img_tgt)
|
structure_same = structure_check_by_ssim(img_src, img_tgt)
|
||||||
|
|
||||||
return structure_same
|
if structure_same:
|
||||||
|
return 1.
|
||||||
|
else:
|
||||||
|
return 0.
|
||||||
|
|
||||||
|
|
||||||
def check_triangle_position(tgt_path):
|
def check_triangle_position(tgt_path):
|
||||||
@@ -272,6 +284,9 @@ def check_triangle_position(tgt_path):
|
|||||||
Check if the triangle is in the middle of the image.
|
Check if the triangle is in the middle of the image.
|
||||||
gimp:f4aec372-4fb0-4df5-a52b-79e0e2a5d6ce
|
gimp:f4aec372-4fb0-4df5-a52b-79e0e2a5d6ce
|
||||||
"""
|
"""
|
||||||
|
if tgt_path is None:
|
||||||
|
return 0.
|
||||||
|
|
||||||
# Load the image
|
# Load the image
|
||||||
img = Image.open(tgt_path)
|
img = Image.open(tgt_path)
|
||||||
img_array = np.array(img)
|
img_array = np.array(img)
|
||||||
@@ -322,6 +337,9 @@ def check_contrast_increase_and_structure_sim(src_path, tgt_path):
|
|||||||
Check if the src image has higher contrast than the tgt image and the structures are similar
|
Check if the src image has higher contrast than the tgt image and the structures are similar
|
||||||
gimp:f723c744-e62c-4ae6-98d1-750d3cd7d79d
|
gimp:f723c744-e62c-4ae6-98d1-750d3cd7d79d
|
||||||
"""
|
"""
|
||||||
|
if src_path is None or tgt_path is None:
|
||||||
|
return 0.
|
||||||
|
|
||||||
# Load images
|
# Load images
|
||||||
source_image = Image.open(src_path)
|
source_image = Image.open(src_path)
|
||||||
target_image = Image.open(tgt_path)
|
target_image = Image.open(tgt_path)
|
||||||
@@ -344,6 +362,9 @@ def check_config_status(actual_config_path, rule):
|
|||||||
"""
|
"""
|
||||||
Check if the GIMP status is as expected
|
Check if the GIMP status is as expected
|
||||||
"""
|
"""
|
||||||
|
if actual_config_path is None:
|
||||||
|
return 0.
|
||||||
|
|
||||||
with open(actual_config_path, 'r') as f:
|
with open(actual_config_path, 'r') as f:
|
||||||
content = f.readlines()
|
content = f.readlines()
|
||||||
|
|
||||||
@@ -367,6 +388,10 @@ def check_image_size_and_structure_sim(src_path, tgt_path, height=512, width=Non
|
|||||||
Check if the size of the src image is correct and the structure of the two images are similar.
|
Check if the size of the src image is correct and the structure of the two images are similar.
|
||||||
gimp:d16c99dc-2a1e-46f2-b350-d97c86c85c15
|
gimp:d16c99dc-2a1e-46f2-b350-d97c86c85c15
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if src_path is None or tgt_path is None:
|
||||||
|
return 0.
|
||||||
|
|
||||||
# Load images
|
# Load images
|
||||||
source_image = Image.open(src_path)
|
source_image = Image.open(src_path)
|
||||||
target_image = Image.open(tgt_path)
|
target_image = Image.open(tgt_path)
|
||||||
@@ -396,6 +421,9 @@ def check_palette_and_structure_sim(src_path, tgt_path):
|
|||||||
Check if the src image is palette-based and the structure of the two images are similar
|
Check if the src image is palette-based and the structure of the two images are similar
|
||||||
gimp:06ca5602-62ca-47f6-ad4f-da151cde54cc
|
gimp:06ca5602-62ca-47f6-ad4f-da151cde54cc
|
||||||
"""
|
"""
|
||||||
|
if src_path is None or tgt_path is None:
|
||||||
|
return 0.
|
||||||
|
|
||||||
# Check if the source image is palette-based
|
# Check if the source image is palette-based
|
||||||
source_image = Image.open(src_path)
|
source_image = Image.open(src_path)
|
||||||
palette_based = source_image.mode == 'P'
|
palette_based = source_image.mode == 'P'
|
||||||
@@ -415,6 +443,9 @@ def check_textbox_on_leftside(src_path):
|
|||||||
Check if the textbox is on the left side of the image.
|
Check if the textbox is on the left side of the image.
|
||||||
gimp:e2dd0213-26db-4349-abe5-d5667bfd725c
|
gimp:e2dd0213-26db-4349-abe5-d5667bfd725c
|
||||||
"""
|
"""
|
||||||
|
if src_path is None:
|
||||||
|
return 0.
|
||||||
|
|
||||||
source_image = Image.open(src_path)
|
source_image = Image.open(src_path)
|
||||||
gray_image = source_image.convert("L")
|
gray_image = source_image.convert("L")
|
||||||
width, height = source_image.size
|
width, height = source_image.size
|
||||||
@@ -440,6 +471,9 @@ def check_image_mirror(src_path, tgt_path):
|
|||||||
Check if the image is mirrored
|
Check if the image is mirrored
|
||||||
gimp:72f83cdc-bf76-4531-9a1b-eb893a13f8aa
|
gimp:72f83cdc-bf76-4531-9a1b-eb893a13f8aa
|
||||||
"""
|
"""
|
||||||
|
if src_path is None or tgt_path is None:
|
||||||
|
return 0.
|
||||||
|
|
||||||
# Load images
|
# Load images
|
||||||
source_image = Image.open(src_path)
|
source_image = Image.open(src_path)
|
||||||
target_image = Image.open(tgt_path)
|
target_image = Image.open(tgt_path)
|
||||||
@@ -448,7 +482,10 @@ def check_image_mirror(src_path, tgt_path):
|
|||||||
transposed_image = source_image.transpose(Image.FLIP_LEFT_RIGHT)
|
transposed_image = source_image.transpose(Image.FLIP_LEFT_RIGHT)
|
||||||
# Use 0.99 because the image may not be exactly mirrored by gimp
|
# Use 0.99 because the image may not be exactly mirrored by gimp
|
||||||
mirrored = structure_check_by_ssim(transposed_image, target_image, 0.99)
|
mirrored = structure_check_by_ssim(transposed_image, target_image, 0.99)
|
||||||
return mirrored
|
if mirrored:
|
||||||
|
return 1.
|
||||||
|
else:
|
||||||
|
return 0.
|
||||||
|
|
||||||
|
|
||||||
def check_green_background(src_path, tgt_path):
|
def check_green_background(src_path, tgt_path):
|
||||||
@@ -456,6 +493,9 @@ def check_green_background(src_path, tgt_path):
|
|||||||
Check if the background of the source image is green.
|
Check if the background of the source image is green.
|
||||||
gimp:734d6579-c07d-47a8-9ae2-13339795476b
|
gimp:734d6579-c07d-47a8-9ae2-13339795476b
|
||||||
"""
|
"""
|
||||||
|
if src_path is None or tgt_path is None:
|
||||||
|
return 0.
|
||||||
|
|
||||||
# Load images
|
# Load images
|
||||||
source_image = Image.open(src_path)
|
source_image = Image.open(src_path)
|
||||||
target_image = Image.open(tgt_path)
|
target_image = Image.open(tgt_path)
|
||||||
@@ -471,9 +511,9 @@ def check_green_background(src_path, tgt_path):
|
|||||||
# Here, "green" means more green than red or blue
|
# Here, "green" means more green than red or blue
|
||||||
r, g, b = source_pixels[x, y][:3]
|
r, g, b = source_pixels[x, y][:3]
|
||||||
if not (g > r and g > b):
|
if not (g > r and g > b):
|
||||||
return False
|
return 0.
|
||||||
|
|
||||||
return True
|
return 1.
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user