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?".
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-03T20:02:24-07:00

More tests...

Code: Select all

convert rose: -colorspace RGB -colorspace LAB -colorspace sRGB show:
comes out correct, so the LAB->sRGB colorspace must be correct.

However

Code: Select all

convert rose: -colorspace LAB -colorspace RGB -colorspace sRGB show:
Comes out wrong (too light)

As the previously seen RGB->LAB and LAB->RGB is known to be working as is the RGB->sRGB and sRGB->RGB, then by a a process of ellimination then, it is the sRGB->LAB conversion that is failing!
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-04T00:34:14-07:00

Just tested using "Surfing in Hawaii" in http://en.wikipedia.org/wiki/Saturation ... _theory%29

The matrix (MATCIE) made from CIE RGB-XYZ weights is actually performing quite well when compared with "LCh chroma (see CIELAB) increased by 50% in Photoshop", marginally better than that from Rec.709 weights.

Code: Select all

set RESZFT=-define filter:c=0.3689927438004929 -filter Cubic -distort resize 75%
set INP50=Surfing_in_Hawaii_50_LCh_chroma.jpg
convert.exe %INP50% -colorspace RGB %RESZFT% -colorspace sRGB -quality 95 test_c_50.jpg
convert.exe %INP50% -colorspace RGB %RESZFT% -colorspace LAB -channel R -separate -colorspace sRGB -quality 95 test_Lab_50.jpg
convert.exe %INP50% -colorspace RGB %RESZFT% -colorspace XYZ -channel G -separate -colorspace sRGB -quality 95 test_xYz_50.jpg
set INPUT=Surfing_in_Hawaii_unmodified.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% -colorspace sRGB -quality 95 test_c_00.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% -colorspace LAB -channel R -separate -colorspace sRGB -quality 95 test_Lab_00.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% -colorspace XYZ -channel G -separate -colorspace sRGB -quality 95 test_xYz_00.jpg
set MATCIE=-color-matrix "1.82303 -0.8124 -0.01063 -0.17697 1.1876 -0.01063 -0.17697 -0.8124 1.98937"
convert.exe %INPUT% -colorspace RGB %RESZFT% %MATCIE% -colorspace sRGB -quality 95 test_c_cie.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% %MATCIE% -colorspace LAB -channel R -separate -colorspace sRGB -quality 95 test_Lab_cie.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% %MATCIE% -colorspace XYZ -channel G -separate -colorspace sRGB -quality 95 test_xYz_cie.jpg
set MAT709=-color-matrix "1.7874 -0.7152 -0.0722 -0.2126 1.2848 -0.0722 -0.2126 -0.7152 1.9278"
convert.exe %INPUT% -colorspace RGB %RESZFT% %MAT709% -colorspace sRGB -quality 95 test_c_709.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% %MAT709% -colorspace LAB -channel R -separate -colorspace sRGB -quality 95 test_Lab_709.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% %MAT709% -colorspace XYZ -channel G -separate -colorspace sRGB -quality 95 test_xYz_709.jpg
set MAT601=-color-matrix "1.701 -0.587 -0.114 -0.299 1.413 -0.114 -0.299 -0.587 1.886"
convert.exe %INPUT% -colorspace RGB %RESZFT% %MAT601% -colorspace sRGB -quality 95 test_c_601.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% %MAT601% -colorspace LAB -channel R -separate -colorspace sRGB -quality 95 test_Lab_601.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% %MAT601% -colorspace XYZ -channel G -separate -colorspace sRGB -quality 95 test_xYz_601.jpg
set MATWEB=-color-matrix "1.6914 -0.6094 -0.082 -0.3086 1.3906 -0.082 -0.3086 -0.6094 1.918"
convert.exe %INPUT% -colorspace RGB %RESZFT% %MATWEB% -colorspace sRGB -quality 95 test_c_web.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% %MATWEB% -colorspace LAB -channel R -separate -colorspace sRGB -quality 95 test_Lab_web.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% %MATWEB% -colorspace XYZ -channel G -separate -colorspace sRGB -quality 95 test_xYz_web.jpg
set MATVIV=-color-matrix "2 -0.5 -0.5 -0.5 2 -0.5 -0.5 -0.5 2"
convert.exe %INPUT% -colorspace RGB %RESZFT% %MATWEB% -colorspace sRGB -quality 95 test_c_viv.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% %MATWEB% -colorspace LAB -channel R -separate -colorspace sRGB -quality 95 test_Lab_viv.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% %MATWEB% -colorspace XYZ -channel G -separate -colorspace sRGB -quality 95 test_xYz_viv.jpg
set MDLPAR=-modulate 100,200
convert.exe %INPUT% -colorspace RGB %RESZFT% %MDLPAR% -colorspace sRGB -quality 95 test_c_mod.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% %MDLPAR% -colorspace LAB -channel R -separate -colorspace sRGB -quality 95 test_Lab_mod.jpg
convert.exe %INPUT% -colorspace RGB %RESZFT% %MDLPAR% -colorspace XYZ -channel G -separate -colorspace sRGB -quality 95 test_xYz_mod.jpg

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-04T18:43:10-07:00

Hmmm following that wikipedia link I see they have a reference to a much more linear 'hue' colorspace...

LCh (Lightness, Chroma, Hue(ab) )

Where Lab is converted to LCh so that
C=sqrt(a^2+b^2)
h=arctan(b/a)

It seems that saturation (chroma) changes or hue rotations in this colorspace would be much more useful!
As such it may make a good colorspace to use for -modulate.


Of course making a modulate type operator that did properly handle an image colorspace, and does hue rotations in terms of changes to hue angle in degrees, would be a nice.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

User avatar
fmw42
Posts: 25556
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-04T18:57:46-07:00

anthony wrote:Hmmm following that wikipedia link I see they have a reference to a much more linear 'hue' colorspace...

LCh (Lightness, Chroma, Hue(ab) )

Where Lab is converted to LCh so that
C=sqrt(a^2+b^2)
h=arctan(b/a)

It seems that saturation (chroma) changes or hue rotations in this colorspace would be much more useful!
As such it may make a good colorspace to use for -modulate.
Interesting article!

I was always taught that, functionally, saturation was the lack of white mixed with a pure color. This seems to be what this reference calls colorfulness.

"Colorfulness is the degree of difference between a color and gray."

But in HSL and HSB, that is what saturation is measuring -- the relative distance from the axis of the (hex) cones. The axis being shades of gray from black to white.

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-04T19:55:59-07:00

Actually in HSL and HSB you would typically multiply saturation by luminance/brilance (appropriteally)
The result is a 'bi-cone' or 'cone' representation.

See http://www.imagemagick.org/Usage/color_ ... olor_names as an example.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

User avatar
fmw42
Posts: 25556
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-04T20:03:35-07:00

anthony wrote:Actually in HSL and HSB you would typically multiply saturation by luminance/brilance (appropriteally)
The result is a 'bi-cone' or 'cone' representation.

See http://www.imagemagick.org/Usage/color_ ... olor_names as an example.

HSL and HSB are already double (hex) cone and single (hex) cone representations.

I don't know why/where you are trying to multiply the saturation by the luminance or brilliance? What reason do you have for that? Then it is not saturation from HSL or HSB, but some other representation, which may be more in line with the definitions in that reference above?

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-04T20:13:11-07:00

fmw42 wrote:
anthony wrote:Actually in HSL and HSB you would typically multiply saturation by luminance/brilance (appropriteally)
The result is a 'bi-cone' or 'cone' representation.

See http://www.imagemagick.org/Usage/color_ ... olor_names as an example.

HSL and HSB are already double (hex) cone and single (hex) cone representations.

I don't know why/where you are trying to multiply the saturation by the luminance or brilliance? What reason do you have for that? Then it is not saturation from HSL or HSB, but some other representation, which may be more in line with the definitions in that reference above?
Strictly they are not. The dimentions really lay out a cylinder. Just most people think or represent them as cones.
I thought they were cones too, until I tried to create the image shown in named colors!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

User avatar
fmw42
Posts: 25556
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-04T21:56:21-07:00

anthony wrote:
The dimentions really lay out a cylinder. Just most people think or represent them as cones.
I thought they were cones too, until I tried to create the image shown in named colors!
Sorry to disagree, the equations define a hex-cone. That is the sides are a hexagon that taper to one or two points.

http://en.wikipedia.org/wiki/Hexcone says it warps a hexagon into a circle. But if you look at the code, you see they are done in segments of a hexagon for hue. That is a point on a side is mapped to a hue angle. So perhaps that is what they mean by warping a hexagon to a circle. Perhaps this is just semantics, but since the code uses a hexagon, most people call the shape a hex-cone. The hex cone is the basis as it is closer to the shape of a cube turned on a point than is a cylindrical cone.

see for example:

http://www.siggraph.org/education/mater ... olorhs.htm

http://books.google.com/books?id=-4ngT0 ... ne&f=false

I worked out similar equations many years ago.

stupid
Posts: 51
Joined: 2010-02-12T07:30:34-07:00
Authentication code: 8675308

Re: Alternative to modulate command to increase Saturation

Post by stupid » 2012-04-05T07:07:32-07:00

Alternative to -modulate saturation:

convert INPUT.JPG ( +clone -colorspace Gray ) +swap -compose Blend -set option:compose:args 250 -composite OUTPUT.JPG

250 is a very heavy increase in saturation.


s.

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-05T08:14:27-07:00

stupid wrote: convert INPUT.JPG ( +clone -colorspace Gray ) +swap -compose Blend -set option:compose:args 250 -composite OUTPUT.JPG
Seems the change in brightness can be better controlled if we add the "-colorspace" pair.

Code: Select all

convert INPUT.JPG -colorspace RGB ( +clone -colorspace Gray ) +swap -compose Blend -set option:compose:args 250 -composite -colorspace sRGB OUTPUT.JPG

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-08T06:37:26-07:00

henrywho wrote: Seems the change in brightness can be better controlled if we add the "-colorspace" pair.

Code: Select all

convert INPUT.JPG -colorspace RGB ( +clone -colorspace Gray ) +swap -compose Blend -set option:compose:args 250 -composite -colorspace sRGB OUTPUT.JPG

Hmmm seems that was an example I am missing from "Using Blend with a single image"
http://www.imagemagick.org/Usage/compose/#blend_use

This is all about the use of 'extroplated values' between the original image and a varient, such as a blurred version of the original.

I'll have to add this. -- DONE (give it an hour or so to appear)
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-08T08:50:55-07:00

I thought "blend" also assumes linear RGB. 8)

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-08T17:07:38-07:00

Well ahrmmm.. yes it does. Practically all operations do.
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 » 2013-03-26T22:03:09-07:00

Just tried something like:

convert.exe input.png -set colorspace srgb -colorspace hcl -channel G +sigmoidal-contrast 3.5,49% +channel -colorspace srgb output.png

Not bad.... but I need something asymmetric so as not to de-saturate the high-saturation areas. Do u guys have any idea?

User avatar
fmw42
Posts: 25556
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 » 2013-03-26T22:57:05-07:00

try shifting the center point to 0% or use -gamma 0.5 (you can adjust either)

convert.exe input.png -set colorspace srgb -colorspace hcl -channel G +sigmoidal-contrast 3.5,0% +channel -colorspace srgb output.png

convert.exe input.png -set colorspace srgb -colorspace hcl -channel G -gamma 0.5 +channel -colorspace srgb output.png


I have used these same ideas to increase or decrease the chroma channel in the low range. It is a form of vibrance (adjust only the low values). You can see that in http://jqmagick.imagemagick.org in the color category saturation filter.

My vibrance script is another method, that uses masking to select the low values to adjust. ttp://www.fmwconcepts.com/imagemagick/vibrance/index.php

Post Reply