cimagemagickmagickwand

Is there a bug in MagickUnsharpMaskImage method for MagickWand C?


I have a below CLI and trying to achieve same result using magickwand c. Everything seems to be perfect or don't know may be I missed something but the MagickUnsharpMaskImage is not working for me. Check my source code. I also attached source and two output images generated by CLI and C API.

CLI

convert testsharp.jpg -unsharp 0x1 unsharpC.jpg

C code

int main(int argc, char const *argv[]) {
    MagickWand * wand;
    wand = NewMagickWand();
    MagickReadImage(wand, "testsharp.jpg");
    MagickUnsharpMaskImage(wand, 0.0, 1.0, 0.0, 0.0);
    MagickWriteImage(wand, "unsharpW.jpg");
    return 0;
}

source image

enter image description here

output image using CLI

enter image description here

output image using C

enter image description here

ImageMagick version

Version: ImageMagick 7.0.5-5 Q16 x86_64 2017-05-23 http://www.imagemagick.org


Solution

  • From the man

    MagickUnsharpMaskImage() 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 and UnsharpMaskImage() selects a suitable radius for you.

    Emphasis mine

    You call it passing radius=0 sigma=1.0

    Moreover default value for those parameters are

    1. radius The radius of the Gaussian, in pixels, not counting the center pixel (default 0).
    2. sigma The standard deviation of the Gaussian, in pixels (default 1.0).
    3. gain The fraction of the difference between the original and the blur image that is added back into the original (default 1.0).
    4. threshold The threshold, as a fraction of QuantumRange, needed to apply the difference amount (default 0.05).

    Correct code to

    MagickUnsharpMaskImage(wand, 0.0, 1.0, 1.0, 0.05);