Detect colors close to white
23 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
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
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.)
More Answers (2)
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.
0 Comments
Ning Wu
on 26 Aug 2015
7 Comments
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
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.
See Also
Categories
Find more on Image Filtering and Enhancement in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!