convert -modulate saturation behavior changed?

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?".
Post Reply
remko

convert -modulate saturation behavior changed?

Post by remko »

Hi,

I used to use 'convert -modulate 100,0' to remove saturation from
pictures. However, I recently upgraded my ImageMagick to 6.4.0 (no
idea what I was using before), and my resulting pictures are not what
I expected them to be:
  • Original icon: Image
  • Convert before: Image
  • Convert now: Image
When I remove saturation with any other graphics program, the result
is the one that I had before. Has something changed? Any suggestions
how I can get the original behavior?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert -modulate saturation behavior changed?

Post by fmw42 »

This is only a temporary workaround. I would suggest you report this to the Bugs forum as I believe you are correct. I checked on IM 6.4.0-3 with the same results from -modulate. Here is a work around.

If you are on Q16:
convert icon.png -colorspace HSL \
-channel G -threshold 65535 +channel \
-colorspace RGB icon_s0.png

If Q8, then replace 65535 with 255

Basically I am changing the Saturation channel to zero (black) without actually converting the image to HSL, as -threshold is a channel selective operator.

See similar processing of the luminance channel of the rose image at:
http://www.imagemagick.org/Usage/channe ... bine_other

This also works:

convert icon.png -colorspace HSL \
-fill black -colorize 0%,100%,0% +channel \
-colorspace RGB icon_s0.png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert -modulate saturation behavior changed?

Post by anthony »

Other solutions, (zeroing the 'G' o saturation channel in HSL) which do not rely on a specific IM version include...

Code: Select all

   -channel G -threshold 101% +channel
   
   -channel G -negate -threshold -1 -negate +channel

   -channel G -evaluate set 0 +channel

   -gamma 1,0,1
That last is VERY tricky, and was in IM examples as a alternative method of channel seperation.

A more complex method is to -separate the image into channel images, delete the saturation channel the -combine just the two channels with a -background of black, though that is an awful lot of work for such a simple operation.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply