رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
درخواست پیشنهاد برای بهینه کردن کد
#1
function quantify() {
        
        $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;
    }

دوستان این کد رو نگا کنید، هر ایده ای به ذهنتون میرسه که سرعتش رو افزایش بدم بگید. حدود 3 میلیون بار توی حلقه باید این کد اجرا بشه و سرعتش مهمه!
پاسخ
تشکر شده توسط:
#2
UP...
پاسخ
تشکر شده توسط:




کاربران در حال بازدید این موضوع: 1 مهمان