Applying a formula to an image (Curves... again) #7317
-
Hi, I feel that this probably a very redundant question, but it has me stumped. I know I'm doing something wrong as I don't fully understand how this thing works (I'm not a programmer by trade) Anybody has any idea how to fix this? Here's the Imagemagick -version info |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 14 replies
-
Imagemagick -fx expressions assume u,v etc are image coordinates in the range 0 to 1. Are you coefficient scaled appropriately for that range? If you are on a Unix-like system or can use Window 10/11 unix or Cygwin, then you could try my script, curves, at http://www.fmwconcepts.com/imagemagick/curves/index.php to do a spline fit to a list of control points. The points can be in the range 0 to 100 (percent) or 0 to 255 for 8-bit values or whatever you want as controlled by the scale arguments. |
Beta Was this translation helpful? Give feedback.
-
If you want to apply the same mapping to all images, you could process it once using HALD images and then apply it to many image using -hald-clut. See https://imagemagick.org/Usage/color_mods/#hald-clut. You can create the original HALD image and transfer it to Photoshop. The process the HALD image with the mapping you like. Then save that result and bring it back to Imagemagick and use it with -hald-clut to process many images. |
Beta Was this translation helpful? Give feedback.
-
If you are using coordinates for your points in the 8-bit range from Photoshop, then divide the values by 255 and do your fit again to get the 2nd order coefficients that you want for Imagemagick -fx equation. |
Beta Was this translation helpful? Give feedback.
-
Values of Perhaps the formula you give is suitable for values in the range 0 to 255. If so, then try this:
|
Beta Was this translation helpful? Give feedback.
-
No simple formula will map one input value (such as 1) to multiple output values (such as 0 and 5). |
Beta Was this translation helpful? Give feedback.
-
I loaded your points. Assuming they mean percent in range 0 to 100 as per the values you provided, then when using the curve fitting tool at https://planetcalc.com/8735/ Then using -fx on a grayscale version of the lena image using snibgo's approach
gives me a totally white output. |
Beta Was this translation helpful? Give feedback.
-
OK, this time I used my approach to divide the control points by 100. and got this fit with this 2nd order equation y=1.1271x2−0.3851x+0.0614
The result on the lena image was |
Beta Was this translation helpful? Give feedback.
-
If the formula is suited for a range 0 to 100, then we need to multiply (not divide) u by 100, then divide the result by 100.
This gives the same result as your:
|
Beta Was this translation helpful? Give feedback.
-
Yes. These two commands give virtually the same result:
We can simplify the first of these, to avoid dividing by 100 at every pixel:
|
Beta Was this translation helpful? Give feedback.
So using your formula with snibgo's method on the lena gray image, I get
magick lena_gray.png -fx "uu=u*100; (4.034e-04*uu*uu*uu -4.908e-02*uu*uu + 1.777*uu + 1.913e-01)/100" lena_gray_cubic.png
You could also use uu^3 in place of uuuuuu. Similarly for uu^2 in place of uu*uu. I am not sure which would be faster.