Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Perspective Transform of an Image

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2008
    Posts
    6

    Perspective Transform of an Image

    Hey
    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:
    http://onebulb.com/D2.png

    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:
    http://onebulb.com/D1.png

    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)
    http://onebulb.com/gimpsrc.txt


    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.

  2. #2
    Member Regular Contributor Jackis's Avatar
    Join Date
    Sep 2005
    Location
    Saint-Petersburg, Russia
    Posts
    275

    Re: Perspective Transform of an Image

    Here is rather old, but very good article about computing quadrilateral-to-rectangle perspective transformation:

    http://www.comp.nus.edu.sg/~lowkl/pu...wk_jgt2003.pdf

  3. #3
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Perspective Transform of an Image

    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.

  4. #4
    Member Regular Contributor Jackis's Avatar
    Join Date
    Sep 2005
    Location
    Saint-Petersburg, Russia
    Posts
    275

    Re: Perspective Transform of an Image

    dletozeun,

    You're right, but if you made such a transform on arbitrary quadrilateral, you would see artifacts
    http://www.r3.nu/~cass/qcoord/

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2008
    Posts
    6

    Re: Perspective Transform of an Image

    Hey

    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.

    Thanks

  6. #6
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Perspective Transform of an Image

    Thanks Jackis, I did not realized it

  7. #7
    Member Regular Contributor Jackis's Avatar
    Join Date
    Sep 2005
    Location
    Saint-Petersburg, Russia
    Posts
    275

    Re: Perspective Transform of an Image

    De rien, dletozeun

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •