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 already know that there will be difficulties: the infinities that come with projective transformations. We shall see.