Page 1 of 1

IsPixelWandSimilar behaviour changed?

Posted: 2015-06-02T12:11:26-07:00
by Danack
Hi,

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 ( https://github.com/mkoppanen/imagick/bl ... 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.

cheers
Dan

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) {

    MagickWandGenesis();

    //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);

    MagickWandTerminus();
    
    return(0);
}

Re: IsPixelWandSimilar behaviour changed?

Posted: 2015-06-02T17:18:10-07:00
by magick
We can reproduce the problem you posted and have a patch in ImageMagick 6.9.1-5 Beta, available by sometime tomorrow. Thanks.