|
from PIL import Image,ImageDraw |
|
from .draw_utils import box_to_xy,to_int_points,box_to_point |
|
|
|
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): |
|
draw = ImageDraw.Draw(image) |
|
int_points = [(int(x), int(y)) for x, y in points] |
|
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) |