Пример #1
0
        private void CropImage()
        {
            if (InputImage1 == null)
            {
                return;
            }
            using (CStreamReader reader = InputImage1.CreateReader())
            {
                using (Bitmap bitmap = new Bitmap(reader))
                {
                    int       x1       = settings.SliderX1 * bitmap.Width / 10000;
                    int       x2       = bitmap.Width - settings.SliderX2 * bitmap.Width / 10000 - x1;
                    int       y1       = settings.SliderY1 * bitmap.Height / 10000;
                    int       y2       = bitmap.Height - settings.SliderY2 * bitmap.Height / 10000 - y1;
                    Rectangle cropRect = new Rectangle(x1, y1, x2, y2);
                    Bitmap    target   = new Bitmap(cropRect.Width, cropRect.Height);

                    using (Graphics g = Graphics.FromImage(target))
                    {
                        g.DrawImage(bitmap, new Rectangle(0, 0, target.Width, target.Height),
                                    cropRect,
                                    GraphicsUnit.Pixel);
                        CreateOutputStream(target);
                    }
                }
            }
        }
Пример #2
0
        //Changes the contrast of an image
        private void contrast(Image <Bgr, Byte> img = null)
        {
            if (img == null)
            {
                if (InputImage1 == null)
                {
                    return;
                }
                img = new Image <Bgr, Byte>(new Bitmap(InputImage1.CreateReader()));
            }
            Image <Bgr, Byte> constrast_img = img.Copy();

            constrast_img._GammaCorrect((double)settings.Contrast / 100); // 0.01 - 10
            CreateOutputStream(constrast_img.ToBitmap());
        }
Пример #3
0
 //Convert bgr Image to black and white
 private void blacknwhite(Image <Bgr, Byte> img = null)
 {
     if (img == null)
     {
         if (InputImage1 == null)
         {
             return;
         }
         img = new Image <Bgr, Byte>(new Bitmap(InputImage1.CreateReader()));
     }
     using (Image <Gray, Byte> blacknwhite = img.Convert <Gray, byte>().ThresholdBinary(new Gray(settings.Threshold), new Gray(255)))
     {
         CreateOutputStream(blacknwhite.ToBitmap());
     }
 }
Пример #4
0
        /// <summary>
        /// Called every time this plugin is run in the workflow execution.
        /// </summary>
        public void Execute()
        {
            ProgressChanged(0, 1);

            if (InputImage1 == null)
            {
                if (InputImage2 != null)
                {
                    InputImage1 = InputImage2;
                }
                else
                {
                    GuiLogMessage("Please select an image.", NotificationLevel.Error);
                    return;
                }
            }

            using (CStreamReader reader = InputImage1.CreateReader())
            {
                using (Bitmap bitmap = new Bitmap(reader))
                {
                    using (Image <Bgr, Byte> img = new Image <Bgr, Byte>(bitmap))
                    {
                        switch (settings.Action)
                        {
                        case ActionType.flip:       // Flip Image
                            switch (settings.FlipType)
                            {
                            case 0:                 // Horizontal
                                img._Flip(Emgu.CV.CvEnum.FLIP.HORIZONTAL);
                                CreateOutputStream(img.ToBitmap());
                                break;

                            case 1:                 // Vertical
                                img._Flip(Emgu.CV.CvEnum.FLIP.VERTICAL);
                                CreateOutputStream(img.ToBitmap());
                                break;
                            }
                            break;

                        case ActionType.gray:       // Gray Scale
                            using (Image <Gray, double> grayImg = img.Convert <Gray, byte>().Convert <Gray, double>())
                            {
                                CreateOutputStream(grayImg.ToBitmap());
                            }
                            break;

                        case ActionType.smooth:     // Smoothing
                            if (settings.Smooth > 10000)
                            {
                                settings.Smooth = 10000;
                            }
                            int smooth = settings.Smooth;
                            if (smooth % 2 == 0)
                            {
                                smooth++;
                                settings.Smooth = smooth;
                            }
                            img._SmoothGaussian(smooth);
                            CreateOutputStream(img.ToBitmap());
                            break;

                        case ActionType.resize:     // Resizeing
                            if (settings.SizeX > 4096)
                            {
                                settings.SizeX = 4096;
                            }
                            if (settings.SizeY > 4096)
                            {
                                settings.SizeY = 4096;
                            }
                            using (Image <Bgr, byte> newImg = img.Resize(settings.SizeX, settings.SizeY, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR))
                            {
                                CreateOutputStream(newImg.ToBitmap());
                            }
                            break;

                        case ActionType.crop:       // Cropping
                            this.CropImage();
                            break;

                        case ActionType.rotate:     // Rotating
                            if (settings.Degrees > 36000)
                            {
                                settings.Degrees = 360;
                            }
                            int degrees = settings.Degrees;
                            while (degrees > 3600)
                            {
                                degrees -= 3600;
                            }
                            while (degrees > 360)
                            {
                                degrees -= 360;
                            }
                            using (Image <Bgr, byte> newImg = img.Rotate(degrees, new Bgr(System.Drawing.Color.White)))
                            {
                                CreateOutputStream(newImg.ToBitmap());
                            }
                            break;

                        case ActionType.invert:     // Inverting
                            using (Image <Bgr, byte> newImg = img.Not())
                            {
                                CreateOutputStream(newImg.ToBitmap());
                            }
                            break;

                        case ActionType.create:     // Create Image
                            if (settings.SizeX > 65536)
                            {
                                settings.SizeX = 65536;
                            }
                            if (settings.SizeY > 65536)
                            {
                                settings.SizeY = 65536;
                            }
                            using (Image <Gray, Single> newImg = new Image <Gray, Single>(settings.SizeX, settings.SizeY))
                            {
                                CreateOutputStream(newImg.ToBitmap());
                            }
                            break;

                        case ActionType.and:        // And-connect Images
                            if (InputImage1 != null && InputImage2 != null)
                            {
                                using (Image <Bgr, Byte> secondImg = new Image <Bgr, Byte>(new Bitmap(InputImage2.CreateReader())))
                                {
                                    using (Image <Bgr, byte> newImg = img.And(secondImg))
                                    {
                                        CreateOutputStream(newImg.ToBitmap());
                                    }
                                }
                            }
                            else
                            {
                                GuiLogMessage("Please select two images.", NotificationLevel.Error);
                            }
                            break;

                        case ActionType.or:        // Ond-connect Images
                            if (InputImage1 != null && InputImage2 != null)
                            {
                                using (Image <Bgr, Byte> secondImg = new Image <Bgr, Byte>(new Bitmap(InputImage2.CreateReader())))
                                {
                                    using (Image <Bgr, byte> newImg = img.Or(secondImg))
                                    {
                                        CreateOutputStream(newImg.ToBitmap());
                                    }
                                }
                            }
                            else
                            {
                                GuiLogMessage("Please select two images.", NotificationLevel.Error);
                            }
                            break;

                        case ActionType.xor:        // Xor-connect Images
                            if (InputImage1 != null && InputImage2 != null)
                            {
                                using (Image <Bgr, Byte> secondImg = new Image <Bgr, Byte>(new Bitmap(InputImage2.CreateReader())))
                                {
                                    using (Image <Bgr, byte> newImg = img.Xor(secondImg))
                                    {
                                        CreateOutputStream(newImg.ToBitmap());
                                    }
                                }
                            }
                            else
                            {
                                GuiLogMessage("Please select two images.", NotificationLevel.Error);
                            }
                            break;

                        case ActionType.xorgray:     // Xor- ImageGrayScales
                            if (InputImage1 != null && InputImage2 != null)
                            {
                                using (Image <Gray, byte> grayImg2 = new Image <Bgr, Byte>(new Bitmap(InputImage2.CreateReader())).Convert <Gray, byte>())
                                {
                                    using (Image <Gray, byte> grayImg1 = img.Convert <Gray, byte>())
                                    {
                                        using (Image <Gray, byte> newImg = grayImg1.Xor(grayImg2))
                                        {
                                            CreateOutputStream(newImg.ToBitmap());
                                        }
                                    }
                                }
                            }
                            else
                            {
                                GuiLogMessage("Please select two images.", NotificationLevel.Error);
                            }
                            break;

                        case ActionType.blacknwhite:
                            this.blacknwhite(img);
                            break;
                        }

                        OnPropertyChanged("OutputImage");
                    }
                }
            }

            ProgressChanged(1, 1);
        }