예제 #1
0
 private void Sharpen()
 {
     // create filter
     AForge.Imaging.Filters.Sharpen filter = new AForge.Imaging.Filters.Sharpen();
     // apply the filter
     filter.ApplyInPlace(image);
 }
예제 #2
0
        private void Go_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                System.Windows.Media.Imaging.BitmapImage imagesource = imageBox.Source as System.Windows.Media.Imaging.BitmapImage;
                if (imageBox.Source == null)
                {
                    System.Windows.MessageBox.Show("Add your image to the Image 1 box!");
                    return;
                }


                System.Drawing.Bitmap image = BmpImage2Bmp(imagesource);
                System.Windows.Media.Imaging.BitmapImage final = new System.Windows.Media.Imaging.BitmapImage();

                if (!AForge.Imaging.Image.IsGrayscale(image))
                {
                    AForge.Imaging.Filters.ExtractChannel Grayer = new AForge.Imaging.Filters.ExtractChannel(0);
                    image = Grayer.Apply(image);
                }

                if (Threshold.IsChecked == true)
                {
                    imageBox.Source = null;
                    AForge.Imaging.Filters.Threshold threshold = new AForge.Imaging.Filters.Threshold((int)slider.Value);
                    threshold.ApplyInPlace(image);
                    final = Bmp2BmpImage(image);
                }
                else if (GaussianFilter.IsChecked == true)
                {
                    AForge.Imaging.Filters.GaussianBlur Gauss = new AForge.Imaging.Filters.GaussianBlur();
                    Gauss.Sigma = GaussSigma_Slide.Value;
                    Gauss.Size  = (int)GaussSize_Slide.Value;
                    AForge.Imaging.UnmanagedImage unmanagedImage = AForge.Imaging.UnmanagedImage.FromManagedImage(image);
                    AForge.Imaging.UnmanagedImage Dst            = unmanagedImage.Clone();
                    Gauss.Apply(unmanagedImage, Dst);
                    final = Bmp2BmpImage(Dst.ToManagedImage());
                }

                else if (HiPass.IsChecked == true)
                {
                    AForge.Imaging.Filters.Sharpen filter = new AForge.Imaging.Filters.Sharpen();
                    filter.ApplyInPlace(image);
                    final = Bmp2BmpImage(image);
                }

                else if (Erode.IsChecked == true)
                {
                    AForge.Imaging.Filters.Erosion filter = new AForge.Imaging.Filters.Erosion();
                    filter.ApplyInPlace(image);
                    final = Bmp2BmpImage(image);
                }

                else if (Invert.IsChecked == true)
                {
                    AForge.Imaging.Filters.Invert filter = new AForge.Imaging.Filters.Invert();
                    filter.ApplyInPlace(image);
                    final = Bmp2BmpImage(image);
                }
                else if (EdgeDetector.IsChecked == true)
                {
                    AForge.Imaging.Filters.CannyEdgeDetector filter = new AForge.Imaging.Filters.CannyEdgeDetector();
                    filter.ApplyInPlace(image);
                    final = Bmp2BmpImage(image);
                }

                else if (Median.IsChecked == true)
                {
                    AForge.Imaging.Filters.Median filter = new AForge.Imaging.Filters.Median();
                    filter.Size = (int)GaussSize_Slide.Value;
                    filter.ApplyInPlace(image);
                    final = Bmp2BmpImage(image);
                }

                else if (More.IsChecked == true)
                {
                    if (Dilate.IsSelected)
                    {
                        AForge.Imaging.Filters.Dilatation filter = new AForge.Imaging.Filters.Dilatation();
                        filter.ApplyInPlace(image);
                        final = Bmp2BmpImage(image);
                    }
                }

                imageBox.Source = final;
                TransformImage  = image;

                boxWidth  = imageBox.RenderSize.Width;
                boxHeight = imageBox.RenderSize.Height;
            }
            catch (Exception exc)
            {
                System.Windows.MessageBox.Show(exc.ToString());
            }
        }