Detect colors close to white

23 views (last 30 days)
Ning Wu
Ning Wu on 21 Aug 2015
Commented: Image Analyst on 31 Aug 2015
Which color space should I use if I need to find pixels close to white. For example, I start with RGB space, where white would be (255,255,255). So, anything close to it would be white. But, how much difference is tolerable. Is it OK to go to 230 in R domain; and 220 in Blue etc. (these values are just examples) while keeping other color components constant.
Or is there a better color space than RGB where I can go. And how to find colors closer to white there.

Accepted Answer

John D'Errico
John D'Errico on 22 Aug 2015
Edited: John D'Errico on 22 Aug 2015
RGB is not sufficiently uniform to be usable here.
Convert to L*a*b*. Then just compute the Euclidean distance (often called delta E) from white. Anything within a given radius will be "close". You need only choose the radius then.
  3 Comments
Stephen23
Stephen23 on 27 Aug 2015
Edited: Stephen23 on 27 Aug 2015
This gives a good introduction to the topic: https://en.wikipedia.org/wiki/Color_difference
John D'Errico
John D'Errico on 27 Aug 2015
HSL is not really a good choice at all here.
You want something that is as uniform as possible, since you will be computing a 3-d Euclidean distance. The variables in an HSL encoding do not even have the same units, since one of them is degrees.
Again, compute the Euclidean distance in Lab. This is reasonably good. (Not perfect, although I think I recall a paper by Hung and Berns that tried to adjust Lab for better uniformity.)

Sign in to comment.

More Answers (2)

Image Analyst
Image Analyst on 27 Aug 2015
Compute the delta E between the image and the white lab:
lab = rgb2lab(rgbImage);
lImage = lab(:,:,1);
aImage = lab(:,:,2);
bImage = lab(:,:,3);
Then compute the delta between them and the white values
deltaL = LWhite - lImage;
Same for a and b, then add a fraction of the delta image to your test image, then convert back with lab2rgb(). The fraction ranges from 0 for no change to 1 which will make the image all the white value.

Ning Wu
Ning Wu on 26 Aug 2015
Thanks, John. This helps. I have one more question: how can one enhance the whiteness in image. Specifically, let a pixel p_1 be d distance away from white in Lab space, i.e., deltaE of white, and p_1 is d. Then how can we move p_1 closer to white if want to enhance the whiteness in image. One option would be to go in RGB space and enhance pixels there. But, is there a way for doing it in some other color space; and how.
  7 Comments
Alex Burt
Alex Burt on 31 Aug 2015
Operating on L channel only does not help. The problem is that at the boundaries of the interesting region, L inside/outside boundary is different, but gradually changing. Modifying pixels inside the region by a factor makes a big discontinuity at the boundaries for L which is indeed visible. Is there a way this can be mitigated.
Image Analyst
Image Analyst on 31 Aug 2015
Of course there will be a difference between pixels you modified inside and outside the ROI. And if that difference is great enough, then there can be a noticeable boundary or edge created. But you should not have strange hue effects there, like bright red or blue pixels like you would if you had operated on all channels because you're not changing the hue.
To soften the effects of an ROI edge, you need to do anti-aliasing, like is done in Photoshop. Basically blurring/interpolating the values inside and outside over a band of a few pixels thick around the ROI boundary.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!