Comment by johnisgood

Comment by johnisgood 2 months ago

2 replies

So 0.5 is correct after all?! I thought I was completely off with 0.5 and I thought it does not align with human perception because I thought I was wrong. Ouch. In my defense, it has been a while. :D

BTW, would this relatively simple way to determine if the color is dark work?

  $luminance = 0.299 * $r + 0.587 * $g + 0.114 * $b;
  return $luminance < $threshold;
Where $threshold is 128, I think? IIRC 128 is a common threshold from what I remember, in this case.
Pinus 2 months ago

I once did it with 0.3R + 0.6G + 0.1B < 128, mostly because I could not be bothered to think deeper than that. It was certainly not perfect — there were obvious cases where the opposite choice of black or white for contrast would have been better — but it worked well enough for my purpose (making a label at least not unreadable regardless of background colour).

  • johnisgood 2 months ago

    I implemented something where contrast matters a lot, so I am using more sophisticated algorithms, but yeah, there are cases where you could get away with less sophisticated ones. :D