Python PIL.Image.PERSPECTIVE Examples

The following are 4 code examples of PIL.Image.PERSPECTIVE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PIL.Image , or try the search function .
Example #1
Source File: perspective.py    From maze-cv with MIT License 7 votes vote down vote up
def transform(startpoints, endpoints, im):
	'''Perform a perspective transformation on an image where startpoints are moved to endpoints, and the image is streched accordingly.'''
	width, height = im.size
	coeffs = find_coeffs(endpoints, startpoints)

	im = im.transform((width, height), Image.PERSPECTIVE, coeffs, Image.BICUBIC)
	return im 
Example #2
Source File: image_operations.py    From gabenizer with MIT License 6 votes vote down vote up
def _paste_donor_on_recipient(
        recipient_face: face_detect.Face,
        recipient_image: Image,
        donor_face: face_detect.Face,
        donor_image: Image) -> Image:

    get_coords = lambda face: [c.xy() for c in [face.left_eye, face.right_eye, face.mouth_left, face.mouth_right]]
    donor_coords = get_coords(donor_face)
    recipient_coords = get_coords(recipient_face)
    coefficients = _find_coeffs(recipient_coords, donor_coords)

    warped_donor = donor_image.transform(
        recipient_image.size, Image.PERSPECTIVE, coefficients, Image.BICUBIC)

    working_recipient = recipient_image.copy()
    working_recipient.paste(warped_donor, (0, 0), warped_donor)

    return working_recipient


# Adapted from https://stackoverflow.com/questions/14177744/how-does-perspective-transformation-work-in-pil. 
Example #3
Source File: joint_transforms.py    From cross-season-segmentation with MIT License 5 votes vote down vote up
def __call__(self, img, mask):
        width, height = img.size
        a = self.scale * (random.random() - 0.5) + 1
        b = self.scale * (random.random() - 0.5)
        c = self.scale * (random.random() - 0.5)
        d = self.scale * (random.random() - 0.5)
        e = self.scale * (random.random() - 0.5) + 1
        f = self.scale * (random.random() - 0.5)
        g = self.scale / width * (random.random() - 0.5)
        h = self.scale / height * (random.random() - 0.5)
        coeffs = np.array([a, b, c, d, e, f, g, h])
        return img.transform((width, height), Image.PERSPECTIVE, coeffs, Image.BICUBIC), mask.transform(
            (width, height), Image.PERSPECTIVE, coeffs, Image.NEAREST) 
Example #4
Source File: terminal.py    From youCanCodeAGif with MIT License 5 votes vote down vote up
def drawTerminal(text, fontsize):
    """Compose an img made of a pseudo-terminal interface,
    with print outs of text and a background from the main video"""
    black = (16,16,16)
    light = (150,210,150)
    white = (190,210,230)
    x,y=(695,500)

    font_title = ImageFont.truetype("COURIER.TTF",15)
    font_text = ImageFont.truetype("COURIER.TTF",fontsize)
    img=Image.new("RGBA", (x,y),black)
    draw = ImageDraw.Draw(img)
    draw.rectangle(((4,4),(x-5,y-5)), outline = light)
    draw.rectangle(((5,5),(x-5,y-5)), outline = white)
    draw.rectangle(((9,9),(x-10,30)), outline = light)
    draw.rectangle(((10,10),(x-10,30)), outline = white)

    draw.text((11, 15),'  GIFOLATINE 3000 V1.337 - By 1-Sisyphe',light,
              font=font_title)
    draw.text((12, 16),'  GIFOLATINE 3000 V1.337 - By 1-Sisyphe',white,
              font=font_title)
    draw.text((x-50, 15),'X O',white,font=font_title)

    draw.multiline_text((10, 40),text,light,font=font_text)
    draw.multiline_text((11, 41),text,white,font=font_text)

    new_size = (800, 800)
    new_im = Image.new("RGBA", new_size)
    new_im.paste(img,(0,100))

    coeffs = find_coeffs(
        [(0, 0), (x, 0), (x, y), (0, y)],
        [(0, 0), (x, 50), (x, 450), (0, y)])

    img = new_im.transform(new_size, Image.PERSPECTIVE, coeffs,
        Image.BICUBIC)
    img = img.rotate(0.5, resample=Image.BICUBIC)
    img_finale = Image.open('temp/background.png')
    img_finale.paste(img,(340,-75),img)

    return img_finale