예제 #1
0
        private void preparationImage()
        {
            //decimal newSizeX = numXAfter.Value / numSizePoint.Value;
            //decimal newSizeY = numYAfter.Value / numSizePoint.Value;

            //if (newSizeX < 1 || newSizeY < 1)
            //{
            //    MessageBox.Show(@"Не указан желаемый размер, вычисление невозможно!");

            //    return;
            //}

            pageImageNOW  = (Bitmap)pageImageIN.Clone();
            pageVectorNOW = new List <GroupPoint>();
            Bitmap newBitmap = ImageProcessing.ConvertToGrayScale(pageImageNOW);

            int Xsize = (int)(numXAfter.Value / numSizePoint.Value);
            int Ysize = (int)(numYAfter.Value / numSizePoint.Value);

            newBitmap = ImageProcessing.ResizeImage(newBitmap, Xsize, Ysize);

            if (useFilter.Text.StartsWith("01")) //FloydSteinbergDithering"
            {
                newBitmap = ImageProcessing.ConvertTo8Bit(newBitmap);

                FloydSteinbergDithering filter = new FloydSteinbergDithering();
                filter.ApplyInPlace(newBitmap);
            }

            if (useFilter.Text.StartsWith("02")) //@"BayerDithering"
            {
                newBitmap = ImageProcessing.ConvertTo8Bit(newBitmap);

                BayerDithering filter = new BayerDithering();
                filter.ApplyInPlace(newBitmap);
            }

            if (useFilter.Text.StartsWith("03")) //@"получение оттенков серого"
            {
                //получим новое перемасштабированное изображение
                //тут с изображением уже ничего не делаем
            }



            pageImageNOW = newBitmap;
        }
예제 #2
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);
        }
예제 #3
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;
            }
        }
예제 #4
0
        public mDitherBayer()
        {
            BitmapType = BitmapTypes.GrayscaleBT709;

            filter = new BayerDithering();
        }