adapting saturation

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
cedricb
Posts: 28
Joined: 2008-06-06T01:33:22-07:00

adapting saturation

Post by cedricb »

I've found this tutorial and I'm just wondering if there is an already built feature in IM to do that. If not then what's the simple way to achieve that special saturation mask?

http://www.clippingimages.com/blog/adaptive-saturation/

Cheers,
Ced.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: adapting saturation

Post by snibgo »

I don't use Photoshop, so can't follow the tutorial. It is interactive, which suggests Gimp rather than ImageMagick. A simple way of increasing saturation in IM is:

convert in.jpg -colorspace HSL -channel G evaluate multiply 3 out.jpg

But you can use masks, eg subtract a grayscale from the image.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: adapting saturation

Post by fmw42 »

you can also change saturation using -modulate

convert image -modulate 100,XX,100

the first number is percent brightness (actually either brightness or lightness, that is HSB vs HSL), the second number is percent satutation and the third number is percent hue

see http://www.imagemagick.org/Usage/color/#modulate

You can also create some kind of image such as a difference image and use it to modify the Saturation channel using composite methods (after converting to HSL or HSB) and then replace the old Saturation channel with the modified one, then convert back to RGB

see http://www.imagemagick.org/Usage/channels/#channels
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: adapting saturation

Post by snibgo »

Another useful command is:

convert in.png -colorspace HSL -channel Saturation -negate -evaluate multiply 0.8 -negate -colorspace RGB out.png

which will shift all saturations two-tenths of the way towards maximum.
snibgo's IM pages: im.snibgo.com
cedricb
Posts: 28
Joined: 2008-06-06T01:33:22-07:00

Re: adapting saturation

Post by cedricb »

Thanks a lot for the pointers!

I've been able to replicate perfectly the tutorial with PS4... It's nightmare to reproduce a mask/layer with IM, I can't get my head around it! :-)

Code: Select all

convert test.tiff -modulate 100,0,100 test_without_saturation.tiff
composite test_without_saluration.tiff test.tiff -compose difference test_diff.tiff
composite test_diff.tiff test.tiff -compose multiply test_merged.tiff
convert test_merged.tiff -normalize -modulate 100,130,100 -negate mask.tiff
Obviously the above is not a workable mask. I think step 3 is incorrect and I'm not sure what PS4 do a with HSL adjustment layer in term of the colorspace (don't know at which step to use HSL or RGB). I've played around with the CopyOpacity operator but I can't find the correct solution...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: adapting saturation

Post by snibgo »

Creating the mask is simple (Windows script):

Code: Select all

convert ^
  iStock_000001938307Large-2.jpg ^
  ( -clone 0 -modulate 100,0,100 ) ^
  -compose Difference -composite ^
  mask.png
snibgo's IM pages: im.snibgo.com
cedricb
Posts: 28
Joined: 2008-06-06T01:33:22-07:00

Re: adapting saturation

Post by cedricb »

that's the same thing than my first 2 steps...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: adapting saturation

Post by fmw42 »

it might be helpful to provide a link to an input image and a processed image that clearly shows what you want to do.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: adapting saturation

Post by snibgo »

It makes what looks like the mask in the Photoshop tutorial.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: adapting saturation

Post by fmw42 »

my guess is the mask is converted to grayscale before compositing (multiplying?) with the saturation channel in order to amplify the saturation for certain pixels or de-emphasize it for others. It might need to be biased or stretched to get the right effect. Don't know how PS composites it!

That is why a good input and output example would be useful for testing theories about how to process it.
cedricb
Posts: 28
Joined: 2008-06-06T01:33:22-07:00

Re: adapting saturation

Post by cedricb »

...here is maybe a solution, I need to further compare with the PS4 result

Code: Select all

convert girl.png \( -clone 0 -modulate 100,0,100 \) -compose difference -composite mask1.tiff
convert girl.png -normalize -modulate 100,130,100 mask2.tiff

composite -compose CopyOpacity \( mask1.tiff -negate \) mask2.tiff mask_dull.tiff
composite mask_dull.tiff girl.png final_saturate_dull.tiff

composite -compose CopyOpacity \( mask1.tiff \) mask2.tiff mask_vivid.tiff
composite mask_vivid.tiff girl.png final_saturate_vivid.tiff
cedricb
Posts: 28
Joined: 2008-06-06T01:33:22-07:00

Re: adapting saturation

Post by cedricb »

that's not the correct solution... :?
cedricb
Posts: 28
Joined: 2008-06-06T01:33:22-07:00

Re: adapting saturation

Post by cedricb »

I'm just trying to do some basic stuff...

What's the difference with

Code: Select all

convert girl.png -colorspace HSL -separate girl_hsl%d.tiff
convert girl_hsl1.tiff -evaluate set 0 girl_hsl1_zero.tiff
mv girl_hsl1_zero.tiff girl_hsl1.tiff
convert girl_hsl?.tiff -set colorspace HSL -combine -colorspace RGB girl2.tiff
and

Code: Select all

convert girl.png -modulate 100,0,100 girl3.tiff
or

Code: Select all

convert girl.png -colorspace HSL -channel G -evaluate set 0 +channel -colorspace RGB girl4.tiff
Obviously I'm not getting the same result...

solution 2 and 3 should be the same, but they have a difference shade of gray on the L channel (H and S are zeroing)
solution 2/3, why do I get zeroing on the H channel?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: adapting saturation

Post by snibgo »

Using http://www.clippingimages.com/blog/wp-c ... arge-2.jpg as the source,
I get identical results for girl2.tiff, 3 and 4. This is IM 6.6.0-8 on Windows 7. If your IM is old, an upgrade might help.

For a gray pixel, the hue isn't relevant. Gray doesn't have a hue.

EDIT: does your input file girl.png have an embedded profile?
snibgo's IM pages: im.snibgo.com
cedricb
Posts: 28
Joined: 2008-06-06T01:33:22-07:00

Re: adapting saturation

Post by cedricb »

thx I'll have a look @home with an updated version
Post Reply