MCPcopy Create free account
hub / github.com/Mercury7353/PyBench / test_task_89

Function test_task_89

data/unit_test/tests.py:947–973  ·  view source on GitHub ↗
(trajectory)

Source from the content-addressed store, hash-verified

945 assert black_ratio > 0.25, "The black pixel percentage does not exceed 30%."
946
947def test_task_89(trajectory):
948 image_path = "./output/89.png"
949 ref_path = "./data/89.jpeg"
950
951 # 打开目标图像
952 image = Image.open(image_path)
953
954 # 将图像转换为灰度图
955 gray_image = image.convert('L')
956
957 # 将灰度图转换为numpy数组
958 gray_array = np.array(gray_image)
959
960 # 定义黑色像素的阈值(例如,灰度值小于等于50的像素被认为是黑色)
961 black_threshold = 50
962
963 # 计算黑色像素的数量
964 black_pixels = np.sum(gray_array <= black_threshold)
965
966 # 计算总像素数量
967 total_pixels = gray_array.size
968
969 # 计算黑色像素比例
970 black_ratio = black_pixels / total_pixels
971 print(black_ratio)
972 # 检查图像中黑色像素的比例是否超过30%
973 assert black_ratio > 0.3, "The black pixel percentage does not exceed 30%."
974
975def test_task_90(trajectory):
976 image_path = "./output/90.png"

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected