Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Perspective transform revisited
#1
Here is a new plugin to perform Perspective transform (=projective transformation for a mathematician), based on two 4-anchor paths. To get it, go to

http://kmarkku.arkku.net/Miscellaneous_p...aster.html

edit: http://kmarkku.arkku.net/Perspective_tra...aster.html (url changed - rich)

move to the bottom row and click the Download button. You get a .zip file. Unzip it and put the sole file it contains (perspective_transform.py) to your user's plug-ins folder and restart Gimp. The plugin will be in Gimp's menu at Filters > Distorts > Perspective transform > ...

The plugin transforms the active layer. It asks for two paths, Source and Target. Both are supposed to be 4-anchor paths. The transformation will send the anchors of the Source onto the anchors of the Target. So, if you have a picture and in it you have some four specific points A,B,C,D that you would like to move to some other points P,Q,R,S, then:
  1. Create the Source path so that it has A,B,C,D as its anchors. Don't make it closed.
  2. Create the Target path so that it has P,Q,R,S as its anchors. Don't make it closed. Ensure that the ordering of P,Q,R,S in the Target path corresponds to the ordering of A,B,C,D in the Source path (excepting possible reversal).
  3. Make sure that the layer you want to transform is the active one.
  4. Open the plugin's GUI.
  5. If you want to retain the original layer as it is, so that the plugin will work on a copy, click the bottom entry (Keep the original layer?) to set it to Yes.
  6. Run the plugin.
  7. If the plugin runs ok and produces some result but it is somehow wrong, repeat but this time click the entry Use the target reversed?  to Yes.
  8. If still not happy, look at the example case below.
  9. If the result is ok, you may wish to do Image > Fit Canvas to Layers.
Some inputs make the job impossible: the transformation would send some parts of the layer to infinity. This problem is inherent in the Perspective (projective) transformation; infinities do occur, and if they happen to lie in the region of the layer, then nothing can be done. If such happens, the plugin raises an error (an Exception). Your layer may be excessively large; crop it to its essential contents and try again. Or change the Source or Target path a little and try again.

The plugin also contains options to draw two special lines connected with infinities, provided that they intersect the image area. I say nothing about those here. You can just ignore them.

Example: I use the picture by Denzjos, which was what lead to this plugin; see https://www.gimp-forum.net/Thread-fix-distorted-round

   

The following picture tries to show the paths Source (red) and Target (blue) that I used. (The clock is dimmed just to show the paths better)

   

The Source path (red) is chosen from the hours 12,3,6,9 on the dial and left unclosed. The Target path (blue) has its anchors at the corners of a square tilted by 45 degrees. I made it as follows:
  1. Make a square selection.
  2. Do Selection to path. Rename the path to Target.
  3. Dismiss the selection.
  4. Rotate the Target by 45 degrees.
  5. Move and scale the Target so that it is close to the Source. (Not necessary.)
  6. Delete one edge from the Target, so that it is open at the same side as the Source.
Then, when I ran the plugin with these Source and Target, the result was somehow wrong. So I tried again but now using the target reversed. The result was reasonably good:

   


That's that. I attach here also the xcf file in case you wish to look at it more closely:


.xcf   clock.xcf (Size: 1.35 MB / Downloads: 312)

The plugin was quite a rushed job. I mostly just copied pieces of code from an unpublished work. If you have problems with the plugin, please be kind enough to tell me. And you will certainly find points that could be made better. My knowledge about Gimp is rather rudimentary, so please make suggestions.
Reply


Messages In This Thread
Perspective transform revisited - by Ottia Tuota - 10-28-2020, 05:11 PM
RE: Perspective transform revisited - by Krikor - 10-28-2020, 07:04 PM
RE: Perspective transform revisited - by denzjos - 10-29-2020, 05:15 PM
RE: Perspective transform revisited - by Blighty - 11-03-2020, 11:16 AM
RE: Perspective transform revisited - by Krikor - 11-03-2020, 02:12 PM
RE: Perspective transform revisited - by denzjos - 11-05-2020, 04:40 PM
RE: Perspective transform revisited - by Krikor - 11-05-2020, 06:04 PM
RE: Perspective transform revisited - by denzjos - 11-06-2020, 09:10 AM
RE: Perspective transform revisited - by Krikor - 11-10-2020, 09:04 PM
RE: Perspective transform revisited - by Krikor - 11-11-2020, 12:50 PM
RE: Perspective transform revisited - by akovia - 11-16-2020, 06:11 PM
RE: Perspective transform revisited - by Krikor - 12-01-2020, 12:45 PM
RE: Perspective transform revisited - by denzjos - 12-03-2020, 02:17 PM
RE: Perspective transform revisited - by denzjos - 12-03-2020, 05:42 PM
RE: Perspective transform revisited - by denzjos - 12-04-2020, 08:58 AM
RE: Perspective transform revisited - by Krikor - 12-05-2020, 07:06 PM
RE: Perspective transform revisited - by denzjos - 12-06-2020, 12:02 PM

Forum Jump: