"threshold" in MagickUnsharpMaskImage

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Hilbert

"threshold" in MagickUnsharpMaskImage

Post by Hilbert »

I'm using MagickUnsharpMaskImage in the MagickWand API: http://www.imagemagick.org/api/magick-i ... pMaskImage

I can't make sense of the threshold parameter. In the command-line unsharp mask, "threshold" is a value from 0 to QuantumRange, a value that can be converted to Photoshop's unsharp-mask threshold parameter. However in the API, a value of 0 threshold WAY oversharpens the image, and a value of 1 does about nothing. The documentation says: "The threshold in pixels needed to apply the difference amount" which doesn't make sense to me: a threshold should be a level above which the mask is applied, not some sort of pixel radius.

Does anybody know how to supply the threshold parameter to MagickUnsharpMaskImage so it behaves like the command-line? I tried looking at the source code, but couldn't find an explanation for the threshold.

Thanks very much.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "threshold" in MagickUnsharpMaskImage

Post by fmw42 »

try using the parameter definitions from the command line -unsharp at http://www.imagemagick.org/script/comma ... hp#unsharp
Hilbert

Re: "threshold" in MagickUnsharpMaskImage

Post by Hilbert »

Hi Fred - I tried threshold=0.05 but it results in a highly oversharpened image for amount=65, radius=4, sigma=1. A threshold value of about 0.22 seems about a right match for Photoshop unsharp mask (with a Photoshop threshold of 3). But if I change to: amount=225, radius=0.5, sigma=0.5, then threshold=0.22 no longer agrees with the equivalent Photoshop unsharp mask. I was hoping to avoid the exercise of determining what the threshold should be for all possible amounts and radii.

The API frequently takes slightly different input parameters than command-line ImageMagick, for reasons that are unclear to me. For sigmoidal-contrast, the documentation for one of the parameters was wrong. For this one, I can't figure it out: it doesn't seem to be a simple translation or equivalency of the command-line and API parameters, they seem to be fundamentally different. A zero threshold should mean the unsharp mask is applied evenly throughout the image, not make the sharpening stronger. In photoshop, the threshold doesn't make a big difference. In the API, the threshold value makes a huge huge difference in the amount of sharpening applied.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "threshold" in MagickUnsharpMaskImage

Post by fmw42 »

In IM, radiusxsigma has special meaning. The radius will determine how big WxH the window is that will contain a Gaussian filter whose profile has a standard deviation of sigma. There are two typical ways to use radiusxsigma. The first is the usual gaussian filter in which if you specify radius=0, sigma will be used to compute automatically a radius that will let the Gaussian profile drop close to zero. Typically a rough guide is radius=3xsigma.

The second way is use radiusxsigma in a special way to generate a uniform rather than gaussian profile, thus a simple average. This is done by specifying a sigma that is atleast 100xradius, such as radiusx65000. Then the radius will make a larger filter and cause more smoothing.

If you try mixing and matching radius and sigma you could get very unrealistic results where the radius is too small to allow the Gaussian profile to drop significantly.

I hope this helps. But as you say the API may be coded differently from the command line.


see http://www.imagemagick.org/script/comma ... s.php#blur for some details about radius x sigma
Post Reply