Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isDistinct problem with B&W photos #6

Open
Havock94 opened this issue Jun 12, 2017 · 1 comment
Open

isDistinct problem with B&W photos #6

Havock94 opened this issue Jun 12, 2017 · 1 comment

Comments

@Havock94
Copy link
Contributor

Havock94 commented Jun 12, 2017

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!

@timominous
Copy link
Owner

@Havock94 Feel free to submit a PR on this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants