Ejemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog
            {
                Filter      = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*",
                FilterIndex = 2
            };

            of.ShowDialog();
            String filename = of.FileName.ToString();

            if (filename != "")
            {
                try
                {
                    read_image      = new BitmapImage(new Uri(of.FileName, UriKind.RelativeOrAbsolute));
                    image1.Source   = read_image;
                    bitmapImage     = read_image.Clone();
                    width           = bitmapImage.PixelWidth;
                    height          = bitmapImage.PixelHeight;
                    stride          = (width * bitmapImage.Format.BitsPerPixel + 7) / 8;
                    pixel_Closing   = GetPixels(bitmapImage);
                    pixel_ori       = (PixelColor[, ])pixel_Closing.Clone();
                    writeableBitmap = new WriteableBitmap(width, height, bitmapImage.DpiX, bitmapImage.DpiY, PixelFormats.Bgra32, bitmapImage.Palette);
                    Dilation(ref pixel_Closing, 7);
                    Erosion(ref pixel_Closing, 7);
                    hsv_image = Transfer_to_HSV(pixel_Closing);
                }
                catch { }
            }

            //button2_Click();
        }
Ejemplo n.º 2
0
        void Dilation(ref PixelColor[,] pixels, int ksize)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            PixelColor[,] temp  = (PixelColor[, ])pixels.Clone();
            PixelColor[,] temp1 = pixels;
            Parallel.For(0, pixels.GetLength(0) - 1, x =>
            {
                for (int y = 0; y < temp.GetLength(1); y++)
                {
                    temp1[x, y] = Dilation_Crossdot(temp, x, y, ksize);
                }
            });
            stopWatch.Stop();
            TimeSpan ts          = stopWatch.Elapsed;
            string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);

            Console.WriteLine("RunTime " + elapsedTime);
        }