How to Adjust Hue and Saturation in ImageMagick?

Adjusting the color characteristics of an image is a fundamental task in digital image processing, and ImageMagick provides powerful command-line utilities to achieve this efficiently. This article demonstrates how to use the ImageMagick convert (or magick) command to precisely manipulate the hue and saturation of an image. By utilizing the -modulate operator and understanding how it interprets percentage values for brightness, saturation, and hue, you can easily automate vibrant color enhancements or subtle color shifts across your image files.

Understanding the -modulate Operator

The primary tool for altering hue and saturation in ImageMagick is the -modulate option. This operator controls three color attributes at once using a specific sequence of percentage values:

magick input.jpg -modulate brightness,saturation,hue output.jpg

Note: In ImageMagick v7, the standard command is magick, while convert is used in v6. The syntax for the -modulate flags remains identical for both.

Each parameter relies on a baseline value of 100%, which represents the original, unaltered state of the image.

Adjusting Saturation

Saturation controls the intensity and purity of the colors in an image.

Example: Boosting Saturation

If you want to keep the brightness and hue exactly the same but increase the saturation by 40%, you would use:

magick input.jpg -modulate 100,140,100 output_vibrant.jpg

Adjusting Hue

Hue represents the actual color tint or position on the color wheel. ImageMagick handles hue adjustments by rotating the color spectrum.

Example: Shifting the Hue

To slightly shift the color palette of an image while keeping the original brightness and saturation intact, you might rotate the hue to 130%:

magick input.jpg -modulate 100,100,130 output_hueshift.jpg

Combining Hue and Saturation Adjustments

You can manipulate both properties simultaneously to achieve dramatic stylistic effects, such as creating a highly saturated, stylized color palette.

Example: High Saturation with a Color Shift

To increase the color intensity by 60% and shift the colors down the spectrum to 80% hue, combine the values like this:

magick input.jpg -modulate 100,160,80 output_stylized.jpg