[Gimp-developer] Problem with perspective transform matrix
Hello, I am trying to build an algorithm that transforms pictures (all taken from the same viewpoint) into their corrected-for-perspective equivalents. In the GIMP, I can apply the desired perspective transformation to an image and retrieve the required transform matrix (it is {{0.485, -0.374, 178}, {0, 0.45, 0}, {0, 0, 1}}, reading rows). (See http://www.rodo.nl/input.jpg and http://www.rodo.nl/result.jpg for input image desired output, respectively). However, when I use this transformation matrix in my own code, I get strange results, even using the function gimp_matrix3_transform_point from gimpmatrix.c. See http://www.rodo.nl/error.jpg for the output I receive. To compute a transformed coordinate (x', y') I simply multiply (x, y, 1) by the transformation matrix that GIMP shows, dividing both x' and y' by w' (the third value in the vector that is a result of that multiplication) in order to switch back to non-homogenuous coordinates. Is there a bug in generating the transformation matrix, or should I interpret it differently? The function I wrote to compute a new coordinate based on an old one and the transformation matrix seems to work, since it yields the exact same results as does gimp_matrix3_transform_point(). I hope that someone can help me interpret GIMP's transformation matrix. Regards, Willem Vervuurt The Netherlands ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Problem with perspective transform matrix
Hi Willem, However, when I use this transformation matrix in my own code, I get strange results, even using the function gimp_matrix3_transform_point from gimpmatrix.c. It looks like you are applying the transform in the wrong direction... To compute a transformed coordinate (x', y') I simply multiply (x, y, 1) by the transformation matrix that GIMP shows In that case, I think that the transformation converts the destination coordinate to the corresponding source coordinate. -- David Hodson -- this night wounds time ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Problem with perspective transform matrix
Hi David, thanks for your input. I have already tried that, but it is not the case. Your suggestion is equal to using exactly my method but with an inverted transformation matrix (I have implemented this to make sure, see http://www.rodo.nl/error_inv.jpg for the output generated after switching source -- destination). Something more complicated must be going on... Regards, Willem David Hodson wrote: Hi Willem, However, when I use this transformation matrix in my own code, I get strange results, even using the function gimp_matrix3_transform_point from gimpmatrix.c. It looks like you are applying the transform in the wrong direction... To compute a transformed coordinate (x', y') I simply multiply (x, y, 1) by the transformation matrix that GIMP shows In that case, I think that the transformation converts the destination coordinate to the corresponding source coordinate. ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
Re: [Gimp-developer] Problem with perspective transform matrix
Hi, On Tue, 2007-05-29 at 14:50 +0200, Willem Vervuurt wrote: I am trying to build an algorithm that transforms pictures (all taken from the same viewpoint) into their corrected-for-perspective equivalents. In the GIMP, I can apply the desired perspective transformation to an image and retrieve the required transform matrix (it is {{0.485, -0.374, 178}, {0, 0.45, 0}, {0, 0, 1}}, reading rows). (See http://www.rodo.nl/input.jpg and http://www.rodo.nl/result.jpg for input image desired output, respectively). I think you are making the wrong assumption that the perspective transform tool would apply an affine transformation which can be expressed as a 3x3 matrix. You probably know these matrices for example from SVG files. The transformation performed by the Perspective transform tool is however not necessarily an affine transformation. It uses a 4x4 matrix. Only the upper left 3x3 submatrix 3x3 is displayed because the other values are always 0.0 or 1.0. Sven ___ Gimp-developer mailing list Gimp-developer@lists.XCF.Berkeley.EDU https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer