图像处理 - 使用opencv的装饰分割 [英] Image Processing - Dress Segmentation using opencv

查看:222
本文介绍了图像处理 - 使用opencv的装饰分割的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用opencv进行礼服功能识别。
作为第一步,我需要通过从图像中删除脸和手来分割t恤。

I am working on dress feature identification using opencv. As a first step, I need to segment t-shirt by removing face and hands from the image. Any suggestion is appreciated.

推荐答案

我建议采用以下方法:


  1. 使用Adrian Rosebrock的皮肤检测算法检测皮肤(感谢Rosa Gronchi为他的评论)
  2. >
  3. 在方差图上使用区域生长算法。使用阶段1可以计算初始种子。

  1. Use Adrian Rosebrock's skin detection algorithm for detecting the skin (thank you for Rosa Gronchi for his comment).
  2. Use region growing algorithm on the variance map. The initial seed can be calculated by using stage 1(see the attached code for more information).

代码:

%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));

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

result after stage 1(skin detection):

最终结果:

注释:


  1. 以下算法< a>。

  2. 地区增长功能可以在这里下载

  3. 解决方案并不完美。例如,如果衬衫的纹理类似于背景的纹理,则它可能失败。但我认为这是一个好的开始。

  4. 可以做的另一个改进是使用更好的区域生长算法,它不会增长到skinMask位置。此外,不是独立地使用区域生长算法,而是区域生长的第二次调用的结果可以基于第一个调用的结果。

  1. Stage 1 is calculated using the following algorithm.
  2. The region growing function can be downloaded here.
  3. The solution is not perfect. For example, it may fail if the texture of the shirt is similar to the texture of the background. But I think that it can be a good start.
  4. Another improvement which can be done is to use a better region growing algorithm, which doesn't grows into the skinMask location. Also, instead of using the region growing algorithm twice independently, the result of the second call of region growing can can be based on the result from the first one.

这篇关于图像处理 - 使用opencv的装饰分割的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