I'm new to IM and need some help to write a simple IM command to desaturate red colors from a jpg image (but retaining all other colors). To do this in Photoshop I select Hue/Saturation then select REDS (from drop down menu) and move the saturation to -100. How can I do the same effect in ImageMagick.
Here is an example of the effect
https://app.box.com/s/by8xqffhl6mn4b03zqmnckjdcvwiqmeu
Desaturate Red colors
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Desaturate Red colors
I break down problems like this into:
1. What effect do I want? In this case, "-modulate 100,0,100".
2. Where do I want it? For example: "I want it where the red channel is at least 15% more than the blue channel." This is "-channel RB -separate +channel -compose MinusSrc -composite -threshold 15%".
We use the result of (2) as a mask to composite (1) over the input. So we get:
1. What effect do I want? In this case, "-modulate 100,0,100".
2. Where do I want it? For example: "I want it where the red channel is at least 15% more than the blue channel." This is "-channel RB -separate +channel -compose MinusSrc -composite -threshold 15%".
We use the result of (2) as a mask to composite (1) over the input. So we get:
Code: Select all
convert "Desaturate Reds.jpg" ( -clone 0 -modulate 100,0,100 ) ( -clone 0 -channel RB -separate +channel -compose MinusSrc -composite -threshold 15% ) -compose Over -composite c.png
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Desaturate Red colors
If on Linux, MacOSX or Windows with Cygwin or Windows 10, you can try my script modulatecolor2 at the link below.
Re: Desaturate Red colors
Thank You snibgo. This script works great except it desaturates yellow. When I do it in photoshop I'm able to keep yellows. Is there anyway to modify the code in order to keep yellow ?snibgo wrote:I break down problems like this into:
1. What effect do I want? In this case, "-modulate 100,0,100".
2. Where do I want it? For example: "I want it where the red channel is at least 15% more than the blue channel." This is "-channel RB -separate +channel -compose MinusSrc -composite -threshold 15%".
We use the result of (2) as a mask to composite (1) over the input. So we get:
Code: Select all
convert "Desaturate Reds.jpg" ( -clone 0 -modulate 100,0,100 ) ( -clone 0 -channel RB -separate +channel -compose MinusSrc -composite -threshold 15% ) -compose Over -composite c.png
Thank you
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Desaturate Red colors
You need to define exactly what you mean by "desaturate red colors ... but retaining all other colors". What defines "red" as opposed to "not red"? And is the boundary between these sharp (so it is binary, and any pixel is either red or not-red) or is there a transition?
You can play with the expression I gave in (2). For example, you could use "-channel R -separate +channel". This would be a smooth transition between red and non-red.
Try Fred's script. Does it do what you want? If not, what do you want different?
You can play with the expression I gave in (2). For example, you could use "-channel R -separate +channel". This would be a smooth transition between red and non-red.
Try Fred's script. Does it do what you want? If not, what do you want different?
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Desaturate Red colors
Here is a v7 command to reduce saturation of a particular hue, or range of hues. Windows BAT syntax.
The controls are all percentages:
centHue determine which hue will be desaturated. 0=red, 16.67=yellow, 33=green, 67=blue etc. 100 is also red.
rangeHue determines what range of hues will be entirely desaturated. "10" means "plus or minus 5%".
transHue is the percentage of hues over which a transition will be applied. In this example, hues greater than 0 + 10/2 + 10 = 15% will not be desaturated. As yellow is more than 15%, it will not be desaturated.
This works for all hues, wrapping as required for 0=100.
Code: Select all
set centHue=0
set rangeHue=10
set transHue=10
%IMG7%magick ^
rose: ^
( -clone 0 -modulate 100,0,100 ) ^
( -clone 0 ^
-colorspace HSL ^
-channel H -separate +channel ^
-evaluate AddModulus %%[fx:50-%centHue%]%% ^
-solarize 50%% ^
-evaluate Multiply 2 ^
-level %%[fx:100-%rangeHue%-2*%transHue%],%%[fx:100-%rangeHue%]%% ^
) ^
-compose Over -composite ^
rose_desat.png
The controls are all percentages:
centHue determine which hue will be desaturated. 0=red, 16.67=yellow, 33=green, 67=blue etc. 100 is also red.
rangeHue determines what range of hues will be entirely desaturated. "10" means "plus or minus 5%".
transHue is the percentage of hues over which a transition will be applied. In this example, hues greater than 0 + 10/2 + 10 = 15% will not be desaturated. As yellow is more than 15%, it will not be desaturated.
This works for all hues, wrapping as required for 0=100.
snibgo's IM pages: im.snibgo.com