3

I'm doing skin detection algorithm according to this article. There are two models at page 21: Mixture of Gaussian Skin and Non-skin Color Model.

The first model for skin detection works exellent. There are examples:

1)Orginal image:

enter image description here

2) Skin mask

enter image description here

But the non-skin model gives wrong results:

enter image description here

Here is my code:

 ipl_image_wrapper NudityDetector::filterPixelsWithGMM(const float covarinceMatrix[][3], const float meanMatrix[][3], const float weightVector[], const float probValue) const
{   
    ipl_image_wrapper mask = cvCreateImage(cvGetSize(m_image.get()), IPL_DEPTH_8U, 1);

    double probability = 0.0;
    float x[3] = { 0, 0, 0};

     for(int i = 0; i < m_image.get()->height; ++i)
    {
        for(int j = 0; j < m_image.get()->width; ++j)
        {
            if (m_image.get()->nChannels == 3)
            {
                x[0] = (reinterpret_cast<uchar*>(m_image.get()->imageData + i * m_image.get()->widthStep))[j * 3 + 2];
                x[1] = (reinterpret_cast<uchar*>(m_image.get()->imageData + i * m_image.get()->widthStep))[j * 3 + 1];
                x[2] = (reinterpret_cast<uchar*>(m_image.get()->imageData + i * m_image.get()->widthStep))[j * 3];

                double cov_det = 0.0;
                double power = 0.0;

                double A1 = 0.0;
                double A2 = 0.0;
                double A3 = 0.0;

                probability = 0;

                for (int k = 0; k < 16; ++k)
                {
                    cov_det = covarinceMatrix[k][0] * covarinceMatrix[k][1] * covarinceMatrix[k][2];

                    A1 = covarinceMatrix[k][1] * covarinceMatrix[k][2];
                    A2 = covarinceMatrix[k][0] * covarinceMatrix[k][2];
                    A3 = covarinceMatrix[k][0] * covarinceMatrix[k][1];

                    power =(std::pow((x[0] - meanMatrix[k][0]), 2) * A1 +
                            std::pow((x[1] - meanMatrix[k][1]), 2) * A2 +
                            std::pow((x[2] - meanMatrix[k][2]), 2) * A3 ) / (2 * cov_det);

                     probability += 100 * weightVector[k] *std::exp(-power) / (std::pow(2 * M_PI, 3/2) * std::pow(cov_det, 1/2));
                }

                if ( probability < probValue)
                {
                    (reinterpret_cast<uchar*>(mask.get()->imageData + i * mask.get()->widthStep))[j] = 0;
                }
                else
                {
                    (reinterpret_cast<uchar*>(mask.get()->imageData + i * mask.get()->widthStep))[j] = 255;
                }
            }
        }
    }

    cvDilate(mask.get(), mask.get(), NULL, 2);
    cvErode(mask.get(), mask.get(), NULL, 1);

    return mask;
}

ipl_image_wrapper NudityDetector::detectSkinWithGMM(const float probValue) const
{
   //matrices are from article
    ipl_image_wrapper mask = filterPixelsWithGMM(COVARIANCE_SKIN_MATRIX, MEAN_SKIN_MATRIX, SKIN_WEIGHT_VECTOR, probValue);

    return mask;
 }

ipl_image_wrapper NudityDetector::detectNonSkinWithGMM(const float probValue) const
{
    //matrices are from article
   ipl_image_wrapper mask = filterPixelsWithGMM(COVARIANCE_NON_SKIN_MATRIX, MEAN_NON_SKIN_MATRIX, NON_SKIN_WEIGHT_VECTOR, probValue);

   return mask;
 }

What I'm doing wrong? Maybe I misunderstand the meaning of tre article? Or I translated formula wrong in the code?

Thank you in advance!

4

1 回答 1

2

事实上,结果似乎没有任何问题,非皮肤模型正确地将非皮肤区域识别为 255,将皮肤区域正确识别为 0。您可能只需将参数调整probValue为较低的值即可消除一些假阴性(小的非皮肤区域)

GMM 可能不是皮肤检测的有效方法,您可以使用一些边缘强度信息作为正则化参数,以便检测到的区域不会被分割。

于 2013-06-25T10:12:27.383 回答