Alternative to modulate command to increase 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?".
stevecx
Posts: 2
Joined: 2012-03-12T15:58:09-07:00
Authentication code: 8675308

Alternative to modulate command to increase Saturation

Post by stevecx » 2012-03-12T16:04:52-07:00

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"

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

Re: Alternative to modulate command to increase Saturation

Post by fmw42 » 2012-03-12T16:19:32-07:00

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

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

Re: Alternative to modulate command to increase Saturation

Post by fmw42 » 2012-03-19T14:21:02-07:00

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.

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

Re: Alternative to modulate command to increase Saturation

Post by fmw42 » 2012-03-23T20:56:01-07:00

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.

henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: Alternative to modulate command to increase Saturation

Post by henrywho » 2012-04-02T03:39:12-07:00

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.

henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: Alternative to modulate command to increase Saturation

Post by henrywho » 2012-04-02T21:46:05-07:00

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

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Alternative to modulate command to increase Saturation

Post by anthony » 2012-04-02T22:56:31-07:00

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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: Alternative to modulate command to increase Saturation

Post by henrywho » 2012-04-03T00:26:17-07:00

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.

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Alternative to modulate command to increase Saturation

Post by anthony » 2012-04-03T00:40:11-07:00

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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: Alternative to modulate command to increase Saturation

Post by henrywho » 2012-04-03T04:53:16-07:00

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

henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: Alternative to modulate command to increase Saturation

Post by henrywho » 2012-04-03T10:49:34-07:00

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

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Alternative to modulate command to increase Saturation

Post by anthony » 2012-04-03T16:46:34-07:00

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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: Alternative to modulate command to increase Saturation

Post by henrywho » 2012-04-03T18:52:24-07:00

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?

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

Re: Alternative to modulate command to increase Saturation

Post by fmw42 » 2012-04-03T19:13:20-07:00

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)

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Alternative to modulate command to increase Saturation

Post by anthony » 2012-04-03T19:58:55-07:00

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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply