Beispiel #1
0
        public override T Accumulate(AccumulationState <T> state)
        {
            var kcp  = Convolution.GetKernelCenterPoint(state.Kernel);
            var ksum = Convolution.GetKernelSum(state.Kernel);
            var acc  = default(T);

            if (state.ImageRow < kcp.Item1 || state.ImageRow >= (state.Image.RowCount - kcp.Item1))
            {
                return(acc);
            }

            if (state.ImageColumn < kcp.Item2 || state.ImageColumn >= (state.Image.ColumnCount - kcp.Item2))
            {
                return(acc);
            }

            for (var rk = -kcp.Item1; rk <= +kcp.Item1; rk++)
            {
                for (var ck = -kcp.Item2; ck <= +kcp.Item2; ck++)
                {
                    var w = state.Kernel[kcp.Item1 + rk, kcp.Item2 + ck] / ksum;
                    acc = this.accumulate(acc, state.Image[state.ImageRow + rk, state.ImageColumn + ck], w);
                }
            }

            return(acc);
        }
Beispiel #2
0
        public override T Accumulate(AccumulationState <T> state)
        {
            var kcp  = Convolution.GetKernelCenterPoint(state.Kernel);
            var ksum = Convolution.GetKernelSum(state.Kernel);
            var acc  = default(T);

            for (var rk = -kcp.Item1; rk <= +kcp.Item1; rk++)
            {
                for (var ck = -kcp.Item2; ck <= +kcp.Item2; ck++)
                {
                    T b;

                    if (state.ImageRow + rk < 0 || state.ImageRow + rk >= state.Image.RowCount)
                    {
                        b = state.Image[state.ImageRow - rk, state.ImageColumn];
                    }
                    else if (state.ImageColumn + ck < 0 || state.ImageColumn + ck >= state.Image.ColumnCount)
                    {
                        b = state.Image[state.ImageRow, state.ImageColumn - ck];
                    }
                    else
                    {
                        b = state.Image[state.ImageRow + rk, state.ImageColumn + ck];
                    }

                    var w = state.Kernel[kcp.Item1 + rk, kcp.Item2 + ck] / ksum;
                    acc = this.accumulate(acc, b, w);
                }
            }

            return(acc);
        }
Beispiel #3
0
        public override T Accumulate(AccumulationState <T> state)
        {
            var kcp  = Convolution.GetKernelCenterPoint(state.Kernel);
            var ksum = Convolution.GetKernelSum(state.Kernel);
            var acc  = default(T);

            for (var rk = -kcp.Item1; rk <= +kcp.Item1; rk++)
            {
                for (var ck = -kcp.Item2; ck <= +kcp.Item2; ck++)
                {
                    var rt = state.ImageRow + rk;
                    var ct = state.ImageColumn + ck;

                    if (rt < 0)
                    {
                        rt = state.Image.RowCount + rk;
                    }

                    if (rt >= state.Image.RowCount)
                    {
                        rt = rk;
                    }

                    if (ct < 0)
                    {
                        ct = state.Image.ColumnCount + ck;
                    }

                    if (ct >= state.Image.ColumnCount)
                    {
                        ct = ck;
                    }

                    var w = state.Kernel[kcp.Item1 + rk, kcp.Item2 + ck] / ksum;
                    acc = this.accumulate(acc, state.Image[rt, ct], w);
                }
            }

            return(acc);
        }