Skip to content

QUAD Deformation #8955

Closed Answered by radarhere
ceccopierangiolieugenio asked this question in Q&A
Discussion options

You must be logged in to vote

To achieve your effect, I found code on StackOverflow. You can find a copy at https://stackoverflow.com/questions/42827978/image-perspective-transform-using-pillow

import numpy
from PIL import Image

def find_coeffs(pa, pb):
    matrix = []
    for p1, p2 in zip(pa, pb):
        matrix.append([p1[0], p1[1], 1, 0, 0, 0, -p2[0]*p1[0], -p2[0]*p1[1]])
        matrix.append([0, 0, 0, p1[0], p1[1], 1, -p2[1]*p1[0], -p2[1]*p1[1]])

    A = numpy.matrix(matrix, dtype=float)
    B = numpy.array(pb).reshape(8)

    res = numpy.dot(numpy.linalg.inv(A.T * A) * A.T, B)
    return numpy.array(res).reshape(8)

with Image.open("input.png") as im:
    coeffs = find_coeffs(
        [(50, 100), (100, 500), (6…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@ceccopierangiolieugenio
Comment options

Comment options

You must be logged in to vote
1 reply
@ceccopierangiolieugenio
Comment options

Answer selected by ceccopierangiolieugenio
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants