Skin color detection algorithm-Skin Color Detection Based on quadratic polynomial hybrid model.

Source: Internet
Author: User

Due to the inconsistency between the editing of the csdn blog and the blog garden, some images in the text are misplaced. To avoid affecting the browsing effect, we recommend that you click the open link.

Due to limited capabilities, there are very few innovations on the algorithm layer, many of which are learned from existing papers and then practiced.

This article involves a lot of algorithms, and there are also a lot of articles of the same type on the Internet, but it is certain that many of them are not code-worthy, or the included code is symbolic and slow, it is not elegant and has no practical value. This article attempts to solve these problems.

The order of algorithms in this article does not represent the superiority of the algorithm. It is just the random arrangement of the author.

1. quadratic polynomial hybrid model

The quadratic polynomial hybrid model was first proposed by Soriano and then improved by Chiang. The improved model consists of the quadratic polynomials of two R-G planes and a circular Square Program:

      

Based on the above three equations, the skin color area can be implemented using the following rules:

Reference Papers of the above algorithms: Adaptive Skin Color modeling using the skin locus.pdf

A novel method for detecting lips, eyes and faces in real time

Articles related to Baidu Library: A Rapid face detection algorithm based on the mixed skin color model

In the preceding formula, lowercase R, G, and B (not involved) are the normalized data for R/G/B (byte data, 0-255), namely:

As shown above, the algorithm involves a lot of floating point operations and a lot of multiplication. If you write code based on the original flavor of the source juice, the program efficiency can be imagined. Therefore, we are focusing on algorithm optimization.

First of all, let's look at the four judgment conditions. Because the judgment conditions are in no particular order and the places that need to be met at the same time are the regions, we should put the simple judgment conditions at the beginning for judgment.

First, if the judgment condition R4 is met, the R> G in the condition R3 must have been established, then you only need to determine whether G is greater than B, which is the optimization method 1.

Next, let's look at the optimization of R2. For the convenience of expression, we make sum = R + G + B and expand the judgment condition R2:

In theory, the last step is multiplied by 156 at the same time. In theory, 156 × 0.33 = 51.48, and 52 should not be taken. However, this 0.33 is originally an empirical data. Who would say it cannot be 1/3.

At this point, we can see that there is a floating point number 0.0624 at the far right of the formula. if this data is not eliminated, the algorithm speed will still be greatly affected, friends who often study shift must be familiar with the number 0.0625, Which is 1/16 = 0.0625. Don't you understand it? Don't you understand it. Check the Code. (many formulas here are empirical formulas, therefore, slightly modifying some parameters does not affect the result ).

The purpose of this operation is to convert all the floating point operations to integer operations.

Finally, let's look at the optimization of Type R1. R1 is actually two conditions, namely, R11 and R12. For R11, we also expand:

Currently, most PCs are still 32-bit systems. Therefore, 32-bit integer data types are the fastest. Therefore, if the above amplification factor is obtained, the values on both sides of the formula must be Int. minvalue and Int. maxvalue, such as the upper formula,> the maximum value of the formula on the left side of the number is 10000 × 255 × 765, which is smaller than Int. the range that maxvalue can express, so the amplification factor is reasonable.

FOR R12 expansion, I don't think I need to post it.

Algorithm reference code:

For (y = 0; y 

I really like optimization, especially at the code level. For example, the lower = 5601 * red * sum + 1766 * sum statement above, occasionally, I write the lower =-red * 7760 + 5601 * red * sum + 1766 * sum. Then, when I'm okay, I have compiled the differences between the two methods, the result is as follows:

Lower =-7760 * red + 5601 * red * sum + 1766 * sum; // extract the common multiplication here, which has no optimized effect: 00000118 imul EBX, ECX, 100000000011e imul EBX, ECx 00000121 imul eax, ECx, 15e1h 00000127 imul eax, ESI 0000012a add EBX, eax 0000012c imul eax, ESI, 6e6h 00000132 imul eax, ESI 00000135 add EBX, eax

 

Lower =-red * 7760 * + 5601 * red * sum + 1766 * sum; // The common multiplication method is extracted here. The optimization effect is basically not 00000118 mov EBX, ECx 0000011a neg EBX 0000011c imul EBX, ECx 0000011f imul EBX, EBX, 1e50h 00000125 imul EBX, EBX, 15e1h 0000012b imul EBX, ECx 0000012e imul EBX, ESI 00000131 imul eax, ESI, 6e6h 00000137 imul eax, ESI 0000013a add EBX, eax

It can be seen that there are two more Assembly statements. Maybe this optimization is not suitable here, because there is a coefficient-7760, generally no one will write like above, but if the coefficient is-1, then it is definitely better, for example, if it is-red + blue or blue-red, it has a completely different meaning.

The skin detection effect of this algorithm is still very good. The images in the original article are as follows:

Original Dream map synthesis Diagram

Then paste an example of a photo posted on someone else's blog (a group of handsome guys and beautiful women ):

Detection Result:

Because of its selective execution, the speed of program execution is actually related to the image content. For images of the same size, if the proportion of some sites on the skin is greater, the execution time may be longer. For the above 800*600 image, the result is only 4 ms in my I3 notebook, therefore, the speed is quite fast.

The test project is attached later.

* **************************** Basically, I do not provide source code, however, I will try to use text to clearly describe the corresponding algorithm or provide the reference documentation ************************* *

* ******************************* Because it is written by your own efforts and practices. the effect is exactly what you are, people must rely on their own ****************************

* ************************* Author: laviewpbt time: 2013.8.17 contact QQ: 33184777 reprinted. Please keep the information of this bank *************************

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.