Page 1 of 2

adapting saturation

Posted: 2010-05-12T13:08:07-07:00
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.

Re: adapting saturation

Posted: 2010-05-12T16:24:07-07:00
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.

Re: adapting saturation

Posted: 2010-05-12T18:14:54-07:00
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

Re: adapting saturation

Posted: 2010-05-12T18:41:51-07:00
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.

Re: adapting saturation

Posted: 2010-05-13T10:40:52-07:00
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...

Re: adapting saturation

Posted: 2010-05-13T11:30:55-07:00
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

Re: adapting saturation

Posted: 2010-05-13T12:14:26-07:00
by cedricb
that's the same thing than my first 2 steps...

Re: adapting saturation

Posted: 2010-05-13T12:45:37-07:00
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.

Re: adapting saturation

Posted: 2010-05-13T13:58:59-07:00
by snibgo
It makes what looks like the mask in the Photoshop tutorial.

Re: adapting saturation

Posted: 2010-05-13T15:36:19-07:00
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.

Re: adapting saturation

Posted: 2010-05-14T02:59:53-07:00
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

Re: adapting saturation

Posted: 2010-05-14T12:03:16-07:00
by cedricb
that's not the correct solution... :?

Re: adapting saturation

Posted: 2010-05-21T02:36:31-07:00
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?

Re: adapting saturation

Posted: 2010-05-21T03:39:48-07:00
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?

Re: adapting saturation

Posted: 2010-05-21T05:31:37-07:00
by cedricb
thx I'll have a look @home with an updated version