示例#1
0
        /// <summary>
        /// Applies the box filter kernel around one pixel.
        /// </summary>
        /// <param name="original">The original image to blur</param>
        /// <param name="target">The result</param>
        /// <param name="centerRow">Vertical coordinate of the result pixel</param>
        /// <param name="centerCol">Horizontal coordinate of the result pixel</param>
        protected virtual void Kernel(ImageBase original, ImageBase target, int centerRow, int centerCol)
        {
            int top    = Math.Max(0, centerRow - radius);
            int bottom = Math.Min(original.Height - 1, centerRow + radius);
            int left   = Math.Max(0, centerCol - radius);
            int right  = Math.Min(original.Width - 1, centerCol + radius);

            int   area          = (bottom - top + 1) * (right - left + 1);
            float normalization = 1.0f / area;

            for (int chan = 0; chan < original.NumChannels; ++chan)
            {
                float result = 0;
                for (int row = top; row <= bottom; ++row)
                {
                    for (int col = left; col <= right; ++col)
                    {
                        result += original.GetPixelChannel(col, row, chan) * normalization;
                    }
                }
                target.SetPixelChannel(centerCol, centerRow, chan, result);
            }
        }