예제 #1
0
 private void Median()
 {
     // create filter
     AForge.Imaging.Filters.Median filter = new AForge.Imaging.Filters.Median();
     // apply the filter
     filter.ApplyInPlace(image);
 }
예제 #2
0
 private Image GetAnimatedImage(Image img, int scale, bool blur)
 {
     if (blur)
     {
         AForge.Imaging.Filters.Median m = new AForge.Imaging.Filters.Median();
         m.Size = scale;
         return(m.Apply((Bitmap)img));
     }
     return(new Bitmap(img));
 }
예제 #3
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());
            }
        }
예제 #4
0
 private Image GetAnimatedImage(Image img, int scale, bool blur)
 {
     if (blur)
     {
         AForge.Imaging.Filters.Median m = new AForge.Imaging.Filters.Median();
         m.Size = scale;
         return m.Apply((Bitmap)img);
     }
     return new Bitmap(img);
 }
예제 #5
0
        private void AllFramesReadyEventHandler(object sender, AllFramesReadyEventArgs args)
        {
            using (ColorImageFrame ciFrame = args.OpenColorImageFrame())
            {
                if (null != ciFrame)
                {
                    ciFrame.CopyPixelDataTo(this.ColorPixels);

                    ColorBitmap.WritePixels(new Int32Rect(0, 0, ColorWidth, ColorHeight),
                                            ColorPixels, ColorWidth * sizeof(int), 0);
                }
            }

            using (DepthImageFrame diFrame = args.OpenDepthImageFrame())
            {
                if (null != diFrame)
                {
                    diFrame.CopyPixelDataTo(this.DepthDatas);
                }
                else
                {
                    return;
                }
            }

            // Clear
            //Array.Clear(PlayerPixels, 0, PlayerPixels.Length);
            //System.Threading.Tasks.Parallel.For(0, PlayerPixels.Length, index =>
            //    {
            //        PlayerPixels[index] = 200;
            //    });

            Array.Clear(CIP, 0, CIP.Length);

            gSensor.MapDepthFrameToColorFrame(DIF, DepthDatas, CIF, CIP);

            byte[] pixels = new byte[gSensor.DepthStream.FramePixelDataLength * sizeof(int)];

            // Fill the Player Image
            for (int hIndex = 0; hIndex < DepthHeight; ++hIndex)
            {
                for (int wIndex = 0; wIndex < DepthWidth; ++wIndex)
                {
                    int index = wIndex + hIndex * DepthWidth;
                    //int player = DepthDatas[index] & DepthImageFrame.PlayerIndexBitmask;

                    if (0 < (DepthDatas[index] & DepthImageFrame.PlayerIndexBitmask)) // Just for Player
                    {
                        ColorImagePoint cip = CIP[index];

                        // scale color coordinates to depth resolution
                        int colorInDepthX = (int)(cip.X / this.Divisor);
                        int colorInDepthY = (int)(cip.Y / this.Divisor);

                        if (colorInDepthX > 0 && colorInDepthX < this.DepthWidth &&
                            colorInDepthY >= 0 && colorInDepthY < this.DepthHeight)
                        {
                            // calculate index into the green screen pixel array
                            int playerIndex = (colorInDepthX + (colorInDepthY * this.DepthWidth)) << 2;
                            int colorIndex  = (cip.X + cip.Y * ColorWidth) << 2;

                            pixels[playerIndex]     = ColorPixels[colorIndex]; //BitConverter.ToInt32(ColorPixels, colorIndex);
                            pixels[playerIndex + 1] = ColorPixels[colorIndex + 1];
                            pixels[playerIndex + 2] = ColorPixels[colorIndex + 2];
                            pixels[playerIndex + 3] = ColorPixels[colorIndex + 3];

                            --playerIndex;
                            --colorIndex;

                            pixels[playerIndex]     = ColorPixels[colorIndex]; //BitConverter.ToInt32(ColorPixels, colorIndex);
                            pixels[playerIndex + 1] = ColorPixels[colorIndex + 1];
                            pixels[playerIndex + 2] = ColorPixels[colorIndex + 2];
                            pixels[playerIndex + 3] = ColorPixels[colorIndex + 3];
                        }

                        HadPlayer = true;
                    }
                    //else
                    //{
                    //    HadPlayer = false;
                    //}
                }
            }

            lock (gLock)
            {
                // Enqueue
                //PixelsQueue.Enqueue(pixels);
                //Average.ResetQueue(PixelsQueue, 3);

                PixelsLinkedList.AddLast(pixels);
                Average.ResetLinkedList(PixelsLinkedList, 3);
            }

            // Smoothen
            if (null == smooth && HadPlayer)
            {
                Color bg = new Color();
                bg.B = bg.G = bg.R = 0;

                // Gaussian
                //smooth = new GaussianFilter(DepthWidth, DepthHeight, PixelFormats.Bgr32, bg);

                // Bilateral
                smooth = new BilateralFilter(DepthWidth, DepthHeight, PixelFormats.Bgr32);

                // Median
                smooth2 = new GenericMedian(DepthWidth, DepthHeight, PixelFormats.Bgr32, bg, 3);

                median = new AForge.Imaging.Filters.Median(5);

                if (null == globalBWorker)
                {
                    globalBWorker         = new BackgroundWorker();
                    globalBWorker.DoWork += DoWorking;

                    globalBWorker.RunWorkerAsync();
                }
            }

            ////PlayerBitmap.WritePixels(new Int32Rect(0, 0, DepthWidth, DepthHeight),
            ////    PlayerPixels, DepthWidth * ((PlayerBitmap.Format.BitsPerPixel + 7) / 8), 0);
        }