Problems with threshold in Magick++

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
schcriher
Posts: 2
Joined: 2015-11-17T14:08:03-07:00
Authentication code: 1151

Problems with threshold in Magick++

Post by schcriher »

I'm trying to replicate a fingerprint generator [1]. I have it running on the command-line version, but when translated into C++ found a bug with threshold.

Test image:
Image

Running from command line:

Code: Select all

convert test.png -threshold 50% test_1.png
Is obtained:
Image

This is ok.

The following code should be the same (true?)

Code: Select all

#include <Magick++.h>
int main(int argc, char **argv) {
    Magick::Image image;
    image.read(argv[1]);
    image.threshold(50);  // test:  0  0.5  1  50  100  -50  -100  -0.5  50.0
    image.write(argv[2]);
    return 0;
}
Compiling:

Code: Select all

g++ $(Magick++-config --cppflags --cxxflags --ldflags --libs) -O2 -Wall main.cpp -o main
Running:

Code: Select all

./main test.png test_2.png
Is obtained:
Image

This is wrong, why? (It is as if all that was not black passed to white). I found no mention of it anywhere on this issue. Here I use only "threshold" because it is what gives me problems.

Thank you very much in advance for any comments, suggestions or help.


Ref:
[1] http://www.jhnc.org/findimagedupes/

ImageMagick Version 6.7.7-10 (command line and Magick++)
g++ Version 4.9.2
OS GNU/Linux Debian Wheezy
Last edited by schcriher on 2015-11-17T17:46:02-07:00, edited 2 times in total.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Problems with threshold in Magick++ (bug?)

Post by dlemstra »

You should specify a value in the quantum range and not a percentage. Instead of 50 you need to specify 65535 (Q16) or 255 (Q8) / 2.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
schcriher
Posts: 2
Joined: 2015-11-17T14:08:03-07:00
Authentication code: 1151

Re: Problems with threshold in Magick++ (bug?)

Post by schcriher »

Thank you very much!!! I spent the whole afternoon with this problem. I worked with 65535/2 (I have Q16). Cheers.
Post Reply