Posts: 236
Threads: 26
Joined: Mar 2020
Reputation:
29
Operating system(s):
- Windows (Vista and later)
Gimp version: Don't know yet
06-06-2021, 10:50 AM
(This post was last modified: 06-06-2021, 11:11 AM by Ottia Tuota.)
I happened to find a simple algorithm to smooth paths of linear line segments. The site is
https://web.archive.org/web/201903270015...ERPOLATION
The algorithm is a simple geometric construction of control points. Certainly there are much more sophisticated algorithms but this is simple and probably sufficient to most purposes. I made a faithful implementation of it. (I manipulated the formulas a little which gave different insight to their meaning. But I refrain from explaining it here.)
To get the plugin, go to
http://kmarkku.arkku.net/Path_modify_fil...aster.html
scroll to the bottom, and click the right download button ("Simple smooth"). You get a zip file. Unzip it and place the one file it contains (simple_smooth_path.py) in your user's plug-ins folder. Then (re)start Gimp. To use the plugin: in the Paths tab, right-click a path and follow the links Tools > Modify path > Simple smooth.
A picture tells all:
This was done with default values. Note that the smoothed path passes through all anchors of the original path. In fact, all anchors are preserved (with one exception, see below) and no new anchors are created; only new handles are made. So the plugin works differently from my recent corners-rounding plugin. To compare the two plugins, look at this:
In
https://www.gimp-forum.net/Thread-Roundi...6#pid23626
Rich recalled some old smoothing plugin. By my experiments the effect differs slightly from that of my simple plugin. I guess it uses some more sophisticated algorithm. This new simple plugin uses a simple local geometric construction, and it, for instance, makes no effort to minimize the deviation of the smoothed path from the original one.
Some words about the new plugin:
The GUI asks for 'strength'. Default is 1. Smaller values give tighter bends. There is also an option on how to use the selection: with it you can restrict the effect to a smaller part of the path.
The only option that needs explaining is that the plugin asks "Remove superfluous anchors from straight edges?" Default is "Yes". An example: Suppose you make a rectangular selection, rotate it, and apply "Selection to path". You get something like on the left, with lots of anchors:
If you apply here the plugin without removing the superfluous anchors you get what you probably were not after. Namely, all anchors are preserved and the result is not good. But if you keep the default value "Yes" you get what is seen on the right. That is what probably was wanted. Only 4 anchors are kept.
By the way, I had some problems with this option. I fear it may cause trouble in some cases. If so, please tell me and I shall see what I can do.
Posts: 1,144
Threads: 178
Joined: Sep 2018
Reputation:
114
Operating system(s):
- Windows (Vista and later)
Gimp version: 2.10
Ottia Tuota, nice job. I wonder if it is possible in gimp to correct curved distortion using curved paths as reference in combination with the gimp Filters / Distorts / Lens Distortion. In PS there was a plugin that correct such a distortion using curves (paths?).
Distorted :
Corrected :
Posts: 236
Threads: 26
Joined: Mar 2020
Reputation:
29
Operating system(s):
- Windows (Vista and later)
Gimp version: Don't know yet
Why not if it is done in Photoshop (if 'PS' means Photoshop). But not by me. I have neither the skills nor the time. But those in the G'mic forum may be interested. Who knows, perhaps there already is something like it? Or perhaps some better coder here would want to take the job?
I have some thoughts. The problem resembles very much what I did with path transformations. (But I was transforming paths, not images!) In:
https://www.gimp-forum.net/Thread-Path-t...4#pid19014
there is the pdf file introducing a transformation F0 from 16 control points. It also describes formulas for a simplified version (Section 1.1.3), and that is almost what you are now asking for. It maps a rectangle onto a curvy quadrilateral, where the curvy quadrilateral is made of four sides, each being a Bezier arc. So there are the formulas. What is missing, is an implementation of those formulas to distort an image. And unfortunately, in your problem we would need the inverse transformation, but perhaps there is some way around that.
So, if you want to ask the question on the G'mic forum, you may bring to their attention that pdf of mine, and from there the transformation F0 and in particular the simplified version (Section 1.1.3).
(And I want to mention that that 16-point transformation F0 was not new, after all, just as I suspected. I later found the formula in Chapter 14 of:
Thomas W. Sederberg: Computer Aided Geometric Design. (2012) Brigham Young University, Faculty Publications. 1.
https://scholarsarchive.byu.edu/facpub/1/
But so far I have not seen anywhere mentioned the simplified version dealing with curvy quadrilaterals. But judging from that screenshot of the Photoshop plugin, something similar may be behind the plugin.)
I make it sound simple: Here we have the formulas, and we just should implement them. But there are certainly problems to solve. I am sorry, but I am not even thinking of trying. For one thing, I don't know how to implement image transformations.
Posts: 6,340
Threads: 272
Joined: Oct 2016
Reputation:
563
Operating system(s):
Gimp version: 2.10
Posts: 1,144
Threads: 178
Joined: Sep 2018
Reputation:
114
Operating system(s):
- Windows (Vista and later)
Gimp version: 2.10
06-24-2021, 05:25 PM
(This post was last modified: 06-24-2021, 05:31 PM by denzjos.)
@ Ottia Tuota : Ottia, it was just an idea. I tought one could extract some coordinates from the paths (in this case circles - see picture - in the small square is the picture), do some calculations and put the values in the gimp 'Filters / Distorts / Lens Correction' filter (that correct an image). No need to take any action. Thank you for your reply (and for the work you have done with the gimp paths).
(06-24-2021, 05:18 PM)Ofnuts Wrote: I think you want this:
http://benpaulthurstonblog.blogspot.com/...ormal.html
@Ofnuts : I see the same question is made in 2016, since then, nothing of this kind is made in gimp, so few people need such a thing.
Posts: 236
Threads: 26
Joined: Mar 2020
Reputation:
29
Operating system(s):
- Windows (Vista and later)
Gimp version: Don't know yet
06-24-2021, 07:15 PM
(This post was last modified: 06-24-2021, 07:31 PM by Ottia Tuota.)
(06-24-2021, 05:18 PM)Ofnuts Wrote: I think you want this:
http://benpaulthurstonblog.blogspot.com/...ormal.html
Yes, I know that one. Some years ago I wasted a whole day trying to figure it out. I came to the conclusion that, contrary to what he claims, the mapping is not conformal. I don't remember the details, but it went like this: For a mapping to be conformal, it is necessary and sufficient that it (taken to be a mapping on the complex plane) has a derivative as a complex function and that the derivative is non-zero. I saw that his mapping cannot have a derivative as a complex function.
But that is not crucial. Correcting a distortion need not be conformal? Thanks to Thurston, I got a new idea in my head, and then finally, after some logical leaps, I came to the 16-point transformation (which, as I explained, was already invented by someone else). It, or the simplified version, is more general, and I think more beatiful mathematically. What it is lacking is that it should be made into some practical form where it would be easy to use and apply to images, not paths. That would be work for some better coder.
(06-24-2021, 05:25 PM)denzjos Wrote: @ Ottia Tuota : Ottia, it was just an idea. I tought one could extract some coordinates from the paths (in this case circles - see picture - in the small square is the picture), do some calculations and put the values in the gimp 'Filters / Distorts / Lens Correction' filter (that correct an image). No need to take any action. Thank you for your reply (and for the work you have done with the gimp paths).
Ok, I see you had a practical idea (more practical than my ramblings). I think that could be done. But it would require some understanding of how Gimp's Lens Distortion works and what the parameters mean. I have no such knowledge, and I know practically nothing about lens distortions. And I don't understand what that pretty picture you posted means. There must be some theory there? Perhaps you have some useful link?
(Or perhaps one could just try without any knowledge. I have to think about this.)
Posts: 7,132
Threads: 155
Joined: Oct 2016
Reputation:
1,003
Operating system(s):
Gimp version: 2.10
@denzjos
Not Gimp. Perhaps the Krita mesh tool : https://i.imgur.com/yu3j5Sg.jpg
Posts: 1,144
Threads: 178
Joined: Sep 2018
Reputation:
114
Operating system(s):
- Windows (Vista and later)
Gimp version: 2.10
@Ottia Tuota : I tried to correct distortion with the 'Lens Distortion' filter and get a result that is about correct. First I straighten the photo using the 'Measure Tool' to set the end points of the green top line horizontal. Then a use the 'Lens Distortion' filter to correct the photo with an acceptable result. I just had to use the 'Shear Tool' to make some minor correction. So, it is not so easy as I first thought. I thought it was possible to use the difference between the center points of the circles to calculate the 'Shift X' and the 'Shift Y' from the 'Lens Distortion' filter and then make some calculations for the 'Main' parameter to straighten the curved lines. But there is more involved as one have to use the 'Edge' parameter also and I think it is difficult to calculate this parameter. Tuota, feel no need to put much energie solving this problem and thank you for your answer.
Corrected with the 'Lens Distortion' filter :
Detail from the circles in the previous post (the middle lines are the connections from the center points of the circles) :
Posts: 236
Threads: 26
Joined: Mar 2020
Reputation:
29
Operating system(s):
- Windows (Vista and later)
Gimp version: Don't know yet
After seeing the post by Rich about the Mesh tool in Krita, I decided not to do anything here. Better minds have already made tools that are superior to anything I could produce.
You are trying to use existing tools. Ok. I cannot help since I have never used the Lens distortion tool and I don't know how it works. Have you tried that Mesh tool in Krita?
When I looked at the picture Rich posted I got the feeling that the "simplified version of the 16-point transform" that I mentioned in post #3 is nothing new either (well, that is just what I expected). Namely, the screenshot looks like there is a "curvy quadrilateral with each side a Bezier arc". The control points (handles) look just like that. So, my great idea is maybe already invented and implemented.
I think I shall leave transforming images to those who can do it better. I stick to transforming paths. There I can perhaps do something nobody else has done or is doing, at least not in Gimp.
Posts: 236
Threads: 26
Joined: Mar 2020
Reputation:
29
Operating system(s):
- Windows (Vista and later)
Gimp version: Don't know yet
06-27-2021, 01:06 PM
(This post was last modified: 06-27-2021, 01:10 PM by Ottia Tuota.)
A bug fix. New version 0.2 is at the old place
http://kmarkku.arkku.net/Path_modify_fil...aster.html
For an explanation of the bug and a workaround of a difficulty, see
https://www.gimp-forum.net/Thread-Simpli...8#pid24258
|