You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I've noticed a problem in the isDistinct method while comparing colors in a black and white picture.
I was comparing black (RGB 0, 0, 0) and white (RGB 1, 1, 1) and I noticed that the method only compares colors channels by subtracting R and G channels and then R and B channels.
So 0 - 0 < threshold and 1 - 1 < threshold, resulting in white and black colors being considered as not distinct, returning only one color while processing my image.
I then added a control for luminance as well, so if the colors are both in a grey scale AND their luminance is within the threshold, then consider them to be similar, otherwise not.
// Check for grays if (abs(r - g < 0.03f && fabs(r - b) < 0.03f)) { if (fabs(rc - gc) < 0.03f && (fabs(rc - bc) < 0.03f)){ //Also check for luminance!! if(fabs([self luminance] - [color luminance]) < threshold){ return NO; }else{ return YES; } ...
After this, the color extraction works for B&W images as well, returning a grey scale palette.
I hope this can help you!
The text was updated successfully, but these errors were encountered:
Hi, I've noticed a problem in the isDistinct method while comparing colors in a black and white picture.
I was comparing black (RGB 0, 0, 0) and white (RGB 1, 1, 1) and I noticed that the method only compares colors channels by subtracting R and G channels and then R and B channels.
So 0 - 0 < threshold and 1 - 1 < threshold, resulting in white and black colors being considered as not distinct, returning only one color while processing my image.
I then added a control for luminance as well, so if the colors are both in a grey scale AND their luminance is within the threshold, then consider them to be similar, otherwise not.
// Check for grays
if (abs(r - g < 0.03f && fabs(r - b) < 0.03f)) {
if (fabs(rc - gc) < 0.03f && (fabs(rc - bc) < 0.03f)){
//Also check for luminance!!
if(fabs([self luminance] - [color luminance]) < threshold){
return NO;
}else{
return YES;
}
...
After this, the color extraction works for B&W images as well, returning a grey scale palette.
I hope this can help you!
The text was updated successfully, but these errors were encountered: