Post Reply 

Automate the correction of perspective and size

Mar 11, 2014, 20:32
Post: #1
Automate the correction of perspective and size
Hello,
I am looking for a plugin or script to correct the perspective of a picture just by selecting 4 points (via free select tool, for example) and setting a height / width ratio, a measure of height and / or width with the overview of the correction if possible (the ratio and 1 measure, height or length, at choice or two measures).

The result would be that the 4 points are recovered in a parallelogram with desired dimensions.

It would also require that the canvas size may increase if the image became too large via a checkbox (not to lose part of the image).

I know this is probably asked a lot but often having to do this kind of correction, and having no concept of creation of script or plugin for gimp, I hope to find someone here who can help me.
Find all posts by this user
Quote this message in a reply
Mar 12, 2014, 03:58
Post: #2
RE: Automate the correction of perspective and size
We effectively get a rectangle (incidentally, the rectangle is a parallelogram Tongue).
Do you think you could do it?
Find all posts by this user
Quote this message in a reply
Mar 12, 2014, 14:17 (This post was last modified: Mar 12, 2014 14:25 by Levi59.)
Post: #3
RE: Automate the correction of perspective and size
In general, I measure a length on the image, the size of which I know, and I apply a known ratio as calculated with the true dimensions (I always use a rectangular vertical repository, such as a window):

A window of 2x1 (HxW) therefore has a ratio of 2/1 or if the image "W = 1253 pixels" then "H = 2506 pixels"

We should be able to define the lengths of at least 2 sides to be able to reconstruct a rectangle.
If you set that AB and CD are the horizontal and vertical BC and AD.
It suffices to choose the desired lengths of AB and BC, or choose a "ratio" option and give the actual size of the repository and the side so the length is fixed.

I attach a picture (sorry in french is the language of my interface) how I imagine the options.


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
Mar 12, 2014, 23:42 (This post was last modified: Mar 12, 2014 23:42 by Levi59.)
Post: #4
RE: Automate the correction of perspective and size
I'll try to pick in my (very) old memories of college to ask a question about the operation of the perspective correction tools.

When you modify an image by moving the corners of this tool, you can see a matrix record corrections to apply.

Assuming that we know:
-coordinate of the 4 points that form a quadrilateral and we know that we must find a rectangle.
-AB and CD are the horizontal and BC and AD the vertical.
-the final dimensions LxW

If we decide that A is the reference point then the new coordinates will be calculable and it should be possible to calculate a matrix representing the transformation, right?
Would it not suffice "to give" to the perspective correction tool this matrix to enable it to make the correction?

It was at this moment that I regret being fallen asleep during math class because I do not remember much more.
Find all posts by this user
Quote this message in a reply
Mar 13, 2014, 01:11
Post: #5
RE: Automate the correction of perspective and size
David Krumholtz is never there when you need it...
Find all posts by this user
Quote this message in a reply
Mar 13, 2014, 09:50 (This post was last modified: Mar 13, 2014 09:53 by iForStyle007.)
Post: #6
RE: Automate the correction of perspective and size
(Mar 13, 2014 01:11)Levi59 Wrote:  David Krumholtz is never there when you need it...

Hey Levi,

There is a plugin for perspective correction(more or less), it lacks a live preview but you can undo & re-run the
plug-in using "shift + crtl + F"

Just drop the plugin into your correct plugin folder (path found via "Edit > Preferences > Folders > Plugins)

restart Gimp, then it will be in the sub menu "Filters > Distorts > Ez Perspective"

EZ Perspective
http://registry.gimp.org/node/24537#installation

Look over the usage tips *Especially about the focal length setting

*It will help to drag guides from the top/side rulers to help line things up

My result of your window with these settings:
- (I had to do a small shear to the right some) Shear
- To fix the transparency/clipped spots you can use the heal brush
or
like I did in the below photo(right side of pic)
-Heal-transparency (a resynthesizer filter) After found in "Filters > Enhance > Heal-transparency"
.
.
left pic, after applying EZ perspective | right pic, after shearing & applying heal-transparency
   

So in essence if you find the right settings & you have a bunch of photos with similar angle, it will become almost automatic.
That's my last mad-gimp scientist lab experiment for the night.

"In order to succeed, your desire for success should be greater than fear of failure." BC
[Image: 29uocaf.png]
iFS007 tut vids on YT ~ auto color B&W landscape tut
Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 14, 2014, 15:16
Post: #7
RE: Automate the correction of perspective and size
Rendering seems worse than mine made only with the perspective correction tool.

And if You must repeat several tests each time to find the right setting, it's not worth it ...
Find all posts by this user
Quote this message in a reply
Mar 15, 2014, 09:03 (This post was last modified: Mar 15, 2014 09:04 by iForStyle007.)
Post: #8
RE: Automate the correction of perspective and size
(Mar 14, 2014 15:16)Levi59 Wrote:  Rendering seems worse than mine made only with the perspective correction tool.

And if You must repeat several tests each time to find the right setting, it's not worth it ...

Sorry if it gotoverlooked on my settings pic, it renders bad on "()fast" option unless you check the "()good" option. I recommend using the good option after you have found the right settings.

----
*However, the creator of the plugin mentions an alternative Gimp *BUILT-IN* filter that has a preview ^_^ So here is but one more way to automate the process

1.
Filters > Map > Map Object... across "plane"

I still had to use the shear/skew tool, to straghten it a bit, but the results are better.

My settings with your window pic:
On the "Options" tab
- turn off "[]anti-aliasing" for a sharper final image
- Turn off "[]wireframe" for an easier preview
on the "Light" tab
-Lightsource type "No Light"
on the "Orientation" tab
-Under Rotation
X "5.0"
Y "-3.0"
Z "14.0"
Click Ok

2.
Use the Shear shear/skew tool, to shear to the right the vertical lines.

*Perhaps you could write a script that would do those two steps automatically,
Visit this user's website Find all posts by this user
Quote this message in a reply
Mar 15, 2014, 11:15
Post: #9
RE: Automate the correction of perspective and size
Looking for alternatives, without any success.

The obvious is Imagemagick but grabbing pairs of co-ordinates from Gimp to apply on a command line I think would drive the OP to insanity.

In theory one of the panorama stitching apps should match control points and distort accordingly. No joy with Hugin. Same applies to a Gimp image registration plugin, the sort of thing used for HDR sets. A least one has affine transform included. Can't get that to work either.

Again Gimp, The MathMap plugin bilinear interpolation. Works but is it any better or faster than a regular perspective transform. Not really, definitely not automatic, slower to apply but might be worth bearing in mind as it is scriptable.

[Image: U33Atso.jpg]

** https://www.gimp-forum.net/ now answering questions**
Find all posts by this user
Quote this message in a reply
Mar 16, 2014, 20:36
Post: #10
RE: Automate the correction of perspective and size
@rich, about the math plugin, if it can retain the settings after you first run it like other filters do, it could then be automatic, all you would have to do is leave gimp open or do the "save tool presets" option.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Scale image to specific size MattRothschild 1 499 Sep 15, 2017 11:13
Last Post: ythgilb
  PDB call to Image/Canvas size... ? Shadowes 3 586 Sep 1, 2014 22:31
Last Post: Shadowes
  Script-fu (gimp-context-set-brush-size size) ain't working Phoenix999 1 1,782 Aug 9, 2012 00:37
Last Post: Phoenix999

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS