示例#1
0
        public void OpenImage(string fileName)
        {
            try
            {
                SegmentedImage = null;
                OriginImage    = new ImageViewModel(new Bitmap(fileName));

                ClearPerfomanceInfo();
                RaisePropertyChanged("PerfomanceInfo");
                RaisePropertyChanged("CanProcessing");
            }
            catch (Exception) { }
        }
示例#2
0
 public void SegmentImage()
 {
     Task task = Task.Factory.StartNew(() =>
     {
         CanNewExecute = false;
         try
         {
             IFhSegmentation segmentation = SegmentationFactory.Instance.GetFhSegmentation(SortModification, MargeHeuristic);
             RGB[,] pixels = ImageHelper.GetPixels(OriginImage.Bitmap);
             if (pixels != null)
             {
                 var input = OriginImage.Bitmap;
                 int[] klabels;
                 int numlabels;
                 var watch      = Stopwatch.StartNew();
                 var superPixel = new SLICO().PerformSLICO_ForGivenK(
                     ref input,
                     out klabels,
                     out numlabels,
                     N,
                     Color.Red);
                 watch.Stop();
                 perfomanceInfo.SuperpixelPerfomance = watch.ElapsedMilliseconds;
                 BitmapData bitmapData = superPixel.LockBits(new Rectangle(0, 0, superPixel.Width, superPixel.Height), ImageLockMode.ReadOnly, superPixel.PixelFormat);
                 var superpixels       = ImageHelper.ToMatrix(klabels, bitmapData.Width, bitmapData.Height,
                                                              bitmapData.Stride);
                 GaussianFilter filter = new GaussianFilter();
                 filter.Filter(OriginImage.Bitmap.Width, OriginImage.Bitmap.Height, pixels, Sigma);
                 int[,] segments = segmentation.BuildSegments(OriginImage.Bitmap.Width, OriginImage.Bitmap.Height, pixels, K, MinSize, Connection, DifType, ref perfomanceInfo, superpixels);
                 if (RandomColor)
                 {
                     SegmentedImage = new ImageViewModel(ImageHelper.GetBitmap(segments));
                 }
                 else
                 {
                     SegmentedImage = new ImageViewModel(ImageHelper.GetBitmap(segments, pixels, MakeBorders));
                 }
                 RaisePropertyChanged("PerfomanceInfo");
             }
         }
         catch { }
         finally
         {
             CanNewExecute = true;
         }
     });
 }
        private void OpenImage()
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Filter = "Image files (*.gif;*.jpg;*.jpe;*.png;*.bmp;*.dib;*.tif;*.wmf;*.ras;*.eps;*.pcx;*psd;*.tga)|*.gif;*.jpg;*.jpe;*.png;*.bmp;*.dib;*.tif;*.wmf;*.ras;*.eps;*.pcx;*psd;*.tga";

            Nullable<bool> result = dlg.ShowDialog();

            if (result == true)
            {
                SegmentedImage = null;
                OriginImage = new ImageViewModel(new Bitmap(dlg.FileName));
            }
        }
 public void SegmentImage()
 {
     Task task = Task.Factory.StartNew(() =>
     {
         App.Current.Dispatcher.Invoke(new Action(() =>
         {
             ProcessRunning = true;
         }));
         try
         {
             IFhSegmentation segmentation = SegmentationFactory.Instance.GetFhSegmentation();
             byte[,] pixels = ImageHelper.GetPixels(OriginImage.Bitmap);
             if (pixels != null)
             {
                 GaussianFilter filter = new GaussianFilter();
                 filter.Filter(OriginImage.Bitmap.Width, OriginImage.Bitmap.Height, pixels, 0.8);
                 int[,] segments = segmentation.BuildSegments(OriginImage.Bitmap.Width, OriginImage.Bitmap.Height, pixels, 300);
                 App.Current.Dispatcher.Invoke(new Action(() =>
                 {
                     SegmentedImage = new ImageViewModel(ImageHelper.GetBitmap(segments));
                 }));
             }
         }
         catch { }
         finally
         {
             App.Current.Dispatcher.Invoke(new Action(() =>
             {
                 ProcessRunning = false;
             }));
         }
     });
 }
        public void SegmentCppImage()
        {
            Task task = Task.Factory.StartNew(() =>
            {
                App.Current.Dispatcher.Invoke(new Action(() =>
                {
                    ProcessRunning = true;
                }));
                try
                {
                    Bitmap src = OriginImage.Bitmap;
                    BitmapData srcData = src.LockBits(new Rectangle(0, 0, src.Width, src.Height), ImageLockMode.ReadOnly, src.PixelFormat);
                    int bytesPerPixel = 1;
                    if (src.PixelFormat == PixelFormat.Format8bppIndexed)
                        bytesPerPixel = 1;
                    else if (src.PixelFormat == PixelFormat.Format24bppRgb)
                        bytesPerPixel = 3;
                    else if ((src.PixelFormat == PixelFormat.Format32bppRgb) || (src.PixelFormat == PixelFormat.Format32bppArgb))
                        bytesPerPixel = 4;

                    Bitmap dst = new Bitmap(src.Width, src.Height, src.PixelFormat);
                    BitmapData dstData = dst.LockBits(new Rectangle(0, 0, dst.Width, dst.Height), ImageLockMode.WriteOnly, dst.PixelFormat);

                    Fhs.Fhs fhs = new Fhs.Fhs();
                    unsafe { fhs.fhs((byte*)srcData.Scan0, src.Width, src.Height, srcData.Stride, bytesPerPixel, (byte*)dstData.Scan0, 0.8, 300); }

                    src.UnlockBits(srcData);
                    dst.UnlockBits(dstData);

                    int[,] segments = ImageHelper.GetSegments(dst);

                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        SegmentedImage = new ImageViewModel(ImageHelper.GetBitmap(segments));
                    }));
                }
                catch { }
                finally
                {
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        ProcessRunning = false;
                    }));
                }
            });
        }
 public void GaussianImage()
 {
     Task task = Task.Factory.StartNew(() =>
     {
         App.Current.Dispatcher.Invoke(new Action(() =>
         {
             ProcessRunning = true;
         }));
         try
         {
             GaussianFilter filter = new GaussianFilter();
             byte[,] pixels = ImageHelper.GetPixels(OriginImage.Bitmap);
             if (pixels != null)
             {
                 filter.Filter(OriginImage.Bitmap.Width, OriginImage.Bitmap.Height, pixels, 0.8);
                 App.Current.Dispatcher.Invoke(new Action(() =>
                 {
                     SegmentedImage = new ImageViewModel(ImageHelper.GetFilterBitmap(pixels));
                 }));
             }
         }
         catch { }
         finally
         {
             App.Current.Dispatcher.Invoke(new Action(() =>
             {
                 ProcessRunning = false;
             }));
         }
     });
 }