QUAD Deformation #8955
QUAD Deformation
#8955
Answered by
radarhere
May 15, 2025
Replies: 3 comments 2 replies
|
Hi. Have you seen https://pillow.readthedocs.io/en/stable/reference/ImageTransform.html? It explains that the parameter you're passing in is
The key word there for this discussion is 'source'. Your expectation was that it was the destination quadrilateral. As far as achieving your effect, could you upload a copy of your initial image? |
1 reply
|
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), (600, 400), (650, 50)],
[(0, 0), (im.width, 0), (im.width, im.height), (0, im.height)]
)
im = im.transform(im.size, Image.PERSPECTIVE, coeffs)
im.save("output.png") |
1 reply
Answer selected by
ceccopierangiolieugenio
|
It works SuperWell!!! Screen.Recording.2025-05-15.at.16.08.57.mov |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment





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