fix distorted round Ottia Tuota Seasoned Gimper    Posts: 170 Threads: 21 Joined: Mar 2020 Reputation: 17 Operating system(s): Windows (Vista and later) Gimp version: Don't know yet 10-26-2020, 05:09 PM (10-26-2020, 10:24 AM)Ofnuts Wrote: (10-26-2020, 07:02 AM)Ottia Tuota Wrote: So, for example if you choose some four points A,B,C,D from the circumference of your clock face, and corresponding four points P,Q,R,S from a circle, the created transformation should be the one needed. The problem is that its difficult to figure out the 4 points that should correspond to 4 known points on the final correct circle. It is however possible to indicate 4 points on the distorted circle, but nothing more. So the question is, given 4 points, is there a way to compute the Projective transform (is this transform unique? additional constraints are possible to make it unique, such as keeping the distance between two points identical, or keepin the orientation between two given points, or both)) than puts them on a circle? If I have this transform, I can figure out a way to use it with gimp_item_transform_perspective(). I was thinking of the original problem. There you yourself chose four points from the dial (3,6,9,12 hours). Those could serve as A,B,C,D. On a true circle we can choose four points P,Q,R,S separated by angles of 90 degrees. This information determines the projective transformation uniquely. Of your more general question, I cannot say anything. But: I never knew that there is a procedure such as gimp_item_transform_perspective() which can be called from a plugin! (I assume it indeed can be called from a plugin? I haven't tried.)  The problem with it is that it uses the corners of the bounding box, not any general 4 points. What is even more interesting is that now I noticed another internal procedure called gimp_item_transform_matrix! It takes as input 9 floats, the elements of a 3x3 matrix. Procedure browser says: "This procedure transforms the specified item. The transformation is done by assembling a 3x3 matrix from the coefficients passed." I guess this is the usual 3x3 matrix that is attached to any projective transformation. This seem to mean that given a suitable matrix (the 9 floats), one can call the procedure gimp_item_transform_matrix to perform the corresponding transformation! On the other hand, my Python function make_projective_map, given points A,B,C,D and P,Q,R,S, computes the transformation by first computing the 3x3 matrix. This now suggests that the following could be possible: Suppose we are given points A,B,C,D and P,Q,R,S. We want to perform a projective transformation where A,B,C,D -> P,Q,R,S. From my Python function make_projective_map extract that piece of code which computes the 3x3 matrix of the desired transformation. Feed that 3x3 matrix to the procedure gimp_item_transform_matrix. I wonder if this is true. I must try it some day when I find the time. I vision that we perhaps could write a plugin that takes as input two 4-anchor paths (these give the points A,B,C,D and P,Q,R,S) and some item (=?) and performs the transformation on the item. This plugin would be the Perspective transform tool in a different disguise. I already know that there will be difficulties: the infinities that come with projective transformations. We shall see. Ottia Tuota Seasoned Gimper    Posts: 170 Threads: 21 Joined: Mar 2020 Reputation: 17 Operating system(s): Windows (Vista and later) Gimp version: Don't know yet 10-28-2020, 05:14 PM It was true, and easier than I thought. I was lucky to have that unpublished work on projective transformations, so I could just copy pieces of code. I made a new thread of it, see https://www.gimp-forum.net/Thread-Perspe...-revisited Ottia Tuota Seasoned Gimper    Posts: 170 Threads: 21 Joined: Mar 2020 Reputation: 17 Operating system(s): Windows (Vista and later) Gimp version: Don't know yet 10-30-2020, 07:26 AM (10-26-2020, 10:24 AM)Ofnuts Wrote: (10-26-2020, 07:02 AM)Ottia Tuota Wrote: So, for example if you choose some four points A,B,C,D from the circumference of your clock face, and corresponding four points P,Q,R,S from a circle, the created transformation should be the one needed. The problem is that its difficult to figure out the 4 points that should correspond to 4 known points on the final correct circle. It is however possible to indicate 4 points on the distorted circle, but nothing more. So the question is, given 4 points, is there a way to compute the Projective transform (is this transform unique? additional constraints are possible to make it unique, such as keeping the distance between two points identical, or keepin the orientation between two given points, or both)) than puts them on a circle? If I have this transform, I can figure out a way to use it with gimp_item_transform_perspective(). I have now a sort of an answer to your question. A general fact: Let A,B,C,D be four points of which no three are collinear, and let P,Q,R,S be other four points of which no three are collinear. Then there is a unique projective transformation sending A->P, B->Q, C->R, D->S. (In fact, this holds true in the projective plane which means the plane extended by one line at infinity. So, some of the points may be at infinity.) Now to your question. Assume that A,B,C,D are four distinct points. Let us assume, as you did, that they lie on a distorted circle (thus, no three are collinear). Draw a circle through A,B,C; let us call the circle Y. Then choose P,Q,R,S as follows: Let P=A, Q=B, R=C, and let S be any point on Y, distinct from A,B,C. Apply the above general fact to this situation. It follows that there is a unique projective transformation which keeps A,B,C fixed and sends D to S. So, A,B,C,D are sent to the circle. To get the construction unique, we can agree that S is defined to be that point on Y which is closest to D, or we can use some other restriction. This may seem like a dubious trick but I think this is all right. After this, writing a plugin for this job is simple, if you are willing to use my plugin: It requires just writing and solving some equations (to find S) and then letting the plugin call my plugin with proper inputs (points A,B,C,D and P,Q,R,S). (Though in practice it probably is not quite so simple. If infinities come into play they may cause my plugin to fail, and this depends on how S is chosen.) « Next Oldest | Next Newest »