IsPixelWandSimilar behaviour changed?

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
Posts: 73
Joined: 2013-10-14T10:00:25-07:00
Authentication code: 6789

IsPixelWandSimilar behaviour changed?

Post by Danack » 2015-06-02T12:11:26-07:00


I'm seeing a change in behaviour for IsPixelWandSimilar. In ImageMagick-6.9.0-6 and other later versions as well the behaviour of the function for a set of tests ( ... milar.phpt ) works as expected.

For version ImageMagick-6.9.1-4 the behaviour is both different and appears to be wrong. I was going to say that the fuzz factor no longer needs to be scaled by the Quantum value. However the behaviour is more confusing than that, and I am not able to say exactly what is happening.

The code below is an extract from those tests - I can't figure out what the pattern is for the behaviour, but it seems that the behaviour of the function is now incorrect, no matter whether I scale the fuzz by QuantumRange or not.


Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <wand/MagickWand.h>

void testSimilar(char *color1, char *color2, float distance, int expectedResult) {

    float fuzz ;
    int status;

    PixelWand *pixel_wand_1 = NULL;
    PixelWand *pixel_wand_2 = NULL;

    pixel_wand_1 = NewPixelWand();    

    PixelSetColor(pixel_wand_1, color1);

    pixel_wand_2 = NewPixelWand();    
    PixelSetColor(pixel_wand_2, color2);

    fuzz = distance / sqrt(3);

    status = IsPixelWandSimilar(pixel_wand_1, pixel_wand_2, fuzz * QuantumRange);
    //Removing the quantum range makes the first test work, and the others fail... 
    //status = IsPixelWandSimilar(pixel_wand_1, pixel_wand_2, fuzz );

    printf("Expected %d actual %d for colors %s %s distance %f \n", expectedResult, status, color1, color2, distance);

int main(int argc,char **argv) {


    //Distance between points is 9.899494936611665
    testSimilar("rgba(0, 0, 0, 1)", "rgba(7, 7, 0, 1)", 9, 0);
    testSimilar("rgba(0, 0, 0, 1)", "rgba(7, 7, 0, 1)", 10, 1);
    //Distance between points is 10
    testSimilar("black", "rgba(10, 0, 0, 1.0)", 11, 1);

    //Distance between points is 10
    testSimilar("rgb(245, 0, 0)", "rgb(255, 0, 0)", 10, 1);


User avatar
Site Admin
Posts: 11039
Joined: 2003-05-31T11:32:55-07:00

Re: IsPixelWandSimilar behaviour changed?

Post by magick » 2015-06-02T17:18:10-07:00

We can reproduce the problem you posted and have a patch in ImageMagick 6.9.1-5 Beta, available by sometime tomorrow. Thanks.

Post Reply