How to Apply Gamma Correction in ImageMagick?

Gamma correction is a crucial image processing technique used to adjust the luminance or brightness of an image, compensating for the way human eyes and digital displays perceive light. This article provides a straightforward guide on how to utilize the ImageMagick convert command to modify an image’s gamma values. You will learn the basic syntax, how to adjust individual color channels, and how to preview your results efficiently.

Understanding the Gamma Command Syntax

In ImageMagick, the -gamma operator adjusts the mid-tones of an image without altering the absolute black and white points. The basic command structure requires you to specify the input image, the gamma value, and the output file name.

The standard syntax is as follows:

magick convert input.jpg -gamma value output.jpg

Note: If you are using ImageMagick version 7 or later, the convert command is replaced by the primary magick command, though magick convert still works for backwards compatibility.

Choosing the Right Gamma Value

The gamma value you input acts as a multiplier for the image’s mid-tones. The default neutral gamma value is $1.0$.

For example, to brighten a dark photo, you might use:

magick convert dark_photo.png -gamma 1.5 bright_photo.png

Applying Channel-Specific Gamma Correction

ImageMagick also allows you to target specific color channels (Red, Green, or Blue) instead of applying the correction globally. This is highly useful for correcting color casts or creative color grading.

You can pass three comma-separated values representing the Red, Green, and Blue channels respectively:

magick convert input.jpg -gamma 1.2,1.0,0.8 output.jpg

In this specific example, the red channel is brightened ($1.2$), the green channel remains unchanged ($1.0$), and the blue channel is darkened ($0.8$). This results in a warmer, more reddish-yellow tint in the mid-tones.