Spaces:
Running
Running
| from PIL import Image,ImageDraw | |
| from .draw_utils import box_to_xy,to_int_points,box_to_point | |
| #ver-2024-11-18 | |
| def create_color_image(width, height, color=(255,255,255)): | |
| if color == None: | |
| color = (0,0,0) | |
| if len(color )== 3: | |
| mode ="RGB" | |
| elif len(color )== 4: | |
| mode ="RGBA" | |
| img = Image.new(mode, (width, height), color) | |
| return img | |
| def fill_points(image,points,color=(255,255,255)): | |
| return draw_points(image,points,fill=color) | |
| def draw_points(image,points,outline=None,fill=None,width=1,plot_color=None,plot_size=3): | |
| draw = ImageDraw.Draw(image) | |
| image_draw_points(draw,points,outline,fill,width,plot_color,plot_size) | |
| return image | |
| def image_draw_points(draw,points,outline=None,fill=None,width=1,plot_color=None,plot_size=3): | |
| int_points = [(int(x), int(y)) for x, y in points] | |
| if outline is not None or fill is not None: | |
| draw.polygon(int_points, outline=outline,fill=fill,width=width) | |
| if plot_color!=None: | |
| print(int_points,plot_size,plot_color) | |
| for point in int_points: | |
| draw.circle(point,plot_size,fill=plot_color) | |
| def draw_box(image,box,outline=None,fill=None): | |
| points = to_int_points(box_to_point(box)) | |
| return draw_points(image,points,outline,fill) | |
| def from_numpy(numpy_array): | |
| return Image.fromarray(numpy_array) |