MATLAB: Color segmentation of skin markers: HSV or Lab? How to choose thresholds

color classificationcolor detectioncolor segmentationcolor spacehsvImage Processing Toolboxlabskinyellow

I am pretty new to color image processing and now face the task of detecting colored skin markers like in the image below. In the cursory reading I've done, it seems like HSV and Lab are the color spaces of choice for distinguishing features based on color, but the reasoning why one would choose one over the other is not clear to me. My attempts so far have used HSV and I'm reasonably happy with the degree of segmentation accuracy I'm getting in the segmentation map to the right. It was generated using the function colorseghsv() below
imagesc(colorseghsv(A)); axis image off
However I'm wondering if Lab might be more appropriate or robust in this scenario for any reason. In this application, I will have a good deal of control over the lighting and color content of the image. For example, I've deliberately painted the markers in fluorescent colors to enhance them and that can always be made the case for all subjects.
I'm also wondering if there are more systematic ways of choosing thresholds for binning the color space coordinates. In my code below, the thresholds were chosen largely through a combination of trial and error and manually inspecting the HSV components of markers in a test image.
function segmap=colorseghsv(rgbImage)
hsv=rgb2hsv(rgbImage);
colors={'green','rose','blue','yellow','green'};
BW=false;
for i=1:length(colors)
BW=BW|markerbin(colors{i},hsv);
end
BW = imclose(BW,ones(5));
for ii=3:-1:1
Q=regionprops(BW,rgbImage(:,:,ii),'MeanIntensity');
cmap(:,ii)=vertcat(Q.MeanIntensity)/255;
end
segmap=label2rgb(bwlabel(BW),cmap,'k');
function bw=markerbin(label,hsv)
vthresh=.9;
H=hsv(:,:,1);
S=hsv(:,:,2);
V=hsv(:,:,3);
Vbin=V>=vthresh;
switch label
case 'blue'
Hbin=abs(H-.55)<=.1;
Sbin=S>=.5;
case 'yellow'
Hbin=abs(H-.16)<=.1;
Sbin=S>=.5;
case 'green'
Hbin=abs(H-.325)<=.1;
Sbin=S>=.5;
case 'orange'
Hbin=abs(H-.125)<=.025;
Sbin=S>=.5;
case 'rose'
Hbin=abs(H-.85)<=.1;
Sbin=S>=.5;
end
bw=Hbin&Sbin&Vbin;

Best Answer

Matt, welcome to the interesting field of image analysis - I think you'll find it fun and interesting to work with pictures. HSV is kind of like LAB color space except that you're using cylindrical coordinates instead of cartesian coordinates. So like in any regular 3D space, you can specify x,y,z or if you'd prefer, you can use radius, angle, and height. With either method you can specify a point/coordinate in the 3D space. It's the same with LAB and HSV (well almost but that's good enough for now).
So, cartesian space, LAB space, is good for thresholding or carving out rectangular boxes. Cylindrical space, HSV space, is good if you need to carve out a pie-shaped sector from the color space. It would be good if you could download ImageJ and use the Color inspector 3D ( http://rsb.info.nih.gov/ij/plugins/color-inspector.html) and install it so you can see your color image's gamut in the different color spaces so you can see which space is best to threshold in. Maybe later tonight I can capture a screenshot of your image and upload it.