Fred's ImageMagick Scripts : COLOR BALANCE

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
Post Reply
badabou
Posts: 54
Joined: 2008-06-23T06:12:24-07:00

Fred's ImageMagick Scripts : COLOR BALANCE

Post by badabou »

Hi,

The script "colorbalance" created by Fred seems to have a problem when a value other than "all" is used for the "region" parameter.

Here is an example:

Code: Select all

./colorbalance -c red -a 100 -r midtones star.jpg out.jpg
Result image:
Image

The same parameters but with Photoshop:
Image

Do you have any idea? If Fred goes here?

Thank's
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Fred's ImageMagick Scripts : COLOR BALANCE

Post by snibgo »

Fred probably will come along, but he may want to try with your original image.
snibgo's IM pages: im.snibgo.com
badabou
Posts: 54
Joined: 2008-06-23T06:12:24-07:00

Re: Fred's ImageMagick Scripts : COLOR BALANCE

Post by badabou »

That's right snibgo, here's the original 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 Scripts : COLOR BALANCE

Post by fmw42 »

Can you reproduce my examples?

I will look into seeing if the script has problems.

But note, my colorbalance is not the same technique as used in Photoshop and likely will not work comparably.

What version of IM are you using and on what platform?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fred's ImageMagick Scripts : COLOR BALANCE

Post by fmw42 »

My colorbalance script is working as programmed. But as I said above it is not the same algorithm as in PS.

Closest I can come is only approximate with

colorbalance -c red -a 25 968678original.jpg result1.jpg

or

colorbalance -c red -a 75 -r m -m 50 -t 200 968678original.jpg result2.jpg
badabou
Posts: 54
Joined: 2008-06-23T06:12:24-07:00

Re: Fred's ImageMagick Scripts : COLOR BALANCE

Post by badabou »

Fred, I looked at the source of the script and the variable $mid (-m) seems to be used anywhere. Is this normal ?

Thus, whatever its value, it has no impact on the final result.

Alternatively, is it possible to have a general method for the script is like Photoshop?

Thank's
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fred's ImageMagick Scripts : COLOR BALANCE

Post by fmw42 »

badabou wrote:Fred, I looked at the source of the script and the variable $mid (-m) seems to be used anywhere. Is this normal ?

Thus, whatever its value, it has no impact on the final result.

Alternatively, is it possible to have a general method for the script is like Photoshop?

Thank's

-r midtones is the argument and it is trapped at the bottom of the script at line 329 with

if [ "$region" = "midtones" ]; then
...

The argument mid is used to set the middle of the midtones region and defaults to the mean of the image. But it is only computed when region is not all (such as for midtones, shadows and highlights). See line 319

You are right about it not being used (unless it takes the default value). That is a mistake. I need to have it compute the low and high values (if not specified) from the mid value when the mid value is provided and not the default value. Give me a little time to fix this. I will get back shortly.

It may be possible to create something like PS colorbalance, but I do not know what algorithm is being used. It would take quite some effort of trial and error to try to figure out what they are doing and I may not be successful in the end.

I will put it on my to do list, but I have no idea when I will be able to get back to it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fred's ImageMagick Scripts : COLOR BALANCE

Post by fmw42 »

I have fixed the issue with the script and done some further testing on your image.

Try adjusting the -a value and especially the -f value. The midtone region needs to be wider than 1 standard deviation. A value of 3 (std) is much better and closer to the PS result though not a perfect match. So try

Code: Select all

colorbalance -c red -a 25 -r m -f 3 968678original.jpg show:
and play around with those values
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fred's ImageMagick Scripts : COLOR BALANCE

Post by fmw42 »

Using tint for a midtone color adjustment gets pretty close to your result from PS


convert 968678original.jpg \
\( +clone -level 0x99% -fill red -tint 25 -alpha set -channel a -evaluate set 100% +channel \) \
-compose over -composite -modulate 100,90,100 result.jpg

You can set the opacity lower to simulate less colorbalance in PS
Post Reply