コード例 #1
0
        public Bitmap Process(Bitmap source)
        {
            Bitmap result = new Bitmap(source);

            int height = source.Height;
            int width  = source.Width;

            if (windowSize % 2 == 0)
            {
                windowSize++;
            }

            int[,] sourceBitsRedValues   = new int[width, height];
            int[,] sourceBitsGreenValues = new int[width, height];
            int[,] sourceBitsBlueValues  = new int[width, height];

            BitmapHelperUtil.FillRGBValues(source, sourceBitsRedValues, sourceBitsGreenValues, sourceBitsBlueValues);

            int halfOfWindow = (windowSize - 1) / 2;

            for (int i = halfOfWindow; i < source.Width - (halfOfWindow + 1); i++)
            {
                for (int j = halfOfWindow; j < source.Height - (halfOfWindow + 1); j++)
                {
                    int newR = 0;
                    int newG = 0;
                    int newB = 0;
                    int K    = 0;

                    for (int wi = -halfOfWindow; wi <= halfOfWindow; wi++)
                    {
                        for (int hw = -halfOfWindow; hw <= halfOfWindow; hw++)
                        {
                            K++;

                            if (hw == 0 && wi == 0)
                            {
                                continue;
                            }

                            newR += sourceBitsRedValues[i + hw, j + wi];

                            newG += sourceBitsGreenValues[i + hw, j + wi];

                            newB += sourceBitsBlueValues[i + hw, j + wi];
                        }
                    }

                    result.SetPixel(i, j, Color.FromArgb(newR / K, newG / K, newB / K));
                }
            }

            return(result);
        }
コード例 #2
0
        public Bitmap Process(Bitmap source)
        {
            Bitmap result = new Bitmap(source);

            int height = source.Height;
            int width  = source.Width;

            int[,] sourceBitsRedValues   = new int[width, height];
            int[,] sourceBitsGreenValues = new int[width, height];
            int[,] sourceBitsBlueValues  = new int[width, height];

            BitmapHelperUtil.FillRGBValues(source, sourceBitsRedValues, sourceBitsGreenValues, sourceBitsBlueValues);

            for (int i = 1; i < source.Width - 1; i++)
            {
                for (int j = 1; j < source.Height - 1; j++)
                {
                    int newXR = 0, newYR = 0;
                    int newXG = 0, newYG = 0;
                    int newXB = 0, newYB = 0;

                    for (int wi = -1; wi < 2; wi++)
                    {
                        for (int hw = -1; hw < 2; hw++)
                        {
                            newXR += _gx[wi + 1, hw + 1] * sourceBitsRedValues[i + hw, j + wi];
                            newYR += _gy[wi + 1, hw + 1] * sourceBitsRedValues[i + hw, j + wi];

                            newXG += _gx[wi + 1, hw + 1] * sourceBitsGreenValues[i + hw, j + wi];
                            newYG += _gy[wi + 1, hw + 1] * sourceBitsGreenValues[i + hw, j + wi];

                            newXB += _gx[wi + 1, hw + 1] * sourceBitsBlueValues[i + hw, j + wi];
                            newYB += _gy[wi + 1, hw + 1] * sourceBitsBlueValues[i + hw, j + wi];
                        }
                    }

                    if (newXR * newXR + newYR * newYR > Limit ||
                        newXG * newXG + newYG * newYG > Limit ||
                        newXB * newXB + newYB * newYB > Limit)
                    {
                        result.SetPixel(i, j, Color.Black);
                    }
                    else
                    {
                        result.SetPixel(i, j, Color.White);
                    }
                }
            }

            return(result);
        }