Page 1 of 1
Curves Adjustments - math help
Posted: 2010-12-19T23:01:38-07:00
by GreenKoopa
I would like to make a 'Curves' color adjustment. My problem is generating polynomial coefficients given control points.
A curves adjustment can be achieved using
-function Polynomial (
usage example). The problem is deciding on coefficients. In an image program such as Photoshop or GIMP, you select a few control points that map input values to output values. There is a
usage example that gives some tips on calculating polynomial coefficients given a few control points, but not for Windows. Does anyone know a way to do this on Windows or using a website?
Re: Curves Adjustments - math help
Posted: 2010-12-20T13:27:56-07:00
by fmw42
you can use control points in my script, curves, if you are on linux/mac or have cygwin/windows. then you don't need a polynomial as it uses the Catmul-Rom spline to interpolate the points.
Re: Curves Adjustments - math help
Posted: 2010-12-20T18:54:48-07:00
by anthony
It is posible for this to be built into IM. But some programmer will need to encode the new function to generate the curve.
Distorts for example internal matrix solving to calculate the function coefficients it needs for distorting images. Maybe it can do curve fitting, as it does output results using verbose!
How many points are you thinking of using? Can you give an example?
Another possibility is to generate a
LUT gradient using -sparse-colors, though the results may not be very exact.
Re: Curves Adjustments - math help
Posted: 2010-12-20T19:08:26-07:00
by anthony
Here is a way of generating a
Shepards Sparse Color LUT gradient
generated using the same points used for the '
curves example'
0.0,0.0 1.0,0.9 0.2,0.8 0.7,0.5
To generate a gradient image is 1000 pixels long, the first number of the above coordinate pairs become a y value *1000. The second number becomes a Gray value.
Code: Select all
convert -size 20x1000 xc: -sparse-color Shepards \
'0,0 black 0,1000 gray(90%)
0,200 gray(80%) 0,700 gray(50%)' \
-rotate -90 shepards_curve_gradient.png
Here is the profile graph of the generated gradient (using a gnuplot based
im_profile script).
The curve generated in not very smooth, but then it isn't so much of a curve generation as a interpolation method.
But once you have a gradient, you can use it as a LUT to adjust your image.
Re: Curves Adjustments - math help
Posted: 2010-12-20T20:50:19-07:00
by fmw42
anthony wrote:It is posible for this to be built into IM. But some programmer will need to encode the new function to generate the curve.
Distorts for example internal matrix solving to calculate the function coefficients it needs for distorting images. Maybe it can do curve fitting, as it does output results using verbose!
How many points are you thinking of using? Can you give an example?
Another possibility is to generate a
LUT gradient using -sparse-colors, though the results may not be very exact.
Anthony,
Interesting use of Sparse Color interpolation! But am I correct in that using Sparse Color is approximating and not interpolating in that it will not necessarily go exactly through the control points specified.
I also think it would be rather easy to generate a lut via IM as a new function (or directly apply the lut via -clut within the new IM function) from control point pairs (input, output in range 0 to 1 or 0 to 100% or 8-bit or 16-bit values, whatever you want) that are interpolated (go exactly through the control points) using Catmul-Rom spline as in my curves script. If you want to discuss, let me know. Of course it is not interactive, but someone could implement that in PHP if they wanted. The Catmul-Rom interpolation is rather simple. One takes 4 points and computed the interpoation for the region between the second and third. Two added points are needed, one at the beginning and one at the end, but they are just straight line extension of the first and last intervals from the given control points.
Here is your same set of points from my curves script:
Fred
Re: Curves Adjustments - math help
Posted: 2010-12-20T21:26:31-07:00
by anthony
The definition of Sparse color is that the specified points are fixed. If the point is an actual pixel location (add 0.5)
then that pixel will be guaranteed to have the color specified.
They will only become approximate if you continue processing the resulting gradient image with things such as BLUR.
The thing of greater concern is the lack of other color processing functions. Shepards for example will always have a zero gradient slope at the specified points. Especially on the ends of the curve. Which is not particularly nice for some CLUT uses. It also has a tendancy for the curve to 'dip' toward an average value when far away from any control
points.
For example try this...
Code: Select all
convert -size 20x1000 xc: -sparse-color Shepards \
'0,0 black 0,1000 black
0,200 gray90 0,700 gray90' \
-rotate -90 miff:- | im_profile -
The center of the curve 'sags' downward between the two 90% gray points!
It is not a particularly nice interpolation, and is a 2d interpolation being used to generate a 1D curve.
A better method would be to use Fred Wienhaus's special gradient generator script (above)
Polynomial by contrast typically has the highest gradient slope at ends.
Re: Curves Adjustments - math help
Posted: 2010-12-20T21:29:54-07:00
by fmw42
see my curve that I generated to emulate your set of points. see above -- edited to add graph
Re: Curves Adjustments - math help
Posted: 2010-12-21T00:24:07-07:00
by GreenKoopa
I think I need to take a break from IM to get a portable cygwin and finally learn some Linux. Gravity is about to overtake friction on this steep learning curve.