(image,
points,
curr_point=None,
highlight_all=True,
radius_scale=0.01)
| 42 | |
| 43 | |
| 44 | def draw_points_on_image(image, |
| 45 | points, |
| 46 | curr_point=None, |
| 47 | highlight_all=True, |
| 48 | radius_scale=0.01): |
| 49 | overlay_rgba = Image.new("RGBA", image.size, 0) |
| 50 | overlay_draw = ImageDraw.Draw(overlay_rgba) |
| 51 | for point_key, point in points.items(): |
| 52 | if ((curr_point is not None and curr_point == point_key) |
| 53 | or highlight_all): |
| 54 | p_color = (255, 0, 0) |
| 55 | t_color = (0, 0, 255) |
| 56 | |
| 57 | else: |
| 58 | p_color = (255, 0, 0, 35) |
| 59 | t_color = (0, 0, 255, 35) |
| 60 | |
| 61 | rad_draw = int(image.size[0] * radius_scale) |
| 62 | |
| 63 | p_start = point.get("start_temp", point["start"]) |
| 64 | p_target = point["target"] |
| 65 | |
| 66 | if p_start is not None and p_target is not None: |
| 67 | p_draw = int(p_start[0]), int(p_start[1]) |
| 68 | t_draw = int(p_target[0]), int(p_target[1]) |
| 69 | |
| 70 | overlay_draw.line( |
| 71 | (p_draw[0], p_draw[1], t_draw[0], t_draw[1]), |
| 72 | fill=(255, 255, 0), |
| 73 | width=2, |
| 74 | ) |
| 75 | |
| 76 | if p_start is not None: |
| 77 | p_draw = int(p_start[0]), int(p_start[1]) |
| 78 | overlay_draw.ellipse( |
| 79 | ( |
| 80 | p_draw[0] - rad_draw, |
| 81 | p_draw[1] - rad_draw, |
| 82 | p_draw[0] + rad_draw, |
| 83 | p_draw[1] + rad_draw, |
| 84 | ), |
| 85 | fill=p_color, |
| 86 | ) |
| 87 | |
| 88 | if curr_point is not None and curr_point == point_key: |
| 89 | # overlay_draw.text(p_draw, "p", font=font, align="center", fill=(0, 0, 0)) |
| 90 | overlay_draw.text(p_draw, "p", align="center", fill=(0, 0, 0)) |
| 91 | |
| 92 | if p_target is not None: |
| 93 | t_draw = int(p_target[0]), int(p_target[1]) |
| 94 | overlay_draw.ellipse( |
| 95 | ( |
| 96 | t_draw[0] - rad_draw, |
| 97 | t_draw[1] - rad_draw, |
| 98 | t_draw[0] + rad_draw, |
| 99 | t_draw[1] + rad_draw, |
| 100 | ), |
| 101 | fill=t_color, |
no test coverage detected