public int ComputeValue(Point WinTopLeft, float SizeRatio, IntegralImage Image)
        {
            /*
             * a ------- b ------- c
             * -         -         -
             * -   R1    -    R2   -
             * -         -         -
             * d ------- e ------- f
             * -         -         -
             * -   R3    -    R4   -
             * -         -         -
             * g ------- h ------- i
             * S(R1) = e - (b + d) + a
             * S(R2) = f - (c + e) + b
             * S(R3) = h - (e + g) + d
             * S(R4) = i - (f + h) + e
             */

            var scaledFrame = this.Frame.Scale(SizeRatio);
            var topLeft = scaledFrame.TopLeft.NestedPoint(WinTopLeft);
            var rectsWidth = scaledFrame.Width / 2;
            var rectsHeight = scaledFrame.Height / 2;

            var aCoords = topLeft;
            var bCoords = aCoords.Translate(rectsWidth, 0);
            var cCoords = bCoords.Translate(rectsWidth, 0);

            var dCoords = aCoords.Translate(0, rectsHeight);
            var eCoords = dCoords.Translate(rectsWidth, 0);
            var fCoords = eCoords.Translate(rectsWidth, 0);

            var gCoords = dCoords.Translate(0, rectsHeight);
            var hCoords = gCoords.Translate(rectsWidth, 0);
            var iCoords = hCoords.Translate(rectsWidth, 0);

            var a = Image.GetValue(aCoords);
            var b = Image.GetValue(bCoords);
            var c = Image.GetValue(cCoords);
            var d = Image.GetValue(dCoords);
            var e = Image.GetValue(eCoords);
            var f = Image.GetValue(fCoords);
            var g = Image.GetValue(gCoords);
            var h = Image.GetValue(hCoords);
            var i = Image.GetValue(iCoords);

            var sumR1 = e - (b + d) + a;
            var sumR2 = f - (c + e) + b;
            var sumR3 = h - (e + g) + d;
            var sumR4 = i - (f + h) + e;

            return (int) (sumR1 - sumR2 - sumR3 + sumR4);
        }
        public int ComputeValue(Point WinTopLeft, float SizeRatio, IntegralImage Image)
        {
            /*
             * a ------- b
             * -         -
             * -   R1    -
             * -         -
             * c ------- d
             * -         -
             * -   R2    -
             * -         -
             * e ------- f
             * S(R1) = d - (b + c) + a
             * S(R2) = f - (d + e) + c
             */

            var scaledFrame = this.Frame.Scale(SizeRatio);
            var topLeft = scaledFrame.TopLeft.NestedPoint(WinTopLeft);
            var rectsWidth = scaledFrame.Width;
            var rectsHeight = scaledFrame.Height / 2;

            var aCoords = topLeft;
            var bCoords = aCoords.Translate(rectsWidth, 0);

            var cCoords = aCoords.Translate(0, rectsHeight);
            var dCoords = cCoords.Translate(rectsWidth, 0);

            var eCoords = cCoords.Translate(0, rectsHeight);
            var fCoords = eCoords.Translate(rectsWidth, 0);

            var a = Image.GetValue(aCoords);
            var b = Image.GetValue(bCoords);
            var c = Image.GetValue(cCoords);
            var d = Image.GetValue(dCoords);
            var e = Image.GetValue(eCoords);
            var f = Image.GetValue(fCoords);

            var sumR1 = d - (b + c) + a;
            var sumR2 = f - (d + e) + c;

            return (int) (sumR2 - sumR1);
        }
示例#3
0
        /// <summary>
        /// Retourne la dispertion de la valeur des pixels
        /// contenus dans la fenêtre/
        /// </summary>
        private int GetDeviation(IntegralImage Image, IntegralImage SquaredImage)
        {
            /*
             * a -------- b
             * -          -
             * -  Window  -
             * -          -
             * c -------- d
             *
             * sum = d - (b + c) + a
             * avg = sum / nPixs
             * deriv = sqrt(sum(pixs²) / nPixs - avg(pixs))
             */

            var nPixs = this.Width * this.Height;

            var aCoords = this.TopLeft;
            var bCoords = aCoords.Translate(this.Width, 0);

            var cCoords = aCoords.Translate(0, this.Height);
            var dCoords = cCoords.Translate(this.Width, 0);

            var a = Image.GetValue(aCoords);
            var b = Image.GetValue(bCoords);
            var c = Image.GetValue(cCoords);
            var d = Image.GetValue(dCoords);

            var squaredA = SquaredImage.GetValue(aCoords);
            var squaredB = SquaredImage.GetValue(bCoords);
            var squaredC = SquaredImage.GetValue(cCoords);
            var squaredD = SquaredImage.GetValue(dCoords);

            var sum = d - (b + c) + a;
            var squaredSum = squaredD - (squaredB + squaredC) + squaredA;

            var avg = sum / nPixs;

            var variance = squaredSum / nPixs - avg*avg;

            // Min 1 to remove division by zero
            if (variance > 0)
                return (int) Math.Sqrt(variance);
            else
                return 1;
        }