What is the background theory of this Skin Detection in RGB code?

1 view (last 30 days)
Hi, I am new to MATLAB and here too. I would like to know more about how the following code works and its background theory.
Currently I am doing my Bachelor Thesis about gesture recognition. For skin detection I found the following code on YouTube whose author is Anirudh Sharma ( https://www.youtube.com/watch?v=gvtqSJx3Y98 ). The most important part of the code looks like this (based on my implement):
vid = videoinput('winvideo',1,'RGB24_640x480');
... %Some webcam setup code after this
data = getsnapshot(vid);
I = imsubtract(data(:,:,1), rgb2gray(data));
I = medfilt2(I,[3 3]);
I = imadjust(I);
level = graythresh(I);
Ibw = im2bw(I,level);
I know it is unusual to use RGB color space to detect skin instead of YCrCb, HSV, etc... but turned out it worked pretty well, fast and robust - especially with a monotone background. But the point is, how could the skin-toned region appears clearly on the background after subtracting the Grayscale from the Red plane (I = imsubtract(data(:,:,1), rgb2gray(data));)? Is there a theory background of this?
So far I haven't found yet any reliable document about this. I also have no hope contacting the author as his video was uploaded 2 years ago and his email or Google+ on his YouTube account are unavailable. I know some people have already asked about this code before but none of them satisfy me. Therefore it would be great if there is an theoretical and practical explanation about this.
Thank you so much in advance.

Accepted Answer

Image Analyst
Image Analyst on 19 Sep 2015
It can work in RGB color space for certain controlled situations, like skin tones that are similar and illumination levels and color that are consistent. It's not the most robust way to do it but it can work provided everything works out just right.
But I'm not sure what your question means. "how could the skin-toned region appears clearly on the background after subtracting the Grayscale from the Red plane" What does that mean - appears clearly? Do you want to mask out the non-skin so that it's black? Or what???
  5 Comments
Image Analyst
Image Analyst on 21 Sep 2015
Well look at your hand. See how it's the same color (intensity) as the background? Try it also with the blue channel and you'll see the hand won't be the same color - it will be darker. Also post your background image (the one without the hand in there at all).
Thanh Nguyen Bui
Thanh Nguyen Bui on 24 Sep 2015
Sorry for the long delay, it took some time for me to came back to the lab room with the same background. Yeah after some more experiments I got your point. Here are what I got:
Red, Green, Blue channel of the background:
It is true that they have almost the same intensity, while the hand is not. Now with the hand included:
Subtracting the Grayscale from the Green channel
Subtracting the Grayscale from the Blue channel
The hands are not visible at all. So can I say that it isn't actually "Skin Detection" but a kind of Background Subtraction that leave the hand visible?
Anyways, thank you so much for your support. I now have clearer view of what I am doing.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!