View Full Version : Perspective Transform of an Image

10-26-2008, 06:17 PM
I don't normally post questions as I like to solve things myself, but I have been stuck on this for over half a year. Its very much so an algorithm question, but is independent of OpenGL for the most part (other then I use OpenGL in my app) so please ignore this if it was inappropriate to post). I do a lot of basic image editing and decided most of the programs I used did far too much and cost a lot. That got me interested in building my own image application. I have built my own application and it does everything I need except for doing a proper perspective transform. I have tried some many different algorithms, I have researched the topic myself (and I am not the best at math, but I don't think I am entirely stupid).

The issue I have is I want to be able to change the coordinates of one corner of the image (like I can in Gimp) and have none of the other image corners be affected.
Just an example, what I would like to be able to do is shown here:

In this image I have moved the bottom left corner of my image up and to the right. The other 3 corners of the image have remained in the same spot.

When I implement any version of this algorithm myself, I end up with:

In the above image I have only tried to move, the top left corner down and too the right, yet the bottom right has also been moved. I use a mac so I have also tried using the Core Image Unit Perspective transform, and the exact same thing happens. I move one corner and at least one other corner also moves. I have even tried duplicating the exact same matrix that Gimp or applications say they are using and I still have multiple corners that are moving.

Am I missing something here. Do I want more then a perspective transform. The algorithm I am currently trying to use is straight from Gimp 2.6. I do not see it doing anything fancy in particular but I am sure there is a lot happening behind the scenes that I am unaware of. On a Mac I have even tried taking the transform that gimp outputs putting to a Core Animation Layer(Mac Specific -- though I have tried the exact same thing in OpenGL) and the result is still always the name, no matter which algorithm I use for my perspective transform and no matter how I apply it.

I have copied and pasted the gimp version here (mine is currently littered with commented out code as I experiment)

So am I missing something? Am I looking at the wrong code in Gimp perhaps. Is there something extra I need to do to lock corners down? Anyone have an implementation of what I want that they are willing to share. Perhaps this is not entirely a perspective transform that I want?

Thanks for any help.

10-27-2008, 06:20 AM
Here is rather old, but very good article about computing quadrilateral-to-rectangle perspective transformation:


10-27-2008, 10:27 AM
I must miss something, but I would not play with view frustum, I would just draw picture as a texture (since you use opengl) on a quad, moving vertices when the user is moving corresponding corners in the original picture. Then Opengl, will do all the job to obtain the 1st screenshot.

10-27-2008, 11:17 AM

You're right, but if you made such a transform on arbitrary quadrilateral, you would see artifacts

10-27-2008, 10:04 PM

Thanks, I will give that paper a read as well as the link. I think I started many months ago doing an arbitrary transform and saw artifacts and was quite puzzled. I was more interested in the math now though to know what im doing wrong so you have given me two new avenues to investigate. Thanks, though I am still puzzled as to what gimp does.


10-28-2008, 07:16 AM
Thanks Jackis, I did not realized it :)

10-28-2008, 10:52 AM
De rien, dletozeun :)