Page 1 of 1

Problems with threshold in Magick++

Posted: 2015-11-17T15:34:53-07:00
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

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

Posted: 2015-11-17T15:44:42-07:00
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.

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

Posted: 2015-11-17T15:54:59-07:00
by schcriher
Thank you very much!!! I spent the whole afternoon with this problem. I worked with 65535/2 (I have Q16). Cheers.