Unsharp mask in Imagemagick and Gimp

20050118 Update - Before you read any further, you probably want to take a look at Eric Jeschke's excellent article "sharpening using Imagemagick", an explanation of Image Magick's unsharp masking parameters, and how the filter compares to the unsharp mask filters in Photoshop and the GIMP. I think he answers the question much better than I did - alas at the time I wrote this page his article was not published yet...

Now, here are the results of my own research in all its incompleteness :

Last night's pictures were particularily blurry, and I can't stand blurry pictures. After toying a bit with Gimp, it appeared that unsharp masking could make the pictures a little more bearable. Many pictures to process and no time to waste... Let's automate that ! Once I was satisfied with the result I decided to write an Imagemagick command to apply the same transformations to all pictures in the batch. The problem is that Imagemagick's unsharp filter does not take the same arguments as the Gimp's unsharp mask filter. I was having much trouble reproducing with Imagemagick the results I obtained with the Gimp.

Here are the arguments I used in Gimp to achieve satisfactory results with those 3072x2048 pixels pictures straight from my Eos 300D:

  • Radius : 6.0
  • Amount : 0.5
  • Threshold : 0

    Here is the syntax of

    -unsharp {x}{+}{+}
    	The -unsharp option sharpens an image. We convolve the image with a Gaussian
    	operator of the given radius and standard deviation (sigma). For reasonable
    	results, radius should be larger than sigma. Use a radius of 0 to have the
    	method select a suitable radius.
    	The parameters are:
    		radius:    The radius of the Gaussian, in pixels,  not
    			   counting the center pixel (default 0).
    		sigma:     The standard deviation of the Gaussian, in
    			   pixels (default 1.0).
    		amount:    The percentage of the difference between the
    			   original and the blur image that is added back								                
    			   into the original (default 1.0).
    		threshold: The threshold, as a fraction of MaxRGB, needed
    			   to apply the difference amount (default 0.05).												   

    Not only is the sigma absent from Gimp's USM settings, but the radius parameter does not seem to have the same effect. I found the solution in the Gimp changelog :

    --- 0.8 --- 1999/07/02
    - Radius parameter changed to refer to the standard deviation instead
      of the radius of effect.  The radius of effect is 2*std_dev.

    Using that information, here are the parameters I found producing the results closest to what I did with Gimp :

    	-unsharp 6x3+1+0
    Why does an amount of '1' in Imagemagick give the same result as an amount of '0.5' in Gimp is beyond my comprehension. Maybe they do not mean the same thing either. I found a relevant thread on the magick-users list, but the comparison was between Imagemagick and Photoshop. I have found nothing on the subject concerning the Gimp and Imagemagick.

    To give a more graphic impression of the results, here is the random sample I worked on :

  • The original blurry picture.
  • The picture after Gimp applied unsharp mask.
  • The picture after Imagemagick applied unsharp mask.

    That's the best results I achieved, but it is still not exactly what I wish I had : Imagemagick produces a very slightly but still perceptibly noisier result, and I have yet to understand why. But life is short and I am not going do process 70 pictures manually so I went with Imagemagick anyway. Twenty five minutes of batch processing later, here are the results.

    This is ruwenzori.net. Send comments, suggestions, criticism, money and death threats to Jean-Marc Liotier.