예제 #1
0
        /// <summary>
        /// val-->
        /// </summary>
        public static MyFilter HighPassKernel(int option)
        {
            MyFilter highPass = new MyFilter(3);

            switch (option)
            {
            case 2:
                highPass.setData(1);
                highPass[1, 0] = -2;
                highPass[0, 1] = -2;
                highPass[1, 1] = 5;
                highPass[2, 1] = -2;
                highPass[1, 2] = -2;
                return(highPass);

            case 1:
                highPass.setData(-1);
                highPass[1, 1] = 9;
                return(highPass);

            case 0:
            default:
                highPass[1, 0] = -1;
                highPass[0, 1] = -1;
                highPass[1, 1] = 5;
                highPass[2, 1] = -1;
                highPass[1, 2] = -1;
                return(highPass);
            }
        }
예제 #2
0
        private static byte[] ROBERT_Y(BitmapData data, int x, int y, BorderMethod borderMethod, MyFilter filter)
        {//SOBEL Y , not use filter
            byte[]       output = new byte[3];
            MyFilterData kernel = new MyFilterData();

            kernel.fill(data, x, y, borderMethod, MyFilter.GradientKernel(MyFilter.GradientOperator.ROBERT, MyFilter.GradientDirect.Y));
            return(kernel.count(1.0));
        }
예제 #3
0
        private static byte[] ROBERT_BOTH(BitmapData data, int x, int y, BorderMethod borderMethod, MyFilter filter)
        {//SOBEL BOTH , not use filter
            byte[]       output  = new byte[3];
            MyFilterData kernel1 = new MyFilterData();
            MyFilterData kernel2 = new MyFilterData();

            kernel1.fill(data, x, y, borderMethod, MyFilter.GradientKernel(MyFilter.GradientOperator.ROBERT, MyFilter.GradientDirect.X));
            kernel2.fill(data, x, y, borderMethod, MyFilter.GradientKernel(MyFilter.GradientOperator.ROBERT, MyFilter.GradientDirect.Y));
            return(MyFilterData.add(kernel1, kernel2).countAbs(1.0));
        }
예제 #4
0
        /// <summary>
        /// operate-->
        /// </summary>
        public static MyFilter add(MyFilter left, MyFilter right)
        {
            MyFilter newFilter = new MyFilter(left.size);

            for (int j = 0; j < newFilter.size; j++)
            {
                for (int i = 0; i < newFilter.size; i++)
                {
                    newFilter[i, j] = left[i, j] + right[i, j];
                }
            }
            return(newFilter);
        }
예제 #5
0
        public void fill(BitmapData src, int x, int y, MyFilter.BorderMethod borderMethod)
        {
            int startX = x - Size / 2;
            int startY = y - Size / 2;

            for (int j = 0; j < Size; j++)
            {
                for (int i = 0; i < Size; i++)
                {
                    _pixels[i, j] = MyFilter.getPixel(src, startX + i, startY + j, borderMethod, 1.0)[0];
                }
            }
        }
예제 #6
0
        protected virtual void button1_Click(object sender, EventArgs e)
        {
            MyFilter.FilterCount countMethod = null;
            double SNR      = 0.0;
            double costTime = 0;

            if (radioButton1.Checked)
            {
                countMethod = MyFilter.meanBlur;
            }
            else if (radioButton2.Checked)
            {
                countMethod = MyFilter.medianBlur;
            }
            else if (radioButton3.Checked)
            {
                countMethod = MyFilter.pseudoMedianBlur;
            }
            DateTime curTime = DateTime.Now;
            MyFilter filter  = new MyFilter(trackBar1.Value);

            if (radioButton4.Checked)//rect
            {
                filter.setData(1.0);
            }
            else if (radioButton5.Checked)
            {//cross
                filter.setData(Double.NegativeInfinity);
                if (trackBar1.Value % 2 == 0)
                {//even
                    int st, ed;
                    ed = trackBar1.Value / 2;
                    st = ed - 1;
                    filter.setData(st, 0, ed, trackBar1.Value - 1, 1.0);
                    filter.setData(0, st, trackBar1.Value - 1, ed, 1.0);
                }
                else
                {//odd
                    int t = trackBar1.Value / 2;
                    filter.setData(t, 0, t, trackBar1.Value - 1, 1.0);
                    filter.setData(0, t, trackBar1.Value - 1, t, 1.0);
                }
            }
            countOutView   = MyDeal.filter2D(imgView, MyFilter.BorderMethod.NULL, countMethod, filter, progress);
            outView        = countOutView;
            costTime       = DateTime.Now.Subtract(curTime).TotalMilliseconds;
            SNR            = MyDeal.SNR(imgView, outView);
            textBox2.Lines = countInfo(countMethod, trackBar1.Value, SNR, costTime);
        }
예제 #7
0
 public void draw(BitmapData src, int startX, int startY)
 {
     double[] pixel = new double[3];
     for (int j = 0; j < Size; j++)
     {
         for (int i = 0; i < Size; i++)
         {
             for (int c = 0; c < 3; c++)
             {
                 pixel[c] = _pixels[i, j];
             }
             MyFilter.setPixel(src, startX + i, startY + j, pixel);
         }
     }
 }
예제 #8
0
            public int fill(BitmapData srx, int x, int y, BorderMethod borderMethod, MyFilter filter)
            {
                int size = filter.size;

                _data = new double[size, size][];
                int startX = x - size / 2;
                int startY = y - size / 2;
                int pixels = 0;

                for (int j = 0; j < size; j++)
                {
                    for (int i = 0; i < size; i++)
                    {
                        _data[i, j] = getPixel(srx, startX + i, startY + j, borderMethod, filter[i, j]);
                        if (_data[i, j] != null)
                        {
                            pixels++;
                        }
                    }
                }
                return(pixels);
            }
예제 #9
0
 private void trackBar1_ValueChanged(object sender, EventArgs e)
 {
     countFilter       = MyFilter.HighPassKernel(comboBox1.SelectedIndex);
     countFilter[1, 1] = (1 + (double)trackBar1.Value / 100) * countFilter[1, 1] - 1;
     setMaskView();
 }
예제 #10
0
        public static MyFilter GradientKernel(GradientOperator operate, GradientDirect direct)
        {// please not use MyFilter.GradientDirect.BOTH
            MyFilter kernel = null;

            switch (operate)
            {
            case MyFilter.GradientOperator.SOBEL:
                kernel = new MyFilter(3);
                switch (direct)
                {
                case MyFilter.GradientDirect.X:
                    if (_SOBEL_X == null)
                    {
                        kernel[0, 0] = 1;
                        kernel[2, 0] = -1;
                        kernel[0, 1] = 2;
                        kernel[2, 1] = -2;
                        kernel[0, 2] = 1;
                        kernel[2, 2] = -1;
                        _SOBEL_X     = kernel;
                        return(kernel);
                    }
                    else
                    {
                        return(_SOBEL_X);
                    }

                case MyFilter.GradientDirect.Y:
                    if (_SOBEL_Y == null)
                    {
                        kernel[0, 0] = 1;
                        kernel[1, 0] = 2;
                        kernel[2, 0] = 1;
                        kernel[0, 2] = -1;
                        kernel[1, 2] = -2;
                        kernel[2, 2] = -1;
                        _SOBEL_Y     = kernel;
                        return(kernel);
                    }
                    else
                    {
                        return(_SOBEL_Y);
                    }
                }
                break;

            case MyFilter.GradientOperator.PREWITT:
                kernel = new MyFilter(3);
                switch (direct)
                {
                case MyFilter.GradientDirect.X:
                    if (_PREWITT_X == null)
                    {
                        kernel[0, 0] = 1;
                        kernel[2, 0] = -1;
                        kernel[0, 1] = 1;
                        kernel[2, 1] = -1;
                        kernel[0, 2] = 1;
                        kernel[2, 2] = -1;
                        _PREWITT_X   = kernel;
                        return(kernel);
                    }
                    else
                    {
                        return(_PREWITT_X);
                    }

                case MyFilter.GradientDirect.Y:
                    if (_PREWITT_Y == null)
                    {
                        kernel[0, 0] = 1;
                        kernel[1, 0] = 1;
                        kernel[2, 0] = 1;
                        kernel[0, 2] = -1;
                        kernel[1, 2] = -1;
                        kernel[2, 2] = -1;
                        _PREWITT_Y   = kernel;
                        return(kernel);
                    }
                    else
                    {
                        return(_PREWITT_Y);
                    }
                }
                break;

            case MyFilter.GradientOperator.ROBERT:
                kernel = new MyFilter(2);
                switch (direct)
                {
                case MyFilter.GradientDirect.X:
                    if (_ROBERT_X == null)
                    {
                        kernel[0, 0] = -1;
                        kernel[1, 0] = 0;
                        kernel[0, 1] = 0;
                        kernel[1, 1] = 1;
                        _ROBERT_X    = kernel;
                        return(kernel);
                    }
                    else
                    {
                        return(_ROBERT_X);
                    }

                case MyFilter.GradientDirect.Y:
                    if (_ROBERT_Y == null)
                    {
                        kernel[0, 0] = 0;
                        kernel[1, 0] = -1;
                        kernel[0, 1] = 1;
                        kernel[1, 1] = 0;
                        _ROBERT_Y    = kernel;
                        return(kernel);
                    }
                    else
                    {
                        return(_ROBERT_Y);
                    }
                }
                break;
            }
            return(kernel);
        }
