1

Given an image, how do I go about determining if a certain pixel is "white" ? Based on Wikipedia, I understand that if the RGB values are at (255,255,255), the pixel is considered white and that a lower similar set of values for eg. (200,200,200) would mean that it is a "darker shade of white" i.e. gray.

Should I just set a threshold of example 80% for each channel and if the RGB at a certain pixel passes that condition then it is marked as gray/white ? Are there any papers that I can read up for help ?

Regards, Haziq

Steve Lillis
  • 3,263
  • 5
  • 22
  • 41
RuiQi
  • 488
  • 2
  • 14

2 Answers2

1

The solution is to convert your color space from RGB to HSV. Here is sample algorithm thread. Finally apply threshold in Value (Lightness) Channel to filter bright region.

Community
  • 1
  • 1
Balaji R
  • 1,805
  • 22
  • 41
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – toesslab Jun 25 '15 at 17:21
  • 1
    @pc-shooter Only when this site get crashed & abandoned :P – Balaji R Jun 25 '15 at 17:33
1

If you simply threshold all channels at, say 200, you are allowing the Red to differ from the Green and that to differ from the Blue, which means you are allowing colour into your images and all the following colours would be permitted:

enter image description here

You need to ensure that, not only are Red, Green and Blue above 200, but further that they are equal. That way you only permit this range:

enter image description here

In the HSL model, you need Lightness to be above say 80%, but also the Saturation to be zero to ensure white/gray.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432