Image Processing - Dress Segmentation using opencv

徘徊边缘 提交于 2019-12-02 23:23:40

I suggest the following approach:

  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).

code:

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

result after stage 1(skin detection):

final result:

Comments:

  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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!