Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
fix distorted round
#8
Since I was mentioned: I know how to get a Python function for the desired plane transformation. But I have no idea how to apply it to transform an image.

When I wrote my plugins on path transformations, I implemented also general projective transformations. But I never published it as a plugin since I felt that it was too laborious to use. But some code is embedded in the file path_transformations.py. Specifically, there is a Python function that creates projective plane transformations. I copy here the comment describing the function:

# -------------------
# make_projective_map
# -------------------
# Given four points A,B,C,D (base) in a general position (no three collinear),
# another four points P,Q,R,S (target) in a general position,
# make plane transformation which sends
#    A -> P
#    B -> Q
#    C -> R
#    D -> S
# Return also
# - coefficients [g,h,k] such that the pre-image of the ideal line has
#   the equation gx+hy+k=0; or None if the pre-image equals the ideal line;
# - the same info for the image of the ideal line.
#
# Args:
# - base:   [A,B,C,D]: [ControlPoint,ControlPoint,ControlPoint,ControlPoint]
# - target: [P,Q,R,S]: [ControlPoint,ControlPoint,ControlPoint,ControlPoint]
# Returns:
# - PlaneTransformation
# - [float,float,float] or None (coefficients g,h,k for the pre-image of ideal line)
# - [float,float,float] or None (coefficients g,h,k for the image of ideal line)
# Exceptions:
# - MakeProjectiveMapError
def make_projective_map(base,target):
.....  For the code see path_transformations.py  .....


The plane is viewed as the complex number plane. (Names 'ControlPoint' and 'RowVector' are synonymous to 'complex'). What the function does, is that it takes (almost) arbitrary four points A,B,C,D in the plane and another four points P,Q,R,S, and it creates the projective transformation which sends A,B,C,D to P,Q,R,S. The transformation will be an object in the class PlaneTransformation (my own creation, also included in the file path_transformations.py).

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.

But the problem is, how to make it to a usable plugin, for instance. That is, how to use the transformation to transform an image. That is too difficult for me. In fact, I have no idea how such image transforms are made. My hobby was to transform paths, and I designed the class PlaneTransformation for that purpose.

Any object pt in the class PlaneTransformation has attributes pt.point_map and pt.jacobian. Here pt.point_map is a function C->C (the C being the complex number plane). So, if z is some point in the plane (as a complex number), then pt.point_map(z) is the transformed point (as a complex number). The other attribute pt.jacobian gives the Jacobian matrix of the mapping: pt.jacobian(z) is the Jacobian matrix at point z.

I imagine that the Jacobian matrix is not needed for image transformations (it was crucial for path transformations). So, having chosen such points A,B,C,D and P,Q,R,S, one calls the Python function 'make_projective_map' as follows:

pt = make_projective_map([A,B,C,D],[P,Q,R,S])[0]

Then pt is an instance of PlaneTransformation, and

F = pt.point_map

is a Python function implementing the desired mapping C->C. The problem is, even given this F,  how to transform an image with it? Here is the limit of my skills. Perhaps somebody who knows how to make such image transformations gets some idea and wants to take over.

But I doubt it would be worth the trouble. It is easiest just to use Gimp's ready-made transform tools since they seem quite adequate for the job (post #4 by Ofnuts). And the result would be no better even if it were done by some fancy plugin.

By the way, here seems to be two traditions in terminology. I believe that what I, as a mathematician, call a "projective transformation", is the same thing as the tool Perspective transform in Gimp.
Reply


Messages In This Thread
fix distorted round - by denzjos - 10-23-2020, 08:47 AM
RE: fix distorted round - by rich2005 - 10-24-2020, 08:44 AM
RE: fix distorted round - by denzjos - 10-24-2020, 11:06 AM
RE: fix distorted round - by Ofnuts - 10-24-2020, 02:38 PM
RE: fix distorted round - by denzjos - 10-24-2020, 05:31 PM
RE: fix distorted round - by Ofnuts - 10-25-2020, 05:37 PM
RE: fix distorted round - by denzjos - 10-25-2020, 06:29 PM
RE: fix distorted round - by Ottia Tuota - 10-26-2020, 07:02 AM
RE: fix distorted round - by Ofnuts - 10-26-2020, 10:24 AM
RE: fix distorted round - by Ottia Tuota - 10-26-2020, 05:09 PM
RE: fix distorted round - by Ottia Tuota - 10-30-2020, 07:26 AM
RE: fix distorted round - by denzjos - 10-26-2020, 08:01 AM
RE: fix distorted round - by Ottia Tuota - 10-28-2020, 05:14 PM

Forum Jump: