Skip to content
MagickCmd › ImageMagick sharpen and blur commands

ImageMagick sharpen and blur commands

Sharpen images after resizing with unsharp mask, apply blur or Gaussian blur, pixelate a region, and denoise with a median filter. Explains the unsharp mask parameters.

Sharpen after a resize

Every downscale softens edges. An unsharp mask restores them:

magick input.jpg -resize 1200 -unsharp 0x0.75+0.75+0.008 output.jpg

What the four numbers mean

The syntax is radius x sigma + amount + threshold:

  • radius — set it to 0 and let ImageMagick derive it from sigma. This is what you almost always want.
  • sigma — how wide the sharpening halo is. 0.5–1.0 for web images, larger for print.
  • amount — strength. Above about 1.5 you start seeing bright outlines around edges.
  • threshold — how different neighbouring pixels must be before sharpening applies. A small value like 0.008 stops flat areas such as sky from gaining noise.

Leaving the threshold at 0 is the most common reason sharpened photos look grainy.

Simple sharpen

magick input.jpg -sharpen 0x1 output.jpg

A plain convolution with no threshold control. Faster, blunter, and more prone to amplifying noise than -unsharp.

Blur

magick input.jpg -blur 0x8 output.jpg
magick input.jpg -gaussian-blur 0x8 output.jpg

They look similar, but -blur is a fast approximation while -gaussian-blur computes a mathematically true Gaussian several times more slowly. For visual effects, -blur is fine.

Pixelate a region

There is no -pixelate operator. The trick is to scale down and back up using -scale, which uses nearest-neighbour sampling and so produces hard blocks rather than a smooth blur:

magick input.jpg -scale 5% -scale 2000% output.jpg

To pixelate only part of an image, crop the region, pixelate it, and composite it back:

magick input.jpg \
  '(' -clone 0 -crop 300x120+400+250 +repage -scale 8% -scale 1250% ')' \
  -geometry +400+250 -composite output.jpg

Blurring is not redaction

If you are hiding sensitive information, a light blur or a coarse pixelation can sometimes be partially reversed, and the original file often still exists elsewhere. For anything that actually matters, draw an opaque rectangle instead:

magick input.jpg -fill black -draw 'rectangle 400,250 700,370' output.jpg

Reduce noise

magick input.jpg -median 2 output.jpg
magick input.jpg -despeckle output.jpg
magick input.jpg -enhance output.jpg

-median removes speckle while preserving edges, which makes it better than a blur for scanned documents and noisy phone photos. Larger values are dramatically slower.


Related

Copied