Ejemplo n.º 1
0
        public mDitherSierra(byte thresholdValue)
        {
            BitmapType = BitmapTypes.GrayscaleBT709;

            ThresholdValue = thresholdValue;

            Effect = new SierraDithering();
            Effect.ThresholdValue = ThresholdValue;

            filter = Effect;
        }
Ejemplo n.º 2
0
        private void video_NewFrame1(object sender, NewFrameEventArgs eventArgs)
        {
            videoCapture.Stop();
            pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
            pictureBox2.SizeMode = PictureBoxSizeMode.CenterImage;
            pictureBox1.Image    = (Bitmap)eventArgs.Frame.Clone();
            //pictureBox2.Image = (Bitmap)eventArgs.Frame.Clone();
            image          = (Bitmap)eventArgs.Frame.Clone();
            byte[,] matrix = new byte[4, 4]
            {
                { 95, 233, 127, 255 },
                { 159, 31, 191, 63 },
                { 111, 239, 79, 207 },
                { 175, 47, 143, 15 }
            };
            switch (choice)
            {
            case 0:
            {
            }
            break;

            //Threshold
            case 1:
            {
                Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
                image = g.Apply(image);
                Threshold filter = new Threshold(100);
                applyfilter(filter);
            }
            break;

            //OrderedDithering
            case 2:
            {
                Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
                image = g.Apply(image);
                OrderedDithering filter = new OrderedDithering(matrix);
                applyfilter(filter);
            }
            break;

            //BayerDithering
            case 3:
            {
                Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
                image = g.Apply(image);
                BayerDithering filter = new BayerDithering();
                applyfilter(filter);
            }
            break;

            //floyd
            case 4:
            {
                Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
                image = g.Apply(image);
                FloydSteinbergDithering filter = new FloydSteinbergDithering();
                applyfilter(filter);
            }
            break;

            //burkes
            case 5:
            {
                Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
                image = g.Apply(image);
                BurkesDithering filter = new BurkesDithering();
                applyfilter(filter);
            }
            break;

            //jarvis
            case 6:
            {
                Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
                image = g.Apply(image);
                JarvisJudiceNinkeDithering filter = new JarvisJudiceNinkeDithering();
                applyfilter(filter);
            }
            break;

            //sierra
            case 7:
            {
                Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
                image = g.Apply(image);
                SierraDithering filter = new SierraDithering();
                applyfilter(filter);
            }
            break;

            //stucki
            case 8:
            {
                Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
                image = g.Apply(image);
                StuckiDithering filter = new StuckiDithering();
                applyfilter(filter);
            }
            break;

            //Homogenity
            case 9:
            {
                Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
                image = g.Apply(image);
                HomogenityEdgeDetector filter = new HomogenityEdgeDetector();
                applyfilter(filter);
            }
            break;

            //rotate
            case 10:
            {
                applyfilter(new RotateChannels());
            } break;

            //sobel
            case 11:
            {
                Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
                image = g.Apply(image);
                SobelEdgeDetector filter = new SobelEdgeDetector();
                applyfilter(filter);
            }
            break;

            //canny
            case 12:
            {
                Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
                image = g.Apply(image);
                CannyEdgeDetector filter = new CannyEdgeDetector();
                applyfilter(filter);
            }
            break;

            case 13:
            {
                applyfilter(new YCbCrFiltering());
            } break;

            case 14:
            {
                applyfilter(new HueModifier(180));
            } break;

            //SIS Threshold
            case 15:
            {
                Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
                image = g.Apply(image);
                SISThreshold filter = new SISThreshold();
                applyfilter(filter);
            } break;

            //Difference
            case 16:
            {
                Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
                image = g.Apply(image);
                DifferenceEdgeDetector filter = new DifferenceEdgeDetector();
                applyfilter(filter);
            } break;

            //mirror
            case 17:
            {
                applyfilter(new Mirror(false, true));
            } break;

            //flip
            case 18:
            {
                applyfilter(new RotateBilinear(180, true));
            } break;

            //Erosion
            case 19:
            {
                applyfilter1(new Erosion());
            } break;

            //Dilatation
            case 20:
            {
                applyfilter1(new Dilatation());
            } break;

            //Opening
            case 21:
            {
                applyfilter1(new Opening());
            } break;

            //closing
            case 22:
            {
                applyfilter1(new Closing());
            } break;

            //jitter
            case 23:
            {
                applyfilter(new Jitter(15));
            } break;

            //OilPainting
            case 24:
            {
                applyfilter(new OilPainting(10));
            } break;

            //pixellate
            case 25:
            {
                applyfilter(new Pixellate(10));
            } break;
            }
        }
Ejemplo n.º 3
0
        public static Bitmap ApplyFiliter(ImageFiliter imgFilter, Bitmap bmp, byte Value, byte Value2)
        {
            Bitmap newImage = null;

            //ContrastCorrection filter2 = new ContrastCorrection(1.0);
            //newImage = filter2.Apply(bmp);
            if (imgFilter != ImageFiliter.None)
            {
                IFilter filter3 = Grayscale.CommonAlgorithms.Y;
                newImage = filter3.Apply(bmp);

                if (imgFilter == ImageFiliter.Threshold)
                {
                    IFilter filter = null;
                    if (Value == 0)
                    {
                        filter = new Threshold();
                    }
                    else
                    {
                        filter = new Threshold(Value);
                    }
                    newImage = filter.Apply(newImage);

                    //IterativeThreshold filter = new IterativeThreshold(Value2, Value);
                    //// apply the filter
                    // newImage = filter.Apply(newImage);
                }
                if (imgFilter == ImageFiliter.ThresholdWithCarry)
                {
                    IFilter filter = new ThresholdWithCarry();
                    newImage = filter.Apply(newImage);
                }
                else if (imgFilter == ImageFiliter.OrderedDithering)
                {
                    IFilter filter = new OrderedDithering();
                    newImage = filter.Apply(newImage);
                }
                else if (imgFilter == ImageFiliter.BayerDithering)
                {
                    IFilter filter = new BayerDithering();
                    newImage = filter.Apply(newImage);
                }
                else if (imgFilter == ImageFiliter.FloydSteinbergDithering)
                {
                    IFilter filter = new FloydSteinbergDithering();
                    newImage = filter.Apply(newImage);
                }
                else if (imgFilter == ImageFiliter.BurkesDithering)
                {
                    IFilter filter = new BurkesDithering();
                    newImage = filter.Apply(newImage);
                }
                else if (imgFilter == ImageFiliter.JarvisJudiceNinkeDithering)
                {
                    IFilter filter = new JarvisJudiceNinkeDithering();
                    newImage = filter.Apply(newImage);
                }
                else if (imgFilter == ImageFiliter.SierraDithering)
                {
                    IFilter filter = new SierraDithering();
                    newImage = filter.Apply(newImage);
                }
                else if (imgFilter == ImageFiliter.StuckiDithering)
                {
                    IFilter filter = new StuckiDithering();
                    newImage = filter.Apply(newImage);
                }
                else if (imgFilter == ImageFiliter.Convolution)
                {
                    // create filter
                    //OtsuThreshold filter = new OtsuThreshold();
                    //// apply the filter
                    //filter.ApplyInPlace(newImage);

                    //// create filter
                    //IterativeThreshold filter = new IterativeThreshold(0);
                    //// apply the filter
                    //newImage = filter.Apply(newImage);

                    int[,] kernel =
                    {
                        { -2, -1, 0 },
                        { -1,  1, 1 },
                        {  0,  1, 2 }
                    };
                    // create filter
                    Convolution filter = new Convolution(kernel);
                    // apply the filter
                    filter.ApplyInPlace(newImage);
                }
                newImage = BitmapTo1Bpp(newImage);
            }
            else
            {
                newImage = BitmapTo1Bpp(bmp);
            }
            //轉換成 1bit bps
            return(newImage);
        }