Exemple #1
0
        public static void ExtractRegionImages1(Bitmap frame1, Bitmap frame2)
        {
            frame1 = greyscaleFilter1.Apply(frame1);
            frame2 = greyscaleFilter1.Apply(frame2);
            lock (_lock1)
            {
                cropFilter1.Rectangle = Region1;
                ROI1 = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame1)));
                diffFilter1.OverlayImage = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame2)));
                ROI1Diff = diffFilter1.Apply(ROI1);
                subFilter1.OverlayImage = invertFilter1.Apply(threshFilter1.Apply(ROI1Diff));
                ROI1DropDiff            = subFilter1.Apply(ROI1Diff);

                cropFilter1.Rectangle = Region2;
                ROI2 = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame1)));
                diffFilter1.OverlayImage = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame2)));
                ROI2Diff = diffFilter1.Apply(ROI2);
                subFilter1.OverlayImage = invertFilter1.Apply(threshFilter1.Apply(ROI2Diff));
                ROI2DropDiff            = subFilter1.Apply(ROI2Diff);

                cropFilter1.Rectangle = Region5;
                ROI5 = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame1)));
                diffFilter1.OverlayImage = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame2)));
                ROI5Diff = diffFilter1.Apply(ROI5);
                subFilter1.OverlayImage = invertFilter1.Apply(threshFilter1.Apply(ROI5Diff));
                ROI5DropDiff            = subFilter1.Apply(ROI5Diff);

                cropFilter1.Rectangle = Region6;
                ROI6 = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame1)));
                diffFilter1.OverlayImage = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame2)));
                ROI6Diff = diffFilter1.Apply(ROI6);
                subFilter1.OverlayImage = invertFilter1.Apply(threshFilter1.Apply(ROI6Diff));
                ROI6DropDiff            = subFilter1.Apply(ROI6Diff);
            }
        }
Exemple #2
0
        public static void ExtractRegionsDevice2(Bitmap frame1, Bitmap frame2)
        {
            frame1 = greyscaleFilter2.Apply(frame1);
            frame2 = greyscaleFilter2.Apply(frame2);
            lock (_lock2)
            {
                cropFilter2.Rectangle = Region3;
                ROI3 = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame1)));
                diffFilter2.OverlayImage = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame2)));
                ROI3Diff = diffFilter2.Apply(ROI3);
                subFilter2.OverlayImage = invertFilter2.Apply(threshFilter2.Apply(ROI3Diff));
                ROI3DropDiff            = subFilter2.Apply(ROI3Diff);

                cropFilter2.Rectangle = Region4;
                ROI4 = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame1)));
                diffFilter2.OverlayImage = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame2)));
                ROI4Diff = diffFilter2.Apply(ROI4);
                subFilter2.OverlayImage = invertFilter2.Apply(threshFilter2.Apply(ROI4Diff));
                ROI4DropDiff            = subFilter2.Apply(ROI4Diff);

                cropFilter2.Rectangle = Region7;
                ROI7 = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame1)));
                diffFilter2.OverlayImage = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame2)));
                ROI7Diff = diffFilter2.Apply(ROI7);
                subFilter2.OverlayImage = invertFilter2.Apply(threshFilter2.Apply(ROI7Diff));
                ROI7DropDiff            = subFilter2.Apply(ROI7Diff);

                cropFilter2.Rectangle = Region8;
                ROI8 = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame1)));
                diffFilter2.OverlayImage = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame2)));
                ROI8Diff = diffFilter2.Apply(ROI8);
                subFilter2.OverlayImage = invertFilter2.Apply(threshFilter2.Apply(ROI8Diff));
                ROI8DropDiff            = subFilter2.Apply(ROI8Diff);
            }
        }
Exemple #3
0
 /// <summary>
 /// Update routine for first camera.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="image"></param>
 private void Camera1_Update(object sender, ref Bitmap image)
 {
     if (Executed)
     {
         Bitmap invrt = FilterInvert.Apply(image);
         FilterColor.ApplyInPlace(invrt);
         FilterSaturateLeft.ApplyInPlace(image);
         // create an instance of blob counter algorithm.
         BlobCounter objCounter = new BlobCounter();
         objCounter.FilterBlobs          = true;
         objCounter.CoupledSizeFiltering = true;
         objCounter.MinWidth             = (int)(0.05f * Wdth);
         objCounter.MinHeight            = (int)(0.05f * Hght);
         objCounter.MaxWidth             = (int)(0.4f * Wdth);
         objCounter.MaxHeight            = (int)(0.4f * Hght);
         // process image.
         objCounter.ProcessImage(invrt);
         ObjectsLeft    = objCounter.GetObjectsRectangles();
         ObjectDescLeft = new Descriptor[ObjectsLeft.Length];
         // Draw lines.
         Graphics graphic = Graphics.FromImage(image);
         Pen      pen     = new Pen(Color.Yellow);
         pen.Width = 7;
         Font       font  = new Font("Courier", 14, FontStyle.Regular);
         SolidBrush brush = new SolidBrush(Color.Yellow);
         for (int a = 0; a < ObjectsLeft.Length; a++)
         {
             // Set descriptor of each detected object.
             SetDescriptor(ref ObjectDescLeft[a], ref ObjectsLeft[a], image);
             pen.Color = ObjectDescLeft[a].ColorMean;
             graphic.DrawRectangle(pen, ObjectsLeft[a]);
             graphic.DrawString(a.ToString() + " | " + ObjectDescLeft[a].ColorClass +
                                "\n" + ObjectDescLeft[a].PercentR.ToString() + "%\n" + ObjectDescLeft[a].PercentG.ToString() +
                                "%\n" + ObjectDescLeft[a].PercentB.ToString() + "%",
                                font, brush, ObjectsLeft[a].X, ObjectsLeft[a].Y);
         }
         pen.Dispose();
         graphic.Dispose();
     }
     else
     {
         Graphics graphic = Graphics.FromImage(image);
         Pen      pen     = new Pen(Color.Yellow);
         pen.Width = 6;
         graphic.DrawRectangle(pen, new Rectangle(30, 30, Wdth - 60, Hght - 60));
         pen.Width = 3;
         graphic.DrawRectangle(pen, new Rectangle(90, 90, Wdth - 180, Hght - 180));
         pen.Dispose();
         graphic.Dispose();
     }
 }
Exemple #4
0
        private void FiltroInvertir(Bitmap bmp)
        {
            IFilter filtro = new Invert();
            Bitmap  xImage = filtro.Apply(bmp);

            peCaptcha.Image = xImage;
        }
Exemple #5
0
        private Bitmap preProcess(Bitmap originalImage)
        {
            Invert invertObj   = new Invert();
            Bitmap invertImage = invertObj.Apply((Bitmap)originalImage.Clone());


            invertImage = Grayscale.CommonAlgorithms.BT709.Apply(invertImage);
            Threshold bwObject = new Threshold();

            invertImage = bwObject.Apply(invertImage);

            ExtractBiggestBlob blobObject = new ExtractBiggestBlob();

            invertImage = blobObject.Apply(invertImage);

            ResizeBicubic resize = new ResizeBicubic(60, 90);

            invertImage = resize.Apply(invertImage);


            //CannyEdgeDetector edgeDetector = new CannyEdgeDetector();
            //invertImage = edgeDetector.Apply(invertImage);

            return(invertImage);
        }
        private void FiltroInvertir(Bitmap bmp)
        {
            IFilter Filtro = new Invert();
            Bitmap  XImage = Filtro.Apply(bmp);

            pictureCapchaE.Image = XImage;
        }
Exemple #7
0
        public Bitmap ToInvert(Bitmap Im)
        {
            AForge.Imaging.Filters.Invert Img = new Invert();
            Bitmap bmImage = AForge.Imaging.Image.Clone(new Bitmap(Im), PixelFormat.Format24bppRgb);

            return(Img.Apply(bmImage));
        }
        public Bitmap GetNewFrame(Bitmap source)
        {
            //инверсия
            var newFrame = _invert.Apply(source);

            source.Dispose();
            return(newFrame);
        }
        public static Bitmap Invert(Bitmap Imagem)
        {
            Invert filter = new Invert();

            Imagem = Imagem.Clone(new Rectangle(0, 0, Imagem.Width, Imagem.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            Imagem = filter.Apply(Imagem);
            return(Imagem);
        }
Exemple #10
0
        public Bitmap Invert()
        {
            Invert inv = new Invert();

            this.imgHandContour = inv.Apply(this.imgHandContour);
            //this.imgHandContour = inv.Apply(this.imgHandContourCut);
            return(this.imgHandContour);
        }
Exemple #11
0
        public Bitmap Invert(Bitmap Bmp)
        {
            Invert a = new Invert();

            Bmp = a.Apply(Bmp);
            AForge.Imaging.Image.FormatImage(ref Bmp);

            return(Bmp);
        }
Exemple #12
0
        /// <summary>
        /// Creates a comic rendered copy of the input image.
        /// </summary>
        public override Bitmap Render(Bitmap sourceImage)
        {
            GrayscaleToRGB convertColor = new GrayscaleToRGB();

            if (sourceImage.PixelFormat == PixelFormat.Format8bppIndexed)
            {
                sourceImage = convertColor.Apply(sourceImage);
            }

            BilateralBlur blur  = new BilateralBlur(3, 0.1);
            Bitmap        comic = blur.Apply(sourceImage);

            // Edges
            Bitmap            grayscale = Grayscale.CommonAlgorithms.Y.Apply(comic);
            SobelEdgeDetector sobelEdge = new SobelEdgeDetector();

            sobelEdge.ScaleIntensity = true;
            Bitmap edgeLayer = sobelEdge.Apply(grayscale);

            edgeLayer = convertColor.Apply(edgeLayer);

            Invert invertEdge = new Invert();

            invertEdge.ApplyInPlace(edgeLayer);

            HSLLinear edgeLinear = new HSLLinear();

            edgeLinear.InLuminance.Min = 0;
            edgeLinear.InLuminance.Max = 0.8;
            edgeLinear.ApplyInPlace(edgeLayer);


            // highlights
            Bitmap     highlightLayer      = invertEdge.Apply(edgeLayer);
            Dilatation highlightDilitation = new Dilatation();

            highlightDilitation.ApplyInPlace(highlightLayer);

            BrightnessCorrection highlightBright = new BrightnessCorrection(-0.35);

            highlightBright.ApplyInPlace(highlightLayer);
            ColorDodge highlightBlend = new ColorDodge(highlightLayer);

            highlightBlend.ApplyInPlace(comic);


            // Merge edges with working layer
            Multiply multEdge = new Multiply(edgeLayer);

            multEdge.ApplyInPlace(comic);


            return(comic);
        }
Exemple #13
0
        //-------------------------------------------------------------
        private void process_imginput(Bitmap img, String Plate_Type)
        {
            //grayscale
            IFilter way_filt;//= new GrayscaleY();

            //process_image = way_filt.Apply(img);
            //resize
            if (Plate_Type == "1hang")
            {
                way_filt = new ResizeBilinear(600, 120); //bien 1 hang
            }
            else
            {
                way_filt = new ResizeBilinear(300, 200); //bien 2 hang
            }

            process_image = way_filt.Apply(img);
            //process_image = get_plate(process_image, 10, 210, 30, 330);
            input_image = way_filt.Apply(input_image);
            p           = process_image;
            //threshold
            way_filt      = new Threshold(125);
            process_image = way_filt.Apply(process_image);


            //K-means
            process_image = kmean(process_image);


            //invert
            way_filt      = new Invert();
            process_image = way_filt.Apply(process_image);


            //liembt
            //UCM
            way_filt      = new Median();
            process_image = way_filt.Apply(process_image);

            //way_filt = new AdaptiveSmooth();
            //process_image = way_filt.Apply(process_image);

            //end liembt
            //filter k
            BlobsFiltering filter = new BlobsFiltering();

            filter.MinHeight = 25;//50
            filter.MinWidth  = 10;
            filter.MaxHeight = 100;
            filter.ApplyInPlace(process_image);
            //p = process_image;
            input_width  = process_image.Width;
            input_height = process_image.Height;
        }
        /// <returns>Invert image</returns>
        public static Bitmap Invert(this Bitmap image)
        {
            if (image.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                throw new NotSupportedException("Operation can be applied to binary 8bpp images only");
            }

            Invert filter = new Invert();

            // apply the filter
            return(filter.Apply(image));
        }
        public static Bitmap ApplyPreProcessing(Bitmap image, int thresholdvalue)
        {
            Bitmap grayImage = image;

            if (!AForge.Imaging.Image.IsGrayscale(image))
            {
                Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
                grayImage = filter.Apply(image);
            }
            AForge.Imaging.Filters.Invert    invert      = new Invert();
            AForge.Imaging.Filters.Threshold thresh_hold = new Threshold(thresholdvalue);
            image = invert.Apply(thresh_hold.Apply(grayImage));
            return(image);
        }
        public Bitmap Invert(Bitmap imageToBlacken)
        {
            Debug.WriteLine("Got Here 2");
            Invert filter = new Invert();

            Debug.WriteLine("Got Here 3");
            Bitmap image = new Bitmap(imageToBlacken);

            Debug.WriteLine("Got Here 4");

            Bitmap blackenedImage = filter.Apply(imageToBlacken);

            Debug.WriteLine("Got Here 4");
            return(blackenedImage);
        }
Exemple #17
0
        private void invertToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (checkifthereisimage() != 1)
            {
                return;
            }
            Invert filter = new Invert();

            try
            {
                pictureBox1ImagePreview.Image = filter.Apply((Bitmap)pictureBox1ImagePreview.Image);
                imgFile = pictureBox1ImagePreview.Image;
            }
            catch (Exception ex)
            { }
        }
        /// <summary>
        /// Extracts Images from smallSize CameraImage, No feed Back given during process
        /// </summary>
        /// <param name="SmallCameraImage"></param>
        /// <param name="OMRSpecsSheetAddress"></param>
        /// <returns>Formated, Right sized OMR Sheet</returns>
        private Bitmap flatten(Bitmap bmp, int fillint, int contint)
        {
            // step 1 - turn background to black
            ColorFiltering colorFilter = new ColorFiltering();

            colorFilter.Red              = new IntRange(0, fillint);
            colorFilter.Green            = new IntRange(0, fillint);
            colorFilter.Blue             = new IntRange(0, fillint);
            colorFilter.FillOutsideRange = false;
            colorFilter.ApplyInPlace(bmp);
            AForge.Imaging.Filters.ContrastCorrection Contrast        = new ContrastCorrection(contint);
            AForge.Imaging.Filters.Invert             invert          = new Invert();
            AForge.Imaging.Filters.ExtractChannel     extract_channel = new ExtractChannel(0);
            AForge.Imaging.Filters.Threshold          thresh_hold     = new Threshold(44);
            bmp = invert.Apply(thresh_hold.Apply(extract_channel.Apply(Contrast.Apply(bmp))));
            return(bmp);
        }
 public PreProcess(UISettings ui, FileData file)
 {
     try {
         ExtendFileData(file);
         BitmapOriginal  = (ui.WorkDirectory + "\\" + FileName).FileTo24bbpRgb(ResizeRatio: ui.ResizeValue, FrameCrop: ui.CropValue, ImageZoom: 1, RotateDegree: ui.RotateDegree);
         UnmanagedMarkup = UnmanagedImage.FromManagedImage(BitmapOriginal);
         ImageStatistics stats    = null;
         Threshold       AFbinary = new Threshold(1);
         Grayscale       AFgray   = new Grayscale(0.1, 0.7, 0.2);
         if (ui.ExcludeColorSwitch && ui.ExcludeColorRadius > 0)
         {
             System.Windows.Media.Color excolor   = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(ui.ExcludeColorHex);
             EuclideanColorFiltering    AFexcolor = new EuclideanColorFiltering(new RGB(excolor.R, excolor.G, excolor.B), (short)ui.ExcludeColorRadius);
             UnmanagedExclude = AFbinary.Apply(AFgray.Apply(AFexcolor.Apply(UnmanagedMarkup)));
         }
         else
         {
             UnmanagedExclude = UnmanagedImage.Create(UnmanagedMarkup.Width, UnmanagedMarkup.Height, PixelFormat.Format8bppIndexed);
         }
         if (ui.WhiteBalanceSwitch || ui.BlackBalanceSwitch)                 // need to apply auto white/black balance
         {
             Invert AFinvert = new Invert();
             stats = new ImageStatistics(UnmanagedMarkup, AFinvert.Apply(UnmanagedExclude));
             int          lowend       = (ui.BlackBalanceSwitch) ? (int)Math.Round(0.333d * (stats.RedWithoutBlack.Center2QuantileValue(ui.BlackBalance) + stats.GreenWithoutBlack.Center2QuantileValue(ui.BlackBalance) + stats.BlueWithoutBlack.Center2QuantileValue(ui.BlackBalance))):0;
             LevelsLinear levelsLinear = new LevelsLinear {
                 InRed   = new IntRange(lowend, (ui.WhiteBalanceSwitch) ? stats.RedWithoutBlack.Center2QuantileValue(ui.WhiteBalance) : 255),
                 InGreen = new IntRange(lowend, (ui.WhiteBalanceSwitch) ? stats.GreenWithoutBlack.Center2QuantileValue(ui.WhiteBalance) : 255),
                 InBlue  = new IntRange(lowend, (ui.WhiteBalanceSwitch) ? stats.BlueWithoutBlack.Center2QuantileValue(ui.WhiteBalance) : 255),
             };
             //LevelsLinear levelsLinear = new LevelsLinear {
             //	InRed=new IntRange((ui.BlackBalanceSwitch)?stats.RedWithoutBlack.Center2QuantileValue(ui.BlackBalance):0, (ui.WhiteBalanceSwitch)?stats.RedWithoutBlack.Center2QuantileValue(ui.WhiteBalance):255),
             //	InGreen=new IntRange((ui.BlackBalanceSwitch)?stats.GreenWithoutBlack.Center2QuantileValue(ui.BlackBalance):0, (ui.WhiteBalanceSwitch)?stats.GreenWithoutBlack.Center2QuantileValue(ui.WhiteBalance):255),
             //	InBlue=new IntRange((ui.BlackBalanceSwitch)?stats.BlueWithoutBlack.Center2QuantileValue(ui.BlackBalance):0, (ui.WhiteBalanceSwitch)?stats.BlueWithoutBlack.Center2QuantileValue(ui.WhiteBalance):255),
             //};
             levelsLinear.ApplyInPlace(UnmanagedMarkup);
         }
         if (ui.GaussianBlurSwitch && ui.GaussianBlur != 0)                                           // Gaussian Blur and Darken
         {
             GaussianBlur AFgblur     = new GaussianBlur(11.0, Math.Max(ui.GaussianBlur, 0) * 2 + 1); // Gaussian Blur sigma = 8.0 kernel size = 7
             Intersect    AFintersect = new Intersect(AFgblur.Apply(UnmanagedMarkup));
             UnmanagedMarkup = AFintersect.Apply(UnmanagedMarkup);
         }
         UnmanagedGray = AFgray.Apply(UnmanagedMarkup);               // directly turn into gray
     } catch { throw new Exception("Error Occured During PreProcessing"); }
 }
Exemple #20
0
    public static ProcessResult <Clip[]> ProcessCommand(Command command, Clip[] incomingClips, ClipMetaData targetMetadata)
    {
        var clips = new Clip[incomingClips.Length];

        for (var i = 0; i < incomingClips.Length; i++)
        {
            clips[i] = new Clip(incomingClips[i]);
        }

        return(command.Id switch
        {
            TokenType.Arpeggiate => Arpeggiate.Apply(command, clips),
            TokenType.Concat => Concat.Apply(clips),
            TokenType.Crop => Crop.Apply(command, clips),
            TokenType.Echo => Echo.Apply(command, clips),
            TokenType.Extract => Take.Apply(command, clips, true),
            TokenType.Filter => Filter.Apply(command, clips),
            TokenType.Invert => Invert.Apply(command, clips),
            TokenType.Interleave => Interleave.Apply(command, targetMetadata, clips, InterleaveMode.NotSpecified),
            TokenType.InterleaveEvent => Interleave.Apply(command, targetMetadata, clips, InterleaveMode.Event),
            TokenType.Legato => Legato.Apply(clips),
            TokenType.Loop => Loop.Apply(command, clips),
            TokenType.Mask => Mask.Apply(command, clips),
            TokenType.Monophonize => Monophonize.Apply(clips),
            TokenType.Padding => Padding.Apply(command, clips),
            TokenType.Quantize => Quantize.Apply(command, clips),
            TokenType.Ratchet => Ratchet.Apply(command, clips),
            TokenType.Relength => Relength.Apply(command, clips),
            TokenType.Remap => Remap.Apply(command, clips),
            TokenType.Resize => Resize.Apply(command, clips),
            TokenType.Scale => Scale.Apply(command, clips),
            TokenType.Scan => Scan.Apply(command, clips),
            TokenType.SetLength => SetLength.Apply(command, clips),
            TokenType.SetPitch => SetPitch.Apply(command, clips),
            TokenType.SetRhythm => SetRhythm.Apply(command, clips),
            TokenType.Shuffle => Shuffle.Apply(command, clips),
            TokenType.Skip => Skip.Apply(command, clips),
            TokenType.Slice => Slice.Apply(command, clips),
            TokenType.Take => Take.Apply(command, clips),
            TokenType.Transpose => Transpose.Apply(command, clips),
            TokenType.VelocityScale => VelocityScale.Apply(command, clips),
            _ => new ProcessResult <Clip[]>($"Unsupported command {command.Id}")
        });
        public Bitmap Apply(Bitmap input)
        {
            var            resize  = new Resize_filter(input.Width, input.Height);
            var            resMask = resize.Apply(_mask);
            GrayscaleToRGB grayscaleToRGBFilter = new GrayscaleToRGB();

            resMask = grayscaleToRGBFilter.Apply(resMask);


            resMask = _brightnessCorrection.Apply(resMask);

            Invert invertFilter = new Invert();

            resMask = invertFilter.Apply(resMask);

            Subtract subtractFilter = new Subtract(resMask);

            return(subtractFilter.Apply(input));
        }
 public void invertClickHandler(object sender, EventArgs e)
 {
     if (image != null)
     {
         Bitmap img    = new Bitmap(path);
         Invert filter = new Invert();
         img = filter.Apply(img);
         // ImageEView
         if (mov != null)
         {
             this.WorkItem.Workspaces[WorkspaceNames.TabWorkspace].Close(mov);
         }
         mov = this.WorkItem.SmartParts.AddNew <ImageEView>();
         mov.panAndZoomPictureBox1.Image = img;
         SmartPartInfo spi =
             new SmartPartInfo("Invert", "MyOwnDescription");
         this.WorkItem.Workspaces[WorkspaceNames.TabWorkspace].Show(mov, spi);
     }
 }
Exemple #23
0
        public CalPAP(UISettings ui, FileData file, ref ConcurrentBag <double> AreaBag) : base(ui, file)
        {
            try {
                MulticolorComponentsLabeling mclabel = new MulticolorComponentsLabeling()
                {
                    Low  = (int)Math.Round(Low_Threshold / ui.um2px2),
                    High = (int)Math.Round(Math.Min(int.MaxValue, High_Threshold / ui.um2px2))
                };

                Invert AFinvert = new Invert();
                UnmanagedResult = mclabel.Apply(AFinvert.Apply(UnmanagedBlackWhite));
                foreach (Blobx blob in mclabel.BlobCounter.blobs)
                {
                    //if (blob.Area<mclabel.Low) {
                    //	Low_count++; Low_sumArea+=blob.Area;
                    //} else if (blob.Area<=mclabel.High) {
                    Normal_count++; Normal_SumArea += ui.um2px2 * blob.Area; AreaBag.Add(ui.um2px2 * blob.Area);
                    //} else {
                    //	High_count++; High_sumArea+=blob.Area;
                    //}
                }

                Total_SumArea = ui.um2px2 * (UnmanagedMarkup.Width * UnmanagedMarkup.Height); // total area
                Lung_SumArea  = Total_SumArea - Low_SumArea - High_SumArea;                   // lung area
                Paren_SumArea = Lung_SumArea - NonParen_SumArea;                              // parenchymal area
                Tis_SumArea   = Paren_SumArea - Normal_SumArea;                               // septum tissue
                Normal_Count  = 1000.0d * 1000.0d * Normal_count / Paren_SumArea;             // counts per reference area

                StringBuilder header = new StringBuilder();
                header.Append($"{FileName}  ps: {ui.PixelScale:G2}/{ui.ResizeValue:G2} px/um"
                              + $"\nlung: {Lung_SumArea:G2}µm\xB2, {Lung_SumArea/Total_SumArea:0%} image (blw: {Low_SumArea/Total_SumArea:0%} ovr: {High_SumArea/Total_SumArea:0%})"
                              + $"\nparenchyma: {Paren_SumArea:G2}µm\xB2, {Paren_SumArea/Lung_SumArea:0%} lung (exc: {NonParen_SumArea/Total_SumArea:0%})"
                              + $"\nseptum: {Tis_SumArea:G2}µm\xB2, {Tis_SumArea/Paren_SumArea:0%} paren (airspace: {Normal_SumArea/Total_SumArea:0%})");

                StringBuilder footer = new StringBuilder();
                footer.Append($"Total #: {mclabel.BlobCounter.blobs.Count}");

                UnmanagedMarkup = UnmanagedImage.FromManagedImage(AddBlobText(UnmanagedMarkup.ToManagedImage(false), Color.Black, $"{header}", $"{footer}", null, null, (int)Math.Round(0.02d * UnmanagedMarkup.Width * Math.Sqrt(ui.ExportDetailRatio))));
                UnmanagedResult = UnmanagedImage.FromManagedImage(AddBlobText(UnmanagedResult.ToManagedImage(false), Color.PaleGreen, $"{header}", $"{footer}", null, null, (int)Math.Round(0.02d * UnmanagedMarkup.Width * Math.Sqrt(ui.ExportDetailRatio))));
            } catch { throw new Exception("Error Occured During Airspace Profiling"); }
        }
        private void SharpenSmooth(object sender, DoWorkEventArgs e)
        {
            Bitmap raw_image = null;

            if (inRb.Checked)
            {
                raw_image = Accord.Imaging.Filters.Grayscale.CommonAlgorithms.BT709.Apply((Bitmap)input_PB.Image.Clone());
            }
            else if (outRb.Checked)
            {
                raw_image = (Bitmap)outputImageBox.Image.Clone();
            }
            if (sharpenRB.Checked)
            {
                var sharpen = new Sharpen();
                sharpen.Threshold = (Byte)threshVal.Value;
                UnmanagedImage r_img = UnmanagedImage.FromManagedImage(raw_image);
                outputImageBox.Image.Dispose();
                r_img = sharpen.Apply(r_img);
                outputImageBox.Image = r_img.ToManagedImage();
            }
            else if (smoothingRB.Checked)
            {
                var Smoothing = new AdaptiveSmoothing();
                Smoothing.Factor = (double)(threshVal.Value);
                UnmanagedImage r_img = UnmanagedImage.FromManagedImage(raw_image);
                outputImageBox.Image.Dispose();
                r_img = Smoothing.Apply(r_img);
                outputImageBox.Image = r_img.ToManagedImage();
            }
            else if (radioButton1.Checked)
            {
                var Invert = new Invert();

                UnmanagedImage r_img = UnmanagedImage.FromManagedImage(raw_image);
                outputImageBox.Image.Dispose();
                r_img = Invert.Apply(r_img);
                outputImageBox.Image = r_img.ToManagedImage();
            }
        }
Exemple #25
0
        private void video_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
        {
            //jalankan frame
            camera = (Bitmap)eventArgs.Frame.Clone();

            videoPlayer.Image = camera;
            Thread.Sleep(10);

            Sepia sp = new Sepia();

            videoPlayer.Image = sp.Apply(camera);
            Thread.Sleep(10);

            Invert i = new Invert();

            videoPlayer.Image = i.Apply(camera);
            Thread.Sleep(10);

            Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);

            videoPlayer.Image = g.Apply(camera);
            Thread.Sleep(10);
        }
        //      gr.ResetTransform();
        //      gr.DrawRectangle(Pens.Black, 0, 0, width - 1, height - 1);


        private void DrawHistogramV(Bitmap img)
        {
            Color back_color = Color.White;

            Invert filter = new Invert();
            // apply the filter
            Bitmap inv = filter.Apply(img);

            VerticalIntensityStatistics his = new VerticalIntensityStatistics(inv);

            AForge.Math.Histogram histogram = his.Gray;

            int[] values = histogram.Values;



            Color[] Colors = new Color[] {
                Color.Red, Color.LightGreen, Color.Blue,
                Color.Pink, Color.Green, Color.LightBlue,
                Color.Orange, Color.Yellow, Color.Purple
            };



            gr2.Clear(back_color);

            // Draw the histogram.
            using (Pen thin_pen = new Pen(Color.Black, 0))
            {
                for (int i = 0; i < values.Length; i++)
                {
                    float f2 = 420F;
                    float fl = (float)values[i] / f2;
                    gr2.DrawLine(thin_pen, 0, i, fl, i);
                }
            }
        }
        private void button_threshold_Click(object sender, EventArgs e)
        {
            if (obraz_w_greyscale != null)
            {
                if (textBox1.TextLength != 0)
                {
                    int       prog         = Convert.ToInt32(textBox1.Text);
                    Threshold binearyzacja = new Threshold(prog);
                    obraz_po_progowaniu = (Bitmap)binearyzacja.Apply(obraz_w_greyscale);

                    Invert odwracanie = new Invert();
                    obraz_po_progowaniu = odwracanie.Apply(obraz_po_progowaniu);


                    AForge.Imaging.Filters.Closing zamykanie = new AForge.Imaging.Filters.Closing();
                    obraz_po_progowaniu = zamykanie.Apply(obraz_po_progowaniu);

                    pictureBox1.Image = obraz_po_progowaniu;
                    pictureBox1.Update();
                }

                button_area_Click(null, null);
            }
        }
Exemple #28
0
        private void segmentationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Grayscale grayscale = new GrayscaleBT709();

            grayimage         = grayscale.Apply(original);
            pictureBox2.Image = grayimage;
            Threshold bw = new Threshold();

            thresholdimage    = bw.Apply(grayimage);
            pictureBox2.Image = thresholdimage;
            //  ResizeBicubic resize = new ResizeBicubic(200, thresholdimage.Height);
            //  thresholdimage = resize.Apply(thresholdimage);
            List <int> xC    = new List <int> ();
            int        xPrev = 0;

            for (int i = 0; i < thresholdimage.Width; i++)
            {
                count = 0;
                for (int j = 0; j < thresholdimage.Height; j++)
                {
                    Color p = thresholdimage.GetPixel(i, j);
                    if (p.R == 0 && p.G == 0 && p.B == 0)
                    {
                        count++;
                    }
                }
                if (count != 0)
                {
                    if (xC.Count == 0)
                    {
                        xC.Add(i);
                    }
                    else
                    {
                        if (i - xPrev > 1)
                        {
                            xC.Add(i);
                        }
                    }
                    xPrev = i;
                }
            }
            List <Bitmap> ni = new List <Bitmap>();

            for (int i = 0; i < xC.Count; i++)
            {
                int endbound;
                if (i + 1 >= xC.Count)
                {
                    endbound = thresholdimage.Width;
                }
                else
                {
                    endbound = xC[i + 1];
                }
                Crop cr = new Crop(new Rectangle(xC[i], 0, endbound - xC[i], thresholdimage.Height));
                newImage = cr.Apply(thresholdimage);
                ni.Add(newImage);
                pictureBox4.Image = newImage;
                //  newImage.Save(@"C:\users\rahul\desktop\sampleImage.png");
            }

            Invert inv = new Invert();

            invertimage       = inv.Apply(newImage);
            pictureBox5.Image = invertimage;

            ExtractBiggestBlob ebb = new ExtractBiggestBlob();

            blobimage         = ebb.Apply(invertimage);
            pictureBox5.Image = blobimage;

            Invert inv1 = new Invert();

            invertimage1      = inv1.Apply(blobimage);
            pictureBox5.Image = invertimage1;

            List <int> yC     = new List <int>();
            int        xPrev1 = 0;

            for (int j = 0; j < thresholdimage.Height; j++)
            {
                count = 0;
                for (int i = 0; i < thresholdimage.Width; i++)
                {
                    Color p = thresholdimage.GetPixel(i, j);
                    if (p.R == 0 && p.G == 0 && p.B == 0)
                    {
                        count++;
                    }

                    if (count != 0)
                    {
                        if (yC.Count == 0)
                        {
                            yC.Add(j);
                        }
                        else
                        {
                            if (j - xPrev1 > 1)
                            {
                                yC.Add(j);
                            }
                        }
                        xPrev1 = j;
                    }
                }
            }
            List <Bitmap> ni1 = new List <Bitmap>();

            for (int j = 0; j < yC.Count; j++)
            {
                int endbound;
                if (j + 1 >= yC.Count)
                {
                    endbound = thresholdimage.Height;
                }
                else
                {
                    endbound = yC[j + 1];
                }
                Crop cr = new Crop(new Rectangle(0, yC[j], thresholdimage.Height, endbound - yC[j]));
                newImage3 = cr.Apply(thresholdimage);
                ni1.Add(newImage3);
                pictureBox3.Image = newImage3;
                // newImage.Save(@"C:\users\rahul\desktop\sampleImage1.png");
            }
            Invert inv2 = new Invert();

            invertimage3      = inv2.Apply(newImage3);
            pictureBox6.Image = invertimage3;

            ExtractBiggestBlob ebb1 = new ExtractBiggestBlob();

            blobimage1        = ebb1.Apply(invertimage3);
            pictureBox6.Image = blobimage1;

            Invert inv3 = new Invert();

            invertimage2      = inv3.Apply(blobimage1);
            pictureBox6.Image = invertimage2;
        }
Exemple #29
0
        public Bitmap Adelgazar()
        {
            Invert ivert = new Invert();

            imagen = ivert.Apply(imagen);

            FiltersSequence filterSequence = new FiltersSequence();

            filterSequence.Add(new HitAndMiss(
                                   new short[, ] {
                { 0, 0, 0 },
                { -1, 1, -1 },
                { 1, 1, 1 }
            },
                                   HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                                   new short[, ] {
                { -1, 0, 0 },
                { 1, 1, 0 },
                { -1, 1, -1 }
            },
                                   HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                                   new short[, ] {
                { 1, -1, 0 },
                { 1, 1, 0 },
                { 1, -1, 0 }
            },
                                   HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                                   new short[, ] {
                { -1, 1, -1 },
                { 1, 1, 0 },
                { -1, 0, 0 }
            },
                                   HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                                   new short[, ] {
                { 1, 1, 1 },
                { -1, 1, -1 },
                { 0, 0, 0 }
            },
                                   HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                                   new short[, ] {
                { -1, 1, -1 },
                { 0, 1, 1 },
                { 0, 0, -1 }
            },
                                   HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                                   new short[, ] {
                { 0, -1, 1 },
                { 0, 1, 1 },
                { 0, -1, 1 }
            },
                                   HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                                   new short[, ] {
                { 0, 0, -1 },
                { 0, 1, 1 },
                { -1, 1, -1 }
            },
                                   HitAndMiss.Modes.Thinning));

            FilterIterator filterIterator = new FilterIterator(filterSequence, 15);

            imagen = filterIterator.Apply(imagen);

            imagen = ivert.Apply(imagen);

            return(imagen);
        }
Exemple #30
0
        public static Bitmap FilterImage(Bitmap img, int filter)
        {
            Bitmap sourceImage = img;

            sourceImage = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            IFilter myFilter;
            Bitmap  filteredImage = sourceImage;

            if (filter == Filters.filters["Greyscale"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                filteredImage = sourceImage;
            }
            else if (filter == Filters.filters["Sepia"])
            {
                myFilter      = new Sepia();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Invert"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Invert();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["RotateChannel"])
            {
                myFilter      = new RotateChannels();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Threshold"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new Threshold();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["FloydFilter"])
            {
                FloydSteinbergColorDithering myReduction = new FloydSteinbergColorDithering();
                filteredImage = myReduction.Apply(sourceImage);
            }
            else if (filter == Filters.filters["OrderedDithering"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new OrderedDithering();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Sharpen"])
            {
                myFilter      = new Sharpen();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["DifferenceEdgeDetector"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new DifferenceEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["HomogenityEdgeDetector"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new HomogenityEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Sobel"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new SobelEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Jitter"])
            {
                myFilter      = new Jitter(); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["OilPainting"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new OilPainting(); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["TextureFiltering"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Texturer(new TextileTexture(), 1.0, 0.8); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Median"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Median();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Mean"])
            {
                myFilter      = new Mean();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Blur"])
            {
                myFilter      = new GaussianBlur();
                filteredImage = myFilter.Apply(sourceImage);
            }

            //Console.Write(filteredImage.PixelFormat.ToString());
            //Console.Write(sourceImage.PixelFormat.ToString());
            filteredImage = ImageUtil.convert(filteredImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            return(filteredImage);
        }