Пример #1
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));
            }
        }
Пример #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
        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));
            }
        }
Пример #5
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));
            }
        }
Пример #6
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);
            }
Пример #7
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);
            }
        }
Пример #8
0
        public static double[] getPixel(BitmapData data, int x, int y, BorderMethod method, double rate)
        {
            if (rate == Double.NegativeInfinity)
            {//不須對該欄位值取值
                return(null);
            }
            double[] output = new double[3];
            switch (method)
            {
            case BorderMethod.NULL:
                if (x < 0 || x >= data.Width || y < 0 || y >= data.Height)
                {
                    return(null);
                }
                else
                {
                    unsafe
                    {
                        byte *target = (byte *)data.Scan0;
                        target   += y * data.Stride + x * 3;
                        output[0] = rate * target[0];
                        output[1] = rate * target[1];
                        output[2] = rate * target[2];
                    }
                    return(output);
                }

            case BorderMethod.ZERO:
                if (x < 0 || x >= data.Width || y < 0 || y >= data.Height)
                {
                    return(new double[3] {
                        0, 0, 0
                    });
                }
                else
                {
                    unsafe
                    {
                        byte *target = (byte *)data.Scan0;
                        target   += y * data.Stride + x * 3;
                        output[0] = rate * target[0];
                        output[1] = rate * target[1];
                        output[2] = rate * target[2];
                    }
                    return(output);
                }

            case BorderMethod.NEAR:
                if (x < 0)
                {
                    x = 0;
                }
                else if (x >= data.Width)
                {
                    x = data.Width - 1;
                }
                if (y < 0)
                {
                    y = 0;
                }
                else if (y >= data.Height)
                {
                    y = data.Height - 1;
                }
                unsafe
                {
                    byte *target = (byte *)data.Scan0;
                    target   += y * data.Stride + x * 3;
                    output[0] = rate * target[0];
                    output[1] = rate * target[1];
                    output[2] = rate * target[2];
                }
                return(output);
            }
            return(output);
        }
Пример #9
0
        public static byte[] getPixel(BitmapData data, int x, int y, BorderMethod method)
        {
            byte[] output = new byte[3];
            switch (method)
            {
            case BorderMethod.NULL:
                if (x < 0 || x >= data.Width || y < 0 || y >= data.Height)
                {
                    return(null);
                }
                else
                {
                    unsafe
                    {
                        byte *target = (byte *)data.Scan0;
                        target   += y * data.Stride + x * 3;
                        output[0] = target[0];
                        output[1] = target[1];
                        output[2] = target[2];
                    }
                    return(output);
                }

            case BorderMethod.ZERO:
                if (x < 0 || x >= data.Width || y < 0 || y >= data.Height)
                {
                    return(new byte[3] {
                        0, 0, 0
                    });
                }
                else
                {
                    unsafe
                    {
                        byte *target = (byte *)data.Scan0;
                        target   += y * data.Stride + x * 3;
                        output[0] = target[0];
                        output[1] = target[1];
                        output[2] = target[2];
                    }
                    return(output);
                }

            case BorderMethod.NEAR:
                if (x < 0)
                {
                    x = 0;
                }
                else if (x >= data.Width)
                {
                    x = data.Width - 1;
                }
                if (y < 0)
                {
                    y = 0;
                }
                else if (y >= data.Height)
                {
                    y = data.Height - 1;
                }
                unsafe
                {
                    byte *target = (byte *)data.Scan0;
                    target   += y * data.Stride + x * 3;
                    output[0] = target[0];
                    output[1] = target[1];
                    output[2] = target[2];
                }
                return(output);
            }
            return(output);
        }
Пример #10
0
 public static extern int imaqFillBorder(IntPtr image, BorderMethod method);