How to use ImageMagick convert unsharp mask?
This article provides a quick overview and practical guide on how to
use the ImageMagick convert command to apply an unsharp
mask, a powerful digital image processing technique used to enhance
sharpness and clarity. You will learn the specific syntax of the
-unsharp operator, understand how its various numerical
parameters control the sharpening effect, and see concrete examples to
achieve professional results on your images.
Sharpening an image with ImageMagick relies on the
-unsharp option, which actually uses a blurred (or
“unsharp”) negative image to create a mask, adding contrast back into
the original image’s edges. The command follows a standard structure
where you pass a specific sequence of numbers to fine-tune the radius,
sigma, gain, and threshold of the effect.
The basic syntax for the command looks like this:
magick convert input.jpg -unsharp radiusxsigma+gain+threshold output.jpg
Note: If you are using ImageMagick v7 or later, the standard command is simply
magickinstead ofmagick convert, but the parameters for the unsharp mask remain exactly the same.
To get the best results, it helps to understand what each of these four parameters controls:
- Radius: This determines the size of the blurring gaussion core. A value of 0 is often recommended because ImageMagick will automatically calculate the best radius based on your sigma value.
- Sigma: This is the standard deviation of the Gaussian blur and is the most critical parameter. It dictates the width of the sharpening band around the edges. A good starting point for web images is usually between 0.5 and 1.5.
- Gain (Amount): This controls the intensity or strength of the sharpening effect, expressed as a fraction or percentage. For example, 1.0 or 1.5 adds a noticeable amount of sharpness, while higher numbers can cause artifacts.
- Threshold: This acts as a noise-reduction filter. It determines the minimum contrast difference required for an edge to be sharpened. A small threshold (like 0.05) ensures that minor digital noise or skin textures aren’t accidentally sharpened and ruined.
Here are a few practical examples demonstrating how to combine these settings for different photography needs:
Standard Web Sharpening
For general images being prepared for a website, you want a subtle
but noticeable boost in clarity without creating harsh artifacts.
magick convert photo.jpg -unsharp 0x1+1.0+0.05 sharp_photo.jpg
Strong Edge Sharpening
If you are working with slightly blurry text, architectural
photography, or images with distinct lines, you can increase the gain.
magick convert document.png -unsharp 0x1.2+2.0+0.02 sharp_document.png
Soft/Fine Detail Sharpening
For portraits or nature shots where you want to preserve soft
gradients but sharpen fine details like hair or feathers, use a smaller
sigma and lower gain.
magick convert portrait.jpg -unsharp 0x0.5+0.8+0.1 sharp_portrait.jpg
When experimenting with ImageMagick sharpening, it is always best practice to test different sigma and gain combinations on a duplicate image until you find the perfect balance for your specific resolution and subject matter.