NudityDetector.php
public function quantifyYCbCr() {

        // Init some vars
        $inc = $this->iteratorIncrement;
        $width = $this->width();
        $height = $this->height();
        list($Cb1, $Cb2, $Cr1, $Cr2) = $this->boundsCbCr;
        $white = $this->excludeWhite;
        $black = $this->excludeBlack;
        $total = $count = 0;

        for($x = 0; $x < $width; $x += $inc)
            for($y = 0; $y < $height; $y += $inc) {
                list($r, $g, $b) = $this->rgbXY($x, $y);

                // Exclude white/black colors from calculation, presumably background
                if((($r > $white) && ($g > $white) && ($b > $white)) ||
                    (($r < $black) && ($g < $black) && ($b < $black))) continue;

                // Converg pixel RGB color to YCbCr, coefficients already divided by 255
                $Cb = 128 + (-0.1482 * $r) + (-0.291 * $g) + (0.4392 * $b);
                $Cr = 128 + (0.4392 * $r) + (-0.3678 * $g) + (-0.0714 * $b);

                // Increase counter, if necessary
                if(($Cb >= $Cb1) && ($Cb <= $Cb2) && ($Cr >= $Cr1) && ($Cr <= $Cr2))
                    $count++;
                $total++;
            }

        return $count / $total;
    }
public function quantifyYCbCr() {

        // Init some vars
        $inc = $this->iteratorIncrement;
        $width = $this->width();
        $height = $this->height();
        list($Cb1, $Cb2, $Cr1, $Cr2) = $this->boundsCbCr;
        $white = $this->excludeWhite;
        $black = $this->excludeBlack;
        $total = $count = 0;

        for($x = 0; $x < $width; $x += $inc)
            for($y = 0; $y < $height; $y += $inc) {
                list($r, $g, $b) = $this->rgbXY($x, $y);

                // Exclude white/black colors from calculation, presumably background
                if((($r > $white) && ($g > $white) && ($b > $white)) ||
                    (($r < $black) && ($g < $black) && ($b < $black))) continue;

                // Converg pixel RGB color to YCbCr, coefficients already divided by 255
                $Cb = 128 + (-0.1482 * $r) + (-0.291 * $g) + (0.4392 * $b);
                $Cr = 128 + (0.4392 * $r) + (-0.3678 * $g) + (-0.0714 * $b);

                // Increase counter, if necessary
                if(($Cb >= $Cb1) && ($Cb <= $Cb2) && ($Cr >= $Cr1) && ($Cr <= $Cr2))
                    $count++;
                $total++;
            }

        return $count / $total;
    }
public function quantifyYCbCr ( ) { // Init some vars $ inc = $ this -> iteratorIncrement ; $ width = $ this -> width ( ) ; $ height = $ this -> height ( ) ; list ( $ Cb1 , $ Cb2 , $ Cr1 , $ Cr2 ) = $ this -> boundsCbCr ; $ white = $ this -> excludeWhite ; $ black = $ this -> excludeBlack ; $ total = $ count = 0 ; for ( $ x = 0 ; $ x < $ width ; $ x += $ inc ) for ( $ y = 0 ; $ y < $ height ; $ y += $ inc ) { list ( $ r , $ g , $ b ) = $ this -> rgbXY ( $ x , $ y ) ; // Exclude white/black colors from calculation, presumably background if ( ( ( $ r > $ white ) && ( $ g > $ white ) && ( $ b > $ white ) ) || ( ( $ r < $ black ) && ( $ g < $ black ) && ( $ b < $ black ) ) ) continue ; // Converg pixel RGB color to YCbCr, coefficients already divided by 255 $ Cb = 128 + ( - 0.1482 * $ r ) + ( - 0.291 * $ g ) + ( 0.4392 * $ b ) ; $ Cr = 128 + ( 0.4392 * $ r ) + ( - 0.3678 * $ g ) + ( - 0.0714 * $ b ) ; // Increase counter, if necessary if ( ( $ Cb >= $ Cb1 ) && ( $ Cb <= $ Cb2 ) && ( $ Cr >= $ Cr1 ) && ( $ Cr <= $ Cr2 ) ) $ count ++ ; $ total ++ ; } return $ count / $ total ; }
Quantify flesh color amount using YCbCr color model

@return float
Quantify flesh color amount using YCbCr color model