예제 #1
0
        // 引数で渡されたビットマップ画像を 2 値化します
        public static Bitmap Apply(Bitmap source, byte threshold = 128)
        {
            // ビットマップ画像から全てのピクセルを抜き出す
            PixelManipulator s = PixelManipulator.LoadBitmap(source);
            PixelManipulator d = s.Clone();

            // しきい値の設定
            byte[] thr_array = new byte[256];
            int    i;

            for (i = 0; i < threshold; i++)
            {
                thr_array[i] = (byte)0;
            }
            for (; i < 256; i++)
            {
                thr_array[i] = (byte)255;
            }

            // 全てのピクセルを巡回する
            s.EachPixel((x, y) => {
                // 2 値化する
                // グレースケール化されてることが前提なのでrgbは同じ値と仮定
                byte color = thr_array[s.R(x, y)];
                d.SetPixel(x, y, color, color, color);
            });

            // 新しいビットマップ画像を作成して、ピクセルをセットする
            return(d.CreateBitmap());
        }
예제 #2
0
        // 引数で渡されたビットマップ画像にメディアンフィルタを適用します
        public static Bitmap Apply(Bitmap source, int size = 3)
        {
            // ビットマップ画像から全てのピクセルを抜き出す
            PixelManipulator s = PixelManipulator.LoadBitmap(source);
            PixelManipulator d = s.Clone();

            // 範囲チェック
            if (size < 3)
            {
                size = 3;
            }
            if (size > 9)
            {
                size = 9;
            }
            size--;
            size /= 2;

            // 全てのピクセルを巡回する
            s.EachPixel((x, y) => {
                byte r = _Median(s.RangeR(x, y, size));
                byte g = _Median(s.RangeG(x, y, size));
                byte b = _Median(s.RangeB(x, y, size));
                d.SetPixel(x, y, r, g, b);
            });

            // 新しいビットマップ画像を作成して、ピクセルをセットする
            return(d.CreateBitmap());
        }
예제 #3
0
        // 引数で渡されたビットマップ画像にモザイクフィルタを適用します
        public static Bitmap Apply(Bitmap source, float rate = 50f, int size = 6)
        {
            // ビットマップ画像から全てのピクセルを抜き出す
            PixelManipulator s = PixelManipulator.LoadBitmap(source);
            PixelManipulator d = s.Clone();

            rate /= 1000;

            // 範囲チェック
            if (size < 1)
            {
                size = 1;
            }
            if (size > 32)
            {
                size = 32;
            }
            int w = size * 2 + 1;

            Tapa.MAX_BOARD_ROW = s.height / w;                          // 問題の行数
            Tapa.MAX_BOARD_COL = s.width / w;                           // 問題の列数
            Tapa.BOX_SUM       = Tapa.MAX_BOARD_ROW * Tapa.MAX_BOARD_COL;

            // 全てのピクセルを巡回する
            s.EachPixel((x, y) => {
                // 塗り終わったところを飛ばす
                if (x % w != 0 || y % w != 0)
                {
                    return;
                }

                // モザイクに色を塗る
                byte r = _SMA(s.RangeR(x, y, size), rate);
                byte g = _SMA(s.RangeG(x, y, size), rate);
                byte b = _SMA(s.RangeB(x, y, size), rate);
                _Fill(d, x, y, size, r, g, b);
                // MozaicFilter._Fill(d, x, y, size, s.R(x,y), s.G(x,y), s.B(x,y));
            });

            // 新しいビットマップ画像を作成して、ピクセルをセットする
            return(d.CreateBitmap());
        }
예제 #4
0
        // 引数で渡されたビットマップ画像をグレースケール化します
        public static Bitmap Apply(Bitmap source)
        {
            // ビットマップ画像から全てのピクセルを抜き出す
            PixelManipulator s = PixelManipulator.LoadBitmap(source);
            PixelManipulator d = s.Clone();

            // 全てのピクセルを巡回する
            s.EachPixel((x, y) => {
                // グレースケールにする
                byte r     = s.R(x, y);
                byte g     = s.G(x, y);
                byte b     = s.B(x, y);
                byte color = _GrayScale(r, g, b);

                d.SetPixel(x, y, color, color, color);
            });

            // 新しいビットマップ画像を作成して、ピクセルをセットする
            return(d.CreateBitmap());
        }
예제 #5
0
        // 引数で渡されたビットマップ画像にラプラシアンフィルタを適用します
        public static Bitmap Apply(Bitmap source)
        {
            // ビットマップ画像から全てのピクセルを抜き出す
            PixelManipulator s = PixelManipulator.LoadBitmap(source);
            PixelManipulator d = s.Clone();

            // フィルタを作成する
            float[] filter = _CreateLaplacianFilter();

            // 全てのピクセルを巡回する
            s.EachPixel((x, y) => {
                byte r = _Laplacian(filter, s.RangeR(x, y, 1));
                byte g = _Laplacian(filter, s.RangeG(x, y, 1));
                byte b = _Laplacian(filter, s.RangeB(x, y, 1));
                d.SetPixel(x, y, r, g, b);
            });

            // 新しいビットマップ画像を作成して、ピクセルをセットする
            return(d.CreateBitmap());
        }