(trajectory)
| 1188 | assert black_ratio > 0.5, "The black pixel percentage does not exceed 50%." |
| 1189 | |
| 1190 | def test_task_102(trajectory): |
| 1191 | image_path = "./output/102.png" |
| 1192 | ref_path = "./data/102.jpeg" |
| 1193 | |
| 1194 | # 打开目标图像 |
| 1195 | image = Image.open(image_path) |
| 1196 | |
| 1197 | # 将图像转换为灰度图 |
| 1198 | gray_image = image.convert('L') |
| 1199 | |
| 1200 | # 将灰度图转换为numpy数组 |
| 1201 | gray_array = np.array(gray_image) |
| 1202 | |
| 1203 | # 定义黑色像素的阈值(例如,灰度值小于等于50的像素被认为是黑色) |
| 1204 | black_threshold = 50 |
| 1205 | |
| 1206 | # 计算黑色像素的数量 |
| 1207 | black_pixels = np.sum(gray_array <= black_threshold) |
| 1208 | |
| 1209 | # 计算总像素数量 |
| 1210 | total_pixels = gray_array.size |
| 1211 | |
| 1212 | # 计算黑色像素比例 |
| 1213 | black_ratio = black_pixels / total_pixels |
| 1214 | print(black_ratio) |
| 1215 | # 检查图像中黑色像素的比例是否超过30% |
| 1216 | assert black_ratio > 0.5, "The black pixel percentage does not exceed 50%." |
| 1217 | |
| 1218 | |
| 1219 | def test_task_103(trajectory): |
nothing calls this directly
no outgoing calls
no test coverage detected