+6  A: 

Ed,

You do not need to loop:

>> a  = magic(5)

a =

    17    24     1     8    15
    23     5     7    14    16
     4     6    13    20    22
    10    12    19    21     3
    11    18    25     2     9


>> vi = (a > 5) & (a < 10)

vi =

     0     0     0     1     0
     0     0     1     0     0
     0     1     0     0     0
     0     0     0     0     0
     0     0     0     0     1

You can see how this statement could be expanded for RGB and such. I would make a function


function out = isFlesh(in)

%% put flesh checking code here


I suspect you are going to want a range of these (isCaucasian, isAsian, etc...) The problem is going to be that there is a huge range of flesh colors, so you are going to want to check for proximity to neighbors of a similar color range.

This part of the problem is easy, but the larger problem is fraught with peril.

-Doug

MatlabDoug
HSV space solves the problem of skin colour, as all the different colours are just variations in melanin, so they're technically the same in HSV space (with different saturation, I believe). But thanks for the comments and the answer, MATLAB's syntax always messes with me!
Ed Woodcock
+4  A: 

One thing to keep in mind is that RGB images are 3-D matrices. The first "page" (i.e. A(:,:,1)) is red, the second is green, and the third is blue. Sometimes I find it easier to operate on RGB matrices by reshaping them into N-by-3 matrices where all the red pixels are in column 1, the green in column 2, and the blue in column 3. This is how to do it:

A = (a 3-D RGB image);
matSize = size(A);
A = reshape(A,prod(matSize(1:2)),3);
...
% Modify or extract data from reshaped matrix
...
A = reshape(A,matSize);  % Return A to original dimensions

Not sure if this will help you specifically with what you want to do , but I often find it useful.

gnovice
+3  A: 

Thresholding every channel is not a very robust way of doing skin color detection. A simple lookup table works much better. The lookup table would record a value for each color how likely it is to be skin. There are various skin color datasets which you can use to obtain such values. Then you can compare the color of the pixel against the value in the table and do a decision based on a threshold.

M456

related questions