图像处理 - 使用opencv进行着装分割

Ama*_*h R 14 matlab image-processing computer-vision image-segmentation opencv3.0

图片

我正在使用opencv进行服装特征识别.作为第一步,我需要通过从图像中移除面部和手部来分割T恤.任何建议表示赞赏.

dro*_*rco 20

我建议采用以下方法:

  1. 使用Adrian Rosebrock的皮肤检测算法检测皮肤(感谢Rosa Gronchi的评论).
  2. 在方差图上使用区域增长算法.可以使用第1阶段计算初始种子(有关详细信息,请参阅附带的代码).

码:

%stage 1: skin detection -  Adrian Rosebrock solution
im = imread(<path to input image>);
hsb = rgb2hsv(im)*255;

skinMask = hsb(:,:,1) > 0 & hsb(:,:,1) < 20;
skinMask = skinMask & (hsb(:,:,2) > 48 & hsb(:,:,2) < 255);
skinMask = skinMask & (hsb(:,:,3) > 80 & hsb(:,:,3) < 255);
skinMask = imclose(skinMask,strel('disk',6));

%stage 2: calculate top, left and right centroid from the different connected
%components of the skin
stats = regionprops(skinMask,'centroid');
topCentroid = stats(1).Centroid;
rightCentroid = stats(1).Centroid;
leftCentroid = stats(1).Centroid;
for x = 1 : length(stats)
    centroid = stats(x).Centroid;
    if topCentroid(2)>centroid(2)
        topCentroid = centroid;
    elseif centroid(1)<leftCentroid(1)
        leftCentroid = centroid;
    elseif centroid(1)>rightCentroid(1)
        rightCentroid = centroid;
    end
end

%first seed - the average of the most left and right centroids.
centralSeed = int16((rightCentroid+leftCentroid)/2);

%second seed - a pixel which is right below the face centroid.
faceSeed = int16(topCentroid);
faceSeed(2) = faceSeed(2)+40; 

%stage 3: std filter
varIm = stdfilt(rgb2gray(im));

%stage 4 - region growing on varIm  using faceSeed and centralSeed
res1=regiongrowing(varIm,centralSeed(2),centralSeed(1),8);
res2=regiongrowing(varIm,faceSeed(2),faceSeed(1),8);
res = res1|res2;

%noise reduction
res = imclose(res,strel('disk',3));
res = imopen(res,strel('disk',2));
Run Code Online (Sandbox Code Playgroud)

第1阶段(皮肤检测)后的结果:

皮肤检测

最后结果:

最后结果

评论:

  1. 使用以下算法计算阶段1 .
  2. 区域增长功能可以在这里下载.
  3. 解决方案并不完美.例如,如果衬衫的纹理与背景的纹理相似,则可能会失败.但我认为这可能是一个良好的开端.
  4. 可以做的另一个改进是使用更好的区域增长算法,该算法不会增长到skinMask位置.而且,代替独立地两次使用区域增长算法,区域增长的第二次调用的结果可以基于来自第一次调用的结果.

  • 很好的答案.+1. (3认同)