Java RGBImageFilter:: SkinColor extraction. Equation to code
<p>I am building a simple face detection program based on <a href="http://cat.hfu.edu.tw/~b8403009/TD-006386.pdf" rel="nofollow">http://cat.hfu.edu.tw/~b8403009/TD-006386.pdf</a>.</p>

<p>Below is the original picture that I run into my filter.
<img src="http://i.stack.imgur.com/AJP40.jpg" alt="original "></p>

<p>Below is after the first condition if (g &lt; F1(r) and g > F2(r) and w > .001) return origianlPixel</p>

<p><img src="http://i.stack.imgur.com/bXrFA.jpg" alt="enter image description here">
There are lots of blue hues that are not being subtracted correctly but it is normal because the document states the issue and introduces the second condition that should subtract the blue hue, but here's the result of the second condition I have.
<img src="http://i.stack.imgur.com/rYbF5.jpg" alt="enter image description here"></p>

<p>I do not know why the blue hues are not being subtracted. Shouldn't it be subtracted? Or is it that the document is somehow less accurate? Or it could be that my code is somewhat less relevant. Please let me know if my interpretation of the equation to code is wrong. I would really appreciate the help</p>

<p>Below is my code.</p>

<pre><code>public int filterRGB(int x,int  y, int rgb){
    unpackRGB(rgb);
    //System.out.println(r + " " + g + " " + b);
    if(firstCondition() &amp;&amp; secondCondtion() ){ return rgb;}
    r=255;g=0;b=0; return toRGB((int)a,(int)r,(int)g,(int)b);
}

boolean firstCondition(){
    double a=this.a,r=this.r / max,g=this.g / max,b=this.b;
    return (g &lt; upperBound(r) &amp;&amp; g &gt; lowerBound(r) &amp;&amp; getW(r, g) &gt; .001);
}
boolean secondCondtion(){
    //taking blues away
    double c = Math.acos(
            (Math.abs((r-g) + (r-b))) /
            (2* Math.sqrt((r-g)*(r-g) + (r-b)*(g-b)))
            );
    c *= 180/Math.PI;
    if( b &gt;g ) c = 360 - c;
    return c &gt; 240 || c &lt; 20;
}
double upperBound(double r){return -1.376*r*r + 1.0743*r + .2;}
double lowerBound(double r){return -.776*r*r + .5601*r + .18;}
double getW(double r, double g){return (r-.33)*(r-.33) + (g-.33)*(g-.33);}
</code></pre>
