I had many issues replicating the generated curve formula example found in the ImageMagick web site on my Windows platform until now.
I've finally worked it out and would like to share it with you.
The FX formula from the ImageMagick web site is needed to specify a custom curve adjustment in ImageMagick for a particular channel just like Photoshop. However, the examples on the web site can be rather misleading when you try to replicate it using Windows.
So my question was:
What are the exact steps I need to follow in order to replicate the example from the ImageMagick web site on Windows?
Preliminaries:
I'm currently running Windows 7 and GnuPlot 4.6
Here are the steps.
Install GnuPlot.
Download the fx_control.txt file from http://www.imagemagick.org/Usage/color_mods/fx_control.txt. This file contains the control points. (These are represented by x/y coordinate pairs of 4 special points on the curve graph).
If you need to replicate a curve in Photoshop, you can grab the coordinates from the curves window in Photoshop. Note: When I open the file in NotePad++ the x&y coordinates are on one line, however every set of control points are on a separate line. So if you are wanting to modify the control point in the file I suggest you install and use notepad++
.
Open GnuPlot. Once loaded you will see a command prompt similar to DOS.
Paste the following text behind the gnuplot>
prompt and hit return:
f(x) = a*x**3 + b*x**2 + c*x + d
Now paste the following text into Gnuplot and hit return. In this example, I'm assuming you have saved the 'fx_control.txt' file to the root directory on your C: drive.
fit f(x) "c:/fx_control.txt" via a, b, c, d
If you have done everything right, you should have seen a heap of text appear in GnuPlot.
Now paste the following text into Gnuplot and hit return.
print a,"*u^3 + ",b,"*u^2 + ",c,"*u + ",d
GnuPlot has now displayed the curve formula which you use with the ImageMagick FX function. The result matches the example on the ImageMagick website and should be:
7.55952380952381*u^3 + -11.9464285714286*u^2 + 5.08690476190476*u + 0.2
To display a plot of this function, copy'n'paste the following line to the gnuplot>
prompt:
plot [0:1][0:1] 7.55952380952381*x**3 + -11.9464285714286*x**2 + 5.08690476190476*x + 0.2
You should see something like this:
I hope these steps help you!
By Anthony, the Author of ImageMagick Examples
NOTE: while the final curve shown in the above is correct, only the small segment of the curve between 0.0 and 1.0 (horizontally) and limited to 0.0 to 1.0 (vertically) is used.
To get gnuplot to limit the results of the copy-n-pasted function to those bounds use a command such as...
plot [0:1][0:1] 7.55952380952381*x**3 + -11.9464285714286*x**2 + 5.08690476190476*x + 0.2
You can also add the control points to the graph so you can see how well they fit...
plot [0:1][0:1] 7.55952380952381*x**3 + -11.9464285714286*x**2 + 5.08690476190476*x + 0.2, "c:fx_control.txt"
Just one small note that should be made clearer. - Imagemagick uses 'u' where gnuplot uses 'x' (though that can be changed) - Imagemagick uses ^ where gnuplot uses ** for mathematical exponentiation (power-of) operation. keeping this in mind will make converting the gnuplot output to ImageMagick usage much easier.
One final note. You can generally get help on using ImageMagick a lot faster by posting, or searching the ImageMagick Users Forum.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With