예제 #11
0
        public static byte[] highBoost(BitmapData data, int x, int y, BorderMethod borderMethod, MyFilter filter)
        {//this is a FilterCount, Mean Blur
            byte[] output = new byte[3];
            int    size   = filter.size;

            if (size <= 1)
            {
                return(getPixel(data, x, y, borderMethod));
            }
            else
            {
                MyFilterData kernel = new MyFilterData();

                kernel.fill(data, x, y, borderMethod, filter);

                double weightSize  = 0;
                int    targetPoint = filter.size / 2;
                for (int j = 0; j < filter.size; j++)
                {
                    for (int i = 0; i < filter.size; i++)
                    {
                        if ((i != targetPoint) || (j != targetPoint))//ignore kernel target
                        {
                            weightSize += filter[i, j];
                        }
                    }
                }
                weightSize = 1 - weightSize;
                if (weightSize <= 0)
                {
                    throw new DivideByZeroException("high boost weightSize 0");
                }
                return(kernel.countAbs(1.0 / weightSize));
            }
        }
예제 #12
0
        public static byte[] outlier(BitmapData data, int x, int y, BorderMethod borderMethod, MyFilter filter)
        {//this is a FilterCount, Mean Blur
            byte[] output = new byte[3];

            int size = filter.size;

            if (size <= 1)
            {
                return(getPixel(data, x, y, borderMethod));
            }
            else
            {
                int    targetPoint = filter.size / 2;
                double cleanValue  = filter[targetPoint, targetPoint];
                filter[targetPoint, targetPoint] = 0;// remove clean value
                MyFilterData kernel = new MyFilterData();
                kernel.fill(data, x, y, borderMethod, filter);
                filter[targetPoint, targetPoint] = cleanValue;// recover clean value

                double weightSize = size * size - 1;
                if (weightSize <= 0)
                {
                    throw new DivideByZeroException("outlier weightSize 0");
                }
                output = kernel.count(1.0 / weightSize);
                byte[] originPixel = getPixel(data, x, y, borderMethod);
                for (int i = 0; i < 3; i++)
                {
                    if (Math.Abs(output[i] - originPixel[i]) > Math.Abs(cleanValue))
                    {
                        output[i] = originPixel[i];
                    }
                }

                return(output);
            }
        }
예제 #13
0
        public static byte[] pseudoMedianBlur(BitmapData data, int x, int y, BorderMethod borderMethod, MyFilter filter)
        {//this is a FilterCount, Mean Blur
            byte[] output = new byte[3];
            int    size   = filter.size;

            if (size <= 1)
            {
                return(getPixel(data, x, y, borderMethod));
            }
            else
            {
                MyFilterData kernel = new MyFilterData();
                int          pixels = 0;
                pixels = kernel.fill(data, x, y, borderMethod, filter);
                List <double>[] sortList = kernel.sort();
                double[]        pixel    = new double[3];
                pixel[0] = sortList[0].ElementAt <double>(sortList[0].Count / 2);
                pixel[1] = sortList[1].ElementAt <double>(sortList[1].Count / 2);
                pixel[2] = sortList[2].ElementAt <double>(sortList[2].Count / 2);
                return(MyFilterData.boundPixel(pixel));
            }
        }
예제 #14
0
        public static byte[] meanBlur(BitmapData data, int x, int y, BorderMethod borderMethod, MyFilter filter)
        {//this is a FilterCount, Mean Blur
            byte[] output = new byte[3];
            int    size   = filter.size;

            if (size <= 1)
            {
                return(getPixel(data, x, y, borderMethod));
            }
            else
            {
                MyFilterData kernel = new MyFilterData();
                int          pixels = 0;
                pixels = kernel.fill(data, x, y, borderMethod, filter);
                if (pixels <= 0)
                {
                    throw new DivideByZeroException("blur pixel size 0");
                }
                return(kernel.count(1.0 / pixels));
            }
        }
예제 #15
0
        private void button1_Click(object sender, EventArgs e)
        {
            MyFilter.FilterCount countMethod = null;
            switch (comboBox1.SelectedIndex)
            {           //operate
            case 0:     //SOBEL
                switch (comboBox2.SelectedIndex)
                {       //direct
                case 0: //BOTH
                    countMethod = MyFilter.gradient(MyFilter.GradientOperator.SOBEL, MyFilter.GradientDirect.BOTH);
                    break;

                case 1:        //X
                    countMethod = MyFilter.gradient(MyFilter.GradientOperator.SOBEL, MyFilter.GradientDirect.X);
                    break;

                case 2:        //Y
                    countMethod = MyFilter.gradient(MyFilter.GradientOperator.SOBEL, MyFilter.GradientDirect.Y);
                    break;
                }
                break;

            case 1:     //PREWITT
                switch (comboBox2.SelectedIndex)
                {       //direct
                case 0: //BOTH
                    countMethod = MyFilter.gradient(MyFilter.GradientOperator.PREWITT, MyFilter.GradientDirect.BOTH);
                    break;

                case 1:        //X
                    countMethod = MyFilter.gradient(MyFilter.GradientOperator.PREWITT, MyFilter.GradientDirect.X);
                    break;

                case 2:        //Y
                    countMethod = MyFilter.gradient(MyFilter.GradientOperator.PREWITT, MyFilter.GradientDirect.Y);
                    break;
                }
                break;

            case 2:     //ROBERT
                switch (comboBox2.SelectedIndex)
                {       //direct
                case 0: //BOTH
                    countMethod = MyFilter.gradient(MyFilter.GradientOperator.ROBERT, MyFilter.GradientDirect.BOTH);
                    break;

                case 1:        //X
                    countMethod = MyFilter.gradient(MyFilter.GradientOperator.ROBERT, MyFilter.GradientDirect.X);
                    break;

                case 2:        //Y
                    countMethod = MyFilter.gradient(MyFilter.GradientOperator.ROBERT, MyFilter.GradientDirect.Y);
                    break;
                }
                break;
            }
            double   SNR      = 0.0;
            double   costTime = 0;
            DateTime curTime  = DateTime.Now;

            outView        = MyDeal.filter2D(imgView, MyFilter.BorderMethod.NEAR, countMethod, null, progress);
            costTime       = DateTime.Now.Subtract(curTime).TotalMilliseconds;
            SNR            = MyDeal.SNR(imgView, outView);
            textBox1.Lines = countInfo(comboBox1.Text, comboBox2.Text, SNR, costTime);
        }
예제 #16
0
        private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedIndex)
            {           //operate
            case 0:     //SOBEL
                switch (comboBox2.SelectedIndex)
                {       //direct
                case 0: //BOTH
                    countFilter = new MyFilter(3);
                    setMaskView();
                    break;

                case 1:        //X
                    countFilter = MyFilter.GradientKernel(MyFilter.GradientOperator.SOBEL, MyFilter.GradientDirect.X);
                    setMaskView();
                    break;

                case 2:        //Y
                    countFilter = MyFilter.GradientKernel(MyFilter.GradientOperator.SOBEL, MyFilter.GradientDirect.Y);
                    setMaskView();
                    break;
                }
                break;

            case 1:     //PREWITT
                switch (comboBox2.SelectedIndex)
                {       //direct
                case 0: //BOTH
                    countFilter = new MyFilter(3);
                    setMaskView();
                    break;

                case 1:        //X
                    countFilter = MyFilter.GradientKernel(MyFilter.GradientOperator.PREWITT, MyFilter.GradientDirect.X);
                    setMaskView();
                    break;

                case 2:        //Y
                    countFilter = MyFilter.GradientKernel(MyFilter.GradientOperator.PREWITT, MyFilter.GradientDirect.Y);
                    setMaskView();
                    break;
                }
                break;

            case 2:     //ROBERT
                switch (comboBox2.SelectedIndex)
                {       //direct
                case 0: //BOTH
                    countFilter = new MyFilter(2);
                    setMaskView();
                    break;

                case 1:        //X
                    countFilter = MyFilter.GradientKernel(MyFilter.GradientOperator.ROBERT, MyFilter.GradientDirect.X);
                    setMaskView();
                    break;

                case 2:        //Y
                    countFilter = MyFilter.GradientKernel(MyFilter.GradientOperator.ROBERT, MyFilter.GradientDirect.Y);
                    setMaskView();
                    break;
                }
                break;
            }
        }