CutΒΆ
The imforge.cut
module contains functions for cutting areas of images.
-
Cut out the areas delimited by a given list of polygons: i.e. fill image pixels outside of given polygons with the given fill color.
The input image is modified in place.
Note
The fill color is not necessarily an RGB color. It depends on the color space of the processed image. In particular, OpenCv images are usually opened in BGR mode, so the fill color must be a BGR value in such case.
Sample (pillow) usage:
from PIL import Image from imforge.cut import cut_out with Image.open("/path/to/image.jpg") as image: # with a single polygon and default color (black) polygon = [(15, 8), (368, 78), (325, 161), (14, 71)] cut_out(image, polygon) # with multiple polygons and purple color polygons = ( [(15, 8), (368, 78), (325, 161), (14, 71)], [(100, 0), (150, 0), (125, 20)], [(0, 150), (200, 150), (200, 178), (0, 178)], ) cut_out(image, *polygons, fillcolor=(255, 0, 255))
Note
Calling
imforge.cut.cut_out()
with aPIL image
is the same as callingimforge.cut.cut_out_pil()
.Sample (opencv) usage:
import cv2 from imforge.cut import cut_out image = cv2.imread("/path/to/image.jpg", cv2.IMREAD_UNCHANGED) # with a single polygon and default color (black) polygon = [(15, 8), (368, 78), (325, 161), (14, 71)] cut_out(image, polygon) # with multiple polygons and purple color polygons = ( [(15, 8), (368, 78), (325, 161), (14, 71)], [(100, 0), (150, 0), (125, 20)], [(0, 150), (200, 150), (200, 178), (0, 178)], ) cut_out(image, *polygons, fillcolor=(255, 0, 255))
Note
Calling
imforge.cut.cut_out()
with an OpenCv image (i.e. aNumPy array
) is the same as callingimforge.cut.cut_out_cv2()
.