Implementing Bilinear Transformation version quadToQuad (without perspective)
-
Hello :-)
This is my first post.
What I'm trying to do, is implement function quadToQuad but based on bilinear transformation.
Mean almost the same result but without perspective.It is possible to implement this doing simple inversed transformation pixel by pixel, with returning changed QImage.
But better is to do it throu matrix with QTransform.
As I searched throu net, I found some people who try to do it, in qt too. But many people who describe bilinear transformation for GIS - Image (Point) Registration, Image Morphing.So I thing many people will use this function as well. Even someone put request for OpenCV developers for this function.
What I need is transformation EXACTLY to requested corners, not like QTransform::quadToQuad which give me picture's corners unreleated to delivered QPoint's.
I want to deform face throu selected points (wider/smaller mouths, eyes, nose, etc). So I need divide photo for triangles or quads, and then modify them. So, if someone have: anyTriangleToAnyTriangle function (affine transformation), I'm appreciate too :-D. -
Here is texts concerning our problem:
"http://qt-project.org/forums/viewthread/2007":http://qt-project.org/forums/viewthread/2007
Unresolved post asking for bilinear transformation."http://qt-project.org/doc/qt-4.8/qtransform.html":http://qt-project.org/doc/qt-4.8/qtransform.html
Qtransform doc for place what to use for build bilinear transformation matrix."http://www.google.pl/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&ved=0CDMQFjAB&url=http://rozwojwnt.dsw.edu.pl/dokumenty/Transformacje_georeferencja_i_rektyfikacja_map_i_obrazow.pdf&ei=_ESKUZjDJpSChQfDjoGQCw&usg=AFQjCNFEXVqXbPQiIeKZDIkz1kceifp3sw&bvm=bv.46226182,d.ZG4":http://www.google.pl/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&ved=0CDMQFjAB&url=http://rozwojwnt.dsw.edu.pl/dokumenty/Transformacje_georeferencja_i_rektyfikacja_map_i_obrazow.pdf&ei=_ESKUZjDJpSChQfDjoGQCw&usg=AFQjCNFEXVqXbPQiIeKZDIkz1kceifp3sw&bvm=bv.46226182,d.ZG4
Here is mathematical models for bilinear transformation among other things. Everything in Polish language."http://www.focus.agh.edu.pl/thesis/MGR05.pdf":http://www.focus.agh.edu.pl/thesis/MGR05.pdf
Very good text for master's degree, about program with bilinear and perspective transformation (page 11, chapter 2.2.1 "Przekształcenie dwuliniowe / bilinear transformation). Polish language."http://en.wikipedia.org/wiki/Möbius_transformation":http://en.wikipedia.org/wiki/Möbius_transformation
"http://pl.wikipedia.org/wiki/Przekształcenie_dwuliniowe":http://pl.wikipedia.org/wiki/Przekształcenie_dwuliniowe
Wikipedia about bilinear transformation."http://www.pyqtgraph.org/documentation/functions.html":http://www.pyqtgraph.org/documentation/functions.html
Find function: solveBilinearTransform(points1, points2), which return matrix for bilinear transformation of given points."http://qt4-x11.sourcearchive.com/documentation/4.5.3really4.5.2/classQRasterPaintEngine_abec277c99e83d314b166f01a8a65b717.html":http://qt4-x11.sourcearchive.com/documentation/4.5.3really4.5.2/classQRasterPaintEngine_abec277c99e83d314b166f01a8a65b717.html
Maybe in this library we can find solution, but I'm not enough good in matrix transformation.
"
http://eigen.tuxfamily.org/index.php?title=Main_Page": http://eigen.tuxfamily.org/index.php?title=Main_Page
This library probably giving solution, but my mathematical abilities cannot let me find solution."http://www.techques.com/question/1-11512829/Create-QTransform-given-4-points-defining-the-transformed-unit-square":http://www.techques.com/question/1-11512829/Create-QTransform-given-4-points-defining-the-transformed-unit-square
Author of the post asking about perspective transformation, but answer 2 giving code for step by step solution matrix deformation, which I tried but without success. My intention was use this code, but remove perspective transformation - but without good understanding of matrixes I can't get it work.
" -
...and rest sources concerning the topic:
http://zrusin.blogspot.com/2006/10/perspective-transformations-in-main.html": http://zrusin.blogspot.com/2006/10/perspective-transformations-in-main.html
"http://zrusin.blogspot.com/2006/09/perspective-transformations.html":http://zrusin.blogspot.com/2006/09/perspective-transformations.html
Zack Rusin is the author of QTransform::quadToQuad function. Probably implementation of this function without perspective is easier. Source is in qtransform.cpp."http://qt.gitorious.org/qt/qtlocation/blobs/f2243e9e9f39363cf80e171034c51cc38ecddbe3/src/location/maps/qgeomapobjectengine_p.cpp":http://qt.gitorious.org/qt/qtlocation/blobs/f2243e9e9f39363cf80e171034c51cc38ecddbe3/src/location/maps/qgeomapobjectengine_p.cpp
Search for "bilinear". This progs using QTransform::quadToQuad, but comments pointing to bilinear transformation. Is this what we need ?"http://cs.brown.edu/courses/csci1950-g/asgn/proj6/resources/ProjectiveMappings.pdf":http://cs.brown.edu/courses/csci1950-g/asgn/proj6/resources/ProjectiveMappings.pdf
This is very good and short text about this what we need. Mathematics."http://stackoverflow.com/questions/2992264/extracting-a-quadrilateral-image-to-a-rectangle":http://stackoverflow.com/questions/2992264/extracting-a-quadrilateral-image-to-a-rectangle
Post about projective transformation (perspective transformation). But author make firstly transformation without perspective. I think it can be usable for this topic."http://opencv.willowgarage.com/documentation/cpp/geometric_image_transformations.html?highlight=bilinear":http://opencv.willowgarage.com/documentation/cpp/geometric_image_transformations.html?highlight=bilinear
Unfortunately OpenCV don't have bilinear image warping. So we cannot use it. But maybe affine transformation for any triangle to any triangle function ??? But the other things is >>probably<< Qt have same functions for affine."http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/2011Update/ippxe/IPPI/ippi_ch12/functn_WarpBilinearQuad.htm#functn_WarpBilinearQuad":http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/2011Update/ippxe/IPPI/ippi_ch12/functn_WarpBilinearQuad.htm#functn_WarpBilinearQuad
"http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/2011Update/ippxe/IPPI/ippi_ch12/functn_WarpBilinear.htm":http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/2011Update/ippxe/IPPI/ippi_ch12/functn_WarpBilinear.htm
Intel paid library have this function implemented. Which i'm not interested to pay for all library for one function only.
"
http://code.opencv.org/issues/1522": http://code.opencv.org/issues/1522
Someone ask for bilinear transformation for OpenCV library, but without success, about one year ago."http://homes.cs.washington.edu/~ankit/course_projects/files/DIP/A2_web/Image Morphing.htm":http://homes.cs.washington.edu/~ankit/course_projects/files/DIP/A2_web/Image Morphing.htm
Short text about Image Morphing."https://ccrma.stanford.edu/~jacobliu/368Report/":https://ccrma.stanford.edu/~jacobliu/368Report/
Search "Bilinear transformation". Here is a great solution for function without matrix. -
"http://www.focus.agh.edu.pl/thesis/MGR05.pdf":http://www.focus.agh.edu.pl/thesis/MGR05.pdf
Inside this dissertation (polish) on page 13, we see picture showing differences between bilinear and perspective transformation.
And on page 70, we can find function "Bilinear Transformation" - completly, but in MatLab.
If anyone know MatLab script language, maybe this solution we can translate to Qtransform matrix :-D