For my online collage machine I need to make transparent a range of colors between colour X and color Y.
Code: Select all
$image->paintTransparentImage ( $color_x , 0 , $fuzzyness );
Code: Select all
$col_x = $color_x->getColor();
$col_y = $color_y->getColor();
$fuzzyness = sqrt( pow ($col_x['r'] - $col_y['r'] , 2) + pow( $col_x['g'] - $col_y['g'] , 2) + pow( $col_x['b'] - $col_y['b'] , 2) ) * 256;
I then tried a rather boorish function that also gave to high values (according to some visual tests) and took too long to calculate the fuzzyness between a whole histogram of colors.
Code: Select all
function fuzz($a,$b){
//$a:ImagickPixel
//$b:ImagickPixel
//returns:float
if (is_object($a) && is_object($b)){
$i =0;
$hit = false;
while (!$hit){
$hit = $a->isSimilar ($b, $i);
$i ++;
}
return $i;
}
else{
return 0;
}
}
Does anyone know how Image Magick determines the fuzzyness between two colors?
Thanks in advance,
Fabian