Fred's ImageMagick Curves script to duplicate PS curves

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
jkeilson
Posts: 7
Joined: 2013-07-09T20:33:26-07:00
Authentication code: 6789

Fred's ImageMagick Curves script to duplicate PS curves

Post by jkeilson »

Hi all, I'm trying to use Fred's ImageMagick Curves Script to duplicate Photoshop Curves filter settings. I loaded the preset into Photoshop and wrote down the x/y pairs of the light (0-255) settings of the RGB combined curve.

I've attempt it on the image below. It doesn't seem to match exactly. Is this because the formula for the curve is different from Fred's to PS?
Any suggestions for getting it closer? Thanks in advance.
-Jon

Using:
./curves.sh -s 250,255 -g C "0,18 31,19 64,62 86,100 110,139 124,159 142,181 161,200 194,223" wedding.jpg weddingtest7.jpg

Original:
Image

Goal:
Image

My results:
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by fmw42 »

My curves script nominally works in the range of 0 to 100 for each of x,y. You can change it to 0 to 255, if you want.

But note that it automatically adds 0,0 and 100,100 (or 255,255) as the end points. That may make changes relative to PS.

Since your list of control points does not include x=255, I am not sure what PS will do. Will it automatically add 255,255 or 255,233. You can duplicate either behavior in curves by adding the appropriate end points.

My script uses Catmull-Rom splines. I have no idea what PS uses. My script works on each channel with the same curve. I do not know if PS does the same or converts to some space such as HCL and applies it to the L channel and then converts back.


The other thing to consider is what profile PS has assigned to the image and what profile or colorspace the original image is using in IM. Also PS adds Dot Gain and IM does not know about that. Check your settings in the Color Settings panel of PS.

Also PS clips the data. You can see it uses 0.1 for blackpt and white point by opening the Options panel for curves.

You can duplicate that by using either -auto-level or -contrast-stretch 0.1% as a preprocess in IM.

My guess is that IM and PS are not using the same color profile. PS usually resets it to Adobe RGB. IM uses sRGB by default unless there is a profile. My script does not particularly do anything with the profile other than what IM might do automatically when using -clut.

Your input jpg file has no detectible profile. Thus IM will assume sRGB colorspace. PS will like add its Adobe RGB color profile unless you change the Color Settings panel to prompt you what profile to use.
Last edited by fmw42 on 2013-07-10T10:29:13-07:00, edited 1 time in total.
jkeilson
Posts: 7
Joined: 2013-07-09T20:33:26-07:00
Authentication code: 6789

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by jkeilson »

Thanks for the fast response and for the useful scripts!

I'm working through all of the items you listed. It seems to work better using 0-255 then when I attempted 0-100. I also attempted to add those endpoints in PS but it doesn't make a significant change since it allows the ends to not be at 0,0 and 255,255.

I just attempted with an image with specifically sRGB color profile and received a similar result.

I have a feeling it's related to the note you mentioned regarding the curve.
My script uses Catmull-Rom splines. I have no idea what PS uses. My script works on each channel with the same curve. I do not know if PS does the same or converts to some space such as HCL and applies it to the L channel and then converts back.]
I attempted breaking out the individual red, green and blue values and processing the image each time using the script but ended up with a more extreme example. I even compared a single red color alteration in curves and it is slightly different so I think it must be related to curve and only adding to the issue by processing all 3.

Do you have any suggestions for manually matching the color values other than trial and error with values? Thanks again!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by fmw42 »

Sure, the best thing is to apply your PS curves to a hald image. Then bring that back to IM and apply that using -hald-clut.

convert hald:8 hald8.png

Apply your curves to hald8.png in PS. Then bring the save result (as png) back to IM. The

convert yourimage modified_hald8.png -clut resultimage.

Be sure to have the same profile in both PS and IM.


see

http://www.imagemagick.org/Usage/color_mods/#hald-clut

Note this only works for global color changes -- no spatially dependent processor or compression
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by fmw42 »

I just attempted with an image with specifically sRGB color profile and received a similar result.
Did you keep PS from changing the profile to Adobe RGB?
jkeilson
Posts: 7
Joined: 2013-07-09T20:33:26-07:00
Authentication code: 6789

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by jkeilson »

I checked in PS within the color settings it is set to sRBG for the image I'm testing with. Also on save it retains sRGB.

The -hald-clut method you mentioned totally solves my problem! The resulting image is just about spot on the same as when I process it within photoshop using the curves preset.

I compared the PS and -hald-clut IM version within the histogram, and although slight differences it seems to be very closer.
Thanks for all of your help here!
-Jon

PS processed image:
Image

IM processed -hald-clut image:
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by fmw42 »

Just so that I can follow up with my curves script, can you take screen snaps of the curves panel showing your break points and also a screen snap of the options panel from the curves panel. There are several options and I would like to know which mode you are in. One mode applies the curve to each RGB channel. Another mode appears to convert to some colorspace such as HSL or HCL or the like and applies the curve to just the L channel and then converts back. You get different results depending upon which mode you were in. Also I am puzzled why your list of control points does not include one for x=255.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by GreenKoopa »

jkeilson wrote: The -hald-clut method you mentioned totally solves my problem! The resulting image is just about spot on the same as when I process it within photoshop using the curves preset.

I compared the PS and -hald-clut IM version within the histogram, and although slight differences it seems to be very closer.
You can use hald-clut to get as close as you need. Make sure you are processing and saving files in 16-bit with IM and PS. Then increase your hald level from 8 to 12 or even 16.
jkeilson
Posts: 7
Joined: 2013-07-09T20:33:26-07:00
Authentication code: 6789

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by jkeilson »

Hi Fred, sure below is the screenshot of the preset I was using in PS. Does this help? I didn't know enough about the options panel to make changes within PS. Regarding the plot points I was using the combined curve of all RGB. I tried including 255 but I wasn't sure it was necessary when you note the max below as 250,255?

./curves.sh -s 250,255 -g C "0,18 31,19 64,62 86,100 110,139 124,159 142,181 161,200 194,223" wedding.jpg weddingtest7.jpg

Curves:
Image

Curves options:
Image
jkeilson
Posts: 7
Joined: 2013-07-09T20:33:26-07:00
Authentication code: 6789

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by jkeilson »

GreenKoopa, does hald 16 provide better accuracy?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by fmw42 »

jkeilson wrote:GreenKoopa, does hald 16 provide better accuracy?
If you are running IM at Q16, you could get better quality/accuracy using a higher hald than hald:8. From Anthony's page

"More typically you would use at least a level 8 Hald (the default), which will hold a color cube with 64 colors per side, or 64^3 = 262144 colors, and produce an image that is 512x512 pixels in size. and saves into into an approximate 10Kbyte PNG image. This is not all 8 bit colors but is quite good.

For a HALD image with every 8 bits color, you would need a level 16 version, producing a 4096x4096 image."
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by fmw42 »

What are the other color curves? Have they been applied to your image also?
./curves.sh -s 250,255 -g C "0,18 31,19 64,62 86,100 110,139 124,159 142,181 161,200 194,223" wedding.jpg weddingtest7.jpg
This set of break points does not seem to match what you have in PS curves diagram. The last break point on your curve is higher than x=194 (out of 255). It looks at something very close but slightly less than x=255. Also I am not sure why you restricted my curves script to x=250. To match PS you would need to use -s 255,255.

I note that the only odd thing is that in your break points, you do not go all the way to x=255 (or even 250). When I do that in my PS, it leave a straight horizontal line. Thus in your case it would extend from 194,223 with a straight line going to 255,223 rather than splining between those two points. My script will add 255,255 automatically and will spline all the points. So there will be some difference between the two. I do not know if that is enough to make the difference you are seeing.

My old PS CS does not have the SHOW options in the panel. I understand the histogram option shows the histogram. I am not sure what the Channel Overlays option does?

I will have to experiment, but only with break points that contain 0,0 and 255,255 and see if I see any substantial difference between PS and my curves.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by GreenKoopa »

Some PS color modifications can't be reproduced using -hald-clut. Others can be perfectly reproduced with a simple -clut.
jkeilson wrote:GreenKoopa, does hald 16 provide better accuracy?
You mentioned slight differences, and interpolation is the source of the difference. hald:x creates an image with x^6 color samples. The more data points available, the less interpolation needed. How much better accuracy depends on your image and color modification. The default hald is 8 because it is a good compromise between accuracy and memory use. You could quantify the difference using IM's compare utility. In short, as the hald number increases you will definitely see accuracy increase, but memory use will increase much faster.
jkeilson
Posts: 7
Joined: 2013-07-09T20:33:26-07:00
Authentication code: 6789

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by jkeilson »

Fred, so that last point is the 250,255. I set this as the max, but I also tried setting a max of 255,255 and then adding the plot point 250,255. There wasn't much of a difference when making this change though. Other then that it should match up in terms of breakpoints. Want me to post the PS preset as well?

The last breakpoint:
Image

The channel overlays just removes the visualization of the red, green, blue individually under the black RBG line visualization.
-Jon
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fred's ImageMagick Curves script to duplicate PS curves

Post by fmw42 »

My point was that you left out that point ( 250,255 ) when using my curves and did not scale it with -s 255,255 in order to be a more fair comparison with PS
./curves.sh -s 250,255 -g C "0,18 31,19 64,62 86,100 110,139 124,159 142,181 161,200 194,223" wedding.jpg weddingtest7.jpg
So you would need this to be the following for my script

./curves.sh -s 255,255 -g C "0,18 31,19 64,62 86,100 110,139 124,159 142,181 161,200 194,223 250,255 255,255" wedding.jpg weddingtest7.jpg
Post Reply