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.jpgNote: In ImageMagick v7, the standard command is
magick, whileconvertis used in v6. The syntax for the-modulateflags 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.
- To decrease saturation (muting colors): Use a value
below 100%. For example,
50reduces the color intensity by half. A value of0removes all color, turning the image into grayscale. - To increase saturation (making colors more
vibrant): Use a value above 100%. For example,
150boosts the color intensity by 50%.
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.jpgAdjusting Hue
Hue represents the actual color tint or position on the color wheel. ImageMagick handles hue adjustments by rotating the color spectrum.
- 100% represents the original color (0 degrees of rotation).
- 0% or 200% represents a complete 180-degree rotation around the color wheel, resulting in complementary, inverted colors.
- Values between 0% and 100% rotate the colors in one direction (e.g., shifting reds toward yellows/greens).
- Values between 100% and 200% rotate the colors in the opposite direction (e.g., shifting reds toward blues/purples).
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.jpgCombining 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