Page 1 of 3
Alternative to modulate command to increase Saturation
Posted: 2012-03-12T16:04:52-07:00
by stevecx
Is there any other alternatives to increase saturation other than using the convert -modulate 100,155,100 with HSL?
Does anyone know the alogrithim or math being used by ImageMagick modulate option which increases saturation.
Example of command being used to increase saturation:
convert "orig.jpg" -modulate 100,165,100 "test-saturation.jpg"
Re: Alternative to modulate command to increase Saturation
Posted: 2012-03-12T16:19:32-07:00
by fmw42
You can modulate in HSB as well as HSL. See defines for that at
http://www.imagemagick.org/Usage/color_ ... colorspace
The algorithms are either single or double hexcones. see
http://en.wikipedia.org/wiki/HSL_and_HSV
Re: Alternative to modulate command to increase Saturation
Posted: 2012-03-19T14:21:02-07:00
by fmw42
You can also look at my scripts, colortoning, enrich and vibrance as alternates to linear saturation changes. see link below.
You can also try adjusting the two non-luminance-like channels in YUV, YCbCr or Lab, ie. channels other Y and L, e.g uv, cbcr and ab.
Re: Alternative to modulate command to increase Saturation
Posted: 2012-03-23T20:56:01-07:00
by fmw42
Another approach is to separate HSL (or HSB) channels, modify the S channel with any linear or non-linear operation (e.g. -level, -brightness-contrast, -gamma, -evaluate pow, -evaluate log, -function polynomial, etc), then recombine the 3 channels.
Re: Alternative to modulate command to increase Saturation
Posted: 2012-04-02T03:39:12-07:00
by henrywho
Yet another approach is to use -color-matrix under linear RGB, as described in
http://www.graficaobscura.com/matrix/index.html
For example, to increase the saturation by a factor of 1.1 without changing luminance (hopefully), I use the following matrix:
Code: Select all
-color-matrix "
1.07875 -0.07154 -0.00721
-0.02125 1.02846 -0.00721
-0.02125 -0.07154 1.09279"
"
This matrix is generated using the HDTV (ITU-R BT.709) R/G/B weights. I prefer it over NTSC because the red color is less emphasized.
Linear RGB is no problem for me because it is always an intermediate step for (distort-)resize.
Re: Alternative to modulate command to increase Saturation
Posted: 2012-04-02T21:46:05-07:00
by henrywho
To calculate the matrix, I use this spreadsheet:
https://docs.google.com/spreadsheet/ccc ... 1M3SE9IQUE
Code: Select all
convert input.png -depth 16 -colorspace RGB -distort Resize 25% -sigmoidal-contrast 3,27% -color-matrix "1.1575 -0.14308 -0.01442 -0.0425 1.05692 -0.01442 -0.0425 -0.14308 1.18558" -colorspace sRGB -depth 8 -quality 05 output.png
And another reason to use the weights over linear RGB:
http://www.w3.org/TR/2008/REC-WCAG20-20 ... minancedef
Re: Alternative to modulate command to increase Saturation
Posted: 2012-04-02T22:56:31-07:00
by anthony
That is a bit like Vivid Colors, though not as strong.
Code: Select all
convert rose: -color-matrix ' 1.2 -0.1 -0.1
-0.1 1.2 -0.1
-0.1 -0.1 1.2 ' matrix_vivid.png
For more about how -color-matrix works see IM examples, Color Modifications, Color Matrix Operator
http://www.imagemagick.org/Usage/color_ ... lor-matrix
henrywho: The use of
-depth does nothing in your command. It is for file depth, not inmemory quality
http://www.imagemagick.org/Usage/basics ... ge_quality
Re: Alternative to modulate command to increase Saturation
Posted: 2012-04-03T00:26:17-07:00
by henrywho
The simple 1.2/-0.1/-0.1 vivid matrix will change the luminance and so I prefer the more complicated matrix.
Thanks for reminding about the redundant "-depth" parameters. They always appear in my command-lines because my scripts are generating intermediate MIFF files and I want them having full depth to minimize truncation errors; when I combine several commands as one, I forgot to remove the "-depth" parameters.
Re: Alternative to modulate command to increase Saturation
Posted: 2012-04-03T00:40:11-07:00
by anthony
Instead of miff for intermediates you could use mpc:
It generates two files but the data file is just a direct memory dump, and a read is just a direct memory map. This means less extra processing (only disk io, but using a ram disk makes that very fast)
-depth also does not coult for this because of the 'memory' nature.
See IM examples. File Handling MPC:
http://www.imagemagick.org/Usage/files/#mpc
I use these all the time for script temporary files, but they are only usful for transient data as tehy are tied to the specific IM compilation.
NOTE I do use MIFF: but usually when I am 'pipelining a stream of images' from a loop into a final 'layout' command.
http://www.imagemagick.org/Usage/files/#miff
Re: Alternative to modulate command to increase Saturation
Posted: 2012-04-03T04:53:16-07:00
by henrywho
Thank you for your advise on "MPC".
Actually, I have one question on "modulate". The below commands are giving different outputs. Which usage is correct?
Code: Select all
convert.exe imput.png -colorspace RGB -distort resize 25% -modulate 100,120 -colorspace sRGB output_1.png
convert.exe imput.png -colorspace RGB -distort resize 25% -colorspace sRGB -modulate 100,120 output_2.png
Re: Alternative to modulate command to increase Saturation
Posted: 2012-04-03T10:49:34-07:00
by henrywho
On further tests, the color matrices generated from the second row of the sRGB (linear) to CIE XYZ matrix found in
http://en.wikipedia.org/wiki/SRGB give better result with "red" being less profound than other weightings
Color matrix updated:
https://docs.google.com/spreadsheet/ccc ... IQUE#gid=0
Re: Alternative to modulate command to increase Saturation
Posted: 2012-04-03T16:46:34-07:00
by anthony
henrywho wrote:Thank you for your advise on "MPC".
Actually, I have one question on "modulate". The below commands are giving different outputs. Which usage is correct?
Code: Select all
convert.exe imput.png -colorspace RGB -distort resize 25% -modulate 100,120 -colorspace sRGB output_1.png
convert.exe imput.png -colorspace RGB -distort resize 25% -colorspace sRGB -modulate 100,120 output_2.png
Both should do the same thing, however looking at the code it just pulls the RGB values (regardless of colorspace)
convert it to HSL, HSB, or HWS, makes the change and converts back and puts the values back.
It seems to be assuming it is linearRGB colorspace, as it does not look at the images current colorspace at all!
This lack of understanding of the images original colorspace can be regarded as a bug.
But I would not fix this until the sRGB -> HSL -> sRGB cycle is fixed.
In any case, like the actual Hue colorspace definition implies it treats all the primary colors as being of equal intensity. As such rotating a blue to a yellow makes that color very bright! Just as warned about in the wikipedia web page.
A hue changer that does take into account color intensity would be a nice addition. Essentually a rotate along the grey color vector in just about any non-RGB or Hue colorspace (XYZ, YUV, etc). Wish I had time for it!
Re: Alternative to modulate command to increase Saturation
Posted: 2012-04-03T18:52:24-07:00
by henrywho
If we want a change the saturation or hue without changing intensity/brightness/intensity/luma/whatsoever, it seems we need to settle on a good definition.
btw, is "-colorspace LAB -channel R -separate" also assuming linear RGB?
Re: Alternative to modulate command to increase Saturation
Posted: 2012-04-03T19:13:20-07:00
by fmw42
If we want a change the saturation or hue without changing intensity/brightness/intensity/luma/whatsoever, it seems we need to settle on a good definition.
It depends upon whether you use HSL or HSB with -modulate.
The definition of saturation is closely associated with those colorspaces. see
http://en.wikipedia.org/wiki/HSL_and_HSV
In general, saturation is just a lack of white mixed with the pure color (saturation is max when no white is mixed in --- saturation is zero when the image is grayscale anywhere between black and white).
But you can implement saturation however you want to achieve such a goal, but it will be different for each colorspace you use depending upon what colorspace you want to use.
see
http://en.wikipedia.org/wiki/Saturation_(color_theory)
Re: Alternative to modulate command to increase Saturation
Posted: 2012-04-03T19:58:55-07:00
by anthony
henrywho wrote:If we want a change the saturation or hue without changing intensity/brightness/intensity/luma/whatsoever, it seems we need to settle on a good definition.
btw, is "-colorspace LAB -channel R -separate" also assuming linear RGB?
-colorspace operator is specifically a colorspace to colorspace converter. It should convert current colorspace TO given colorspace. the
-set colorspace however just re-assigns the colorspace settign without changing the data.
NOW whether these colorspace conversions are working right is another question. The tests is to try various conversions from one colorspace to another, and back again to the original colorspace. If the result is not right then we have a bug.
For example....
Code: Select all
convert rose: -colorspace LAB -colorspace sRGB show:
Unfortunatally the above is (at this moment) producing a image which is too light.
It is currently buggy Whether this is caused by
sRGB->LAB or
LAB->sRGB is not known.
On the other hand a quick test shows that a cycle of
RGB->LAB and
LAB->RGB (that cycle between
linear-RGB and
LAB) is working correctly!
Code: Select all
convert rose: -set colorspace RGB -colorspace LAB -colorspace RGB -set colorspace sRGB show:
yes I am pretending the image data is in different colorspace that it should be, but the result of the able should be a no-op and it is.