示例#1
0
        public const int r = 4; // specifies the size of the filter

        public void Run(ImageProcessor ip)
        {
            int M    = ip.Width;
            int N    = ip.Height;
            var copy = ip.Duplicate();

            // Vector to hold the pixels from (2r+1)x(2r+1) neighborhood
            int[] A = new int[(2 * r + 1) * (2 * r + 1)];

            // Index of center vector element
            int n = 2 * (r * r + r);

            for (int u = r; u <= M - r - 2; u++)
            {
                for (int v = r; v <= M - r - 2; v++)
                {
                    // Fill the pixel vector A for filter position (u,v)
                    int k = 0;
                    for (int i = -r; i <= r; i++)
                    {
                        for (int j = -r; j <= r; j++)
                        {
                            A[k] = copy.GetPixel(u + i, v + j);
                            k++;
                        }
                    }
                    // Sort vector A and take the center element A[n]
                    Arrays.Sort(A);
                    ip.PutPixel(u, v, A[n]);
                }
            }
        }
示例#2
0
        public void Run(ImageProcessor ip)
        {
            int M    = ip.Width;
            int N    = ip.Height;
            var copy = ip.Duplicate();

            for (int u = 1; u <= M - 1; u++)
            {
                for (int v = 1; v <= N - 2; v++)
                {
                    int sum = 0;
                    for (int i = -1; i <= 1; i++)
                    {
                        for (int j = -1; j <= 1; j++)
                        {
                            int p = copy.GetPixel(u + 1, v + j);
                            sum += p;
                        }
                    }
                    int q = (int)(sum / 9.0);
                    ip.PutPixel(u, v, q);
                }
            }
        }