File size: 1,004 Bytes
0aba763
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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

# deprecated
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):
    
    draw = ImageDraw.Draw(image)
    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)
    
    return image

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)