polymerist.graphics.imageutils

Tools for editing and manipulating images, and image colors, sizes, and representations

Functions

img_from_bytes(→ PIL.Image.Image)

Load an image from a bytestream

img_to_array(→ numpy.ndarray)

Convert an image to a numpy array

get_axis_bounds(→ tuple[tuple[int, int], tuple[int, int]])

Takes an image and returns a pair of tuples containing the min and max non-background

get_tight_bbox(→ tuple[int, Ellipsis])

Takes an image and returns a 4-tuple of the coordinates of the tight bounding box based on a choice of background color

crop_borders(→ PIL.Image.Image)

Takes an image and returns an image with all extraneous borders of a particular background color cropped off

Module Contents

polymerist.graphics.imageutils.img_from_bytes(img_bytes: bytearray) PIL.Image.Image[source]

Load an image from a bytestream

polymerist.graphics.imageutils.img_to_array(image: PIL.Image.Image, encoding: str = 'RGB') numpy.ndarray[source]

Convert an image to a numpy array

polymerist.graphics.imageutils.get_axis_bounds(image: PIL.Image.Image, bg_color: int | tuple[int]) tuple[tuple[int, int], tuple[int, int]][source]

Takes an image and returns a pair of tuples containing the min and max non-background coordinates along the x- and y-axis (respectively) for some chosen background color

polymerist.graphics.imageutils.get_tight_bbox(image: PIL.Image.Image, bg_color: int | tuple[int]) tuple[int, Ellipsis][source]

Takes an image and returns a 4-tuple of the coordinates of the tight bounding box based on a choice of background color

polymerist.graphics.imageutils.crop_borders(image: PIL.Image.Image, bg_color: int | tuple[int]) PIL.Image.Image[source]

Takes an image and returns an image with all extraneous borders of a particular background color cropped off