A transformation that maps lines to lines (but does not necessarily preserve parallelism) is a projective transformation. This matlab library helps you find the projective transformation matrix H (non-singular 3 × 3 matrix) given 4 pairs of non-collinear points in original and projective 2d indexed images. Also you can apply projective transformation on any image with matrix H.
A example is provided in main.m, input image is in test_image folder. You can download and run it.
Hartley, R., & Zisserman, A. (2015). Multiple view geometry in computer vision. Cambridge: Cambridge Univ. Press.