/// <summary> /// 处理(当前)画面 /// </summary> /// <param name="image"></param> public void ProcessFrame(ref Bitmap image) { if (backgroundFrame == null) { backgroundFrame = GrayscaleFilter.Apply(image); // create initial backgroung image // get image dimension width = image.Width; height = image.Height; // just return for the first time return; } Bitmap tmpImage = GrayscaleFilter.Apply(image); //灰度过滤 // set backgroud frame as an overlay for difference filter DifferenceFilter.OverlayImage = backgroundFrame; Bitmap tmpImage2 = DifferenceFilter.Apply(tmpImage); //差异过滤 // lock the temporary image and apply some filters on the locked data bitmapData = tmpImage2.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); // threshold filter ThresholdFilter.ApplyInPlace(bitmapData); //阈值过滤 // erosion filter Bitmap tmpImage3 = ErosionFilter.Apply(bitmapData); //腐蚀过滤 // unlock temporary image tmpImage2.UnlockBits(bitmapData); tmpImage2.Dispose(); // calculate amount of changed pixels pixelsChanged = (calculateMotionLevel) ? CalculateWhitePixels(tmpImage3) : 0; // dispose old background backgroundFrame.Dispose(); // set backgound to current backgroundFrame = tmpImage; // extract red channel from the original image Bitmap redChannel = extrachChannel.Apply(image); //提取通道 // merge red channel with moving object MergeFilter.OverlayImage = tmpImage3; Bitmap tmpImage4 = MergeFilter.Apply(redChannel); //合并过滤 redChannel.Dispose(); tmpImage3.Dispose(); // replace red channel in the original image replaceChannel.ChannelImage = tmpImage4; Bitmap tmpImage5 = replaceChannel.Apply(image); //替换通道 tmpImage4.Dispose(); image.Dispose(); image = tmpImage5; }
// Process new frame public void ProcessFrame(ref Bitmap image) { if (backgroundFrame == null) { // create initial backgroung image backgroundFrame = grayscaleFilter.Apply(image); // just return for the first time return; } Bitmap tmpImage; // apply the the grayscale file tmpImage = grayscaleFilter.Apply(image); if (++counter == 2) { counter = 0; // move background towards current frame moveTowardsFilter.OverlayImage = tmpImage; Bitmap tmp = moveTowardsFilter.Apply(backgroundFrame); // dispose old background backgroundFrame.Dispose(); backgroundFrame = tmp; } // set backgroud frame as an overlay for difference filter differenceFilter.OverlayImage = backgroundFrame; // apply the the filters sequence Bitmap tmpImage2 = processingFilter.Apply(tmpImage); tmpImage.Dispose(); // extract red channel from the original image Bitmap redChannel = extrachChannel.Apply(image); // merge red channel with moving object borders mergeFilter.OverlayImage = tmpImage2; Bitmap tmpImage3 = mergeFilter.Apply(redChannel); redChannel.Dispose(); tmpImage2.Dispose(); // replace red channel in the original image replaceChannel.ChannelImage = tmpImage3; Bitmap tmpImage4 = replaceChannel.Apply(image); tmpImage3.Dispose(); image.Dispose(); image = tmpImage4; }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Bitmap sourceImage = null; DA.GetData(0, ref sourceImage); Bitmap RChannel = null; DA.GetData(1, ref RChannel); Bitmap GChannel = null; DA.GetData(2, ref GChannel); Bitmap BChannel = null; DA.GetData(3, ref BChannel); Bitmap AChannel = null; DA.GetData(4, ref AChannel); sourceImage = ImageUtil.convert(sourceImage, PixelFormat.Format32bppArgb); if (RChannel != null) { RChannel = ImageUtil.convert(RChannel, PixelFormat.Format32bppArgb); RChannel = Grayscale.CommonAlgorithms.RMY.Apply(RChannel); ReplaceChannel myFilter = new ReplaceChannel(RGB.R, RChannel); sourceImage = myFilter.Apply(sourceImage); } if (GChannel != null) { GChannel = ImageUtil.convert(GChannel, PixelFormat.Format32bppArgb); GChannel = Grayscale.CommonAlgorithms.RMY.Apply(GChannel); ReplaceChannel myFilter = new ReplaceChannel(RGB.G, GChannel); sourceImage = myFilter.Apply(sourceImage); } if (BChannel != null) { BChannel = ImageUtil.convert(BChannel, PixelFormat.Format32bppArgb); BChannel = Grayscale.CommonAlgorithms.RMY.Apply(BChannel); ReplaceChannel myFilter = new ReplaceChannel(RGB.B, BChannel); sourceImage = myFilter.Apply(sourceImage); } if (AChannel != null) { AChannel = ImageUtil.convert(AChannel, PixelFormat.Format32bppArgb); AChannel = Grayscale.CommonAlgorithms.RMY.Apply(AChannel); ReplaceChannel myFilter = new ReplaceChannel(RGB.A, AChannel); sourceImage = myFilter.Apply(sourceImage); } DA.SetData(0, sourceImage); }
private void process_button_Click(object sender, EventArgs e) { //changes are made here //Doing classic image layer by layer //modifying image layer by layer var extractRGBchannelFilter = new ExtractChannel(); extractRGBchannelFilter.Channel = AForge.Imaging.RGB.G;//RGB.R RGB.B var redChannel = extractRGBchannelFilter.Apply(_inputImage); var threshold = new Threshold(150); var thresholdedImage = threshold.Apply(redChannel); var replacedFilter = new ReplaceChannel(AForge.Imaging.RGB.G, thresholdedImage); var replacedImage = replacedFilter.Apply(_inputImage); pictureBoxOutput.Image = replacedImage; }
public static Bitmap RGBA_replaceChannel(Bitmap img, Bitmap RChannel, Bitmap GChannel, Bitmap BChannel, Bitmap AChannel) { Bitmap NewIMG = ImageUtil.convert(img, PixelFormat.Format32bppArgb); if (RChannel != null) { RChannel = ImageUtil.convert(RChannel, PixelFormat.Format32bppArgb); RChannel = Grayscale.CommonAlgorithms.RMY.Apply(RChannel); ReplaceChannel myFilter = new ReplaceChannel(RGB.R, RChannel); img = myFilter.Apply(img); } if (GChannel != null) { GChannel = ImageUtil.convert(GChannel, PixelFormat.Format32bppArgb); GChannel = Grayscale.CommonAlgorithms.RMY.Apply(GChannel); ReplaceChannel myFilter = new ReplaceChannel(RGB.G, GChannel); img = myFilter.Apply(img); } if (BChannel != null) { BChannel = ImageUtil.convert(BChannel, PixelFormat.Format32bppArgb); BChannel = Grayscale.CommonAlgorithms.RMY.Apply(BChannel); ReplaceChannel myFilter = new ReplaceChannel(RGB.B, BChannel); img = myFilter.Apply(img); } if (AChannel != null) { AChannel = ImageUtil.convert(AChannel, PixelFormat.Format32bppArgb); AChannel = Grayscale.CommonAlgorithms.RMY.Apply(AChannel); ReplaceChannel myFilter = new ReplaceChannel(RGB.A, AChannel); img = myFilter.Apply(img); } return(img); }
// Process new frame public void ProcessFrame(ref Bitmap image) { if (backgroundFrame == null) { // create initial backgroung image backgroundFrame = processingFilter1.Apply(image); // get image dimension width = image.Width; height = image.Height; // just return for the first time return; } Bitmap tmpImage; // apply the the first filters sequence tmpImage = processingFilter1.Apply(image); if (++counter == 2) { counter = 0; // move background towards current frame moveTowardsFilter.OverlayImage = tmpImage; moveTowardsFilter.ApplyInPlace(backgroundFrame); } // set backgroud frame as an overlay for difference filter differenceFilter.OverlayImage = backgroundFrame; // lock temporary image to apply several filters bitmapData = tmpImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); // apply difference filter differenceFilter.ApplyInPlace(bitmapData); // apply threshold filter thresholdFilter.ApplyInPlace(bitmapData); // apply dilatation filter Bitmap tmpImage2 = dilatationFilter.Apply(bitmapData); // unlock temporary image tmpImage.UnlockBits(bitmapData); tmpImage.Dispose( ); // calculate amount of changed pixels pixelsChanged = (calculateMotionLevel) ? CalculateWhitePixels(tmpImage2) : 0; // find edges Bitmap tmpImage2b = edgesFilter.Apply(tmpImage2); tmpImage2.Dispose( ); // extract red channel from the original image Bitmap redChannel = extrachChannel.Apply(image); // merge red channel with moving object borders mergeFilter.OverlayImage = tmpImage2b; Bitmap tmpImage3 = mergeFilter.Apply(redChannel); redChannel.Dispose( ); tmpImage2b.Dispose( ); // replace red channel in the original image replaceChannel.ChannelImage = tmpImage3; Bitmap tmpImage4 = replaceChannel.Apply(image); tmpImage3.Dispose( ); image.Dispose( ); image = tmpImage4; }
// Process new frame public void ProcessFrame(ref Bitmap image) { if (backgroundFrame == null) { // create initial backgroung image backgroundFrame = grayscaleFilter.Apply(image); // get image dimension width = image.Width; height = image.Height; // just return for the first time return; } Bitmap tmpImage; // apply the grayscale file tmpImage = grayscaleFilter.Apply(image); // set backgroud frame as an overlay for difference filter differenceFilter.OverlayImage = backgroundFrame; // apply difference filter Bitmap tmpImage2 = differenceFilter.Apply(tmpImage); // lock the temporary image and apply some filters on the locked data bitmapData = tmpImage2.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); // threshold filter thresholdFilter.ApplyInPlace(bitmapData); // erosion filter Bitmap tmpImage3 = erosionFilter.Apply(bitmapData); // unlock temporary image tmpImage2.UnlockBits(bitmapData); tmpImage2.Dispose( ); // calculate amount of changed pixels pixelsChanged = (calculateMotionLevel) ? CalculateWhitePixels(tmpImage3) : 0; // dispose old background backgroundFrame.Dispose( ); // set backgound to current backgroundFrame = tmpImage; // extract red channel from the original image Bitmap redChannel = extrachChannel.Apply(image); // merge red channel with moving object mergeFilter.OverlayImage = tmpImage3; Bitmap tmpImage4 = mergeFilter.Apply(redChannel); redChannel.Dispose( ); tmpImage3.Dispose( ); // Updated from original example to support new AForge Libraries (Sumit) if (replaceChannel == null) { replaceChannel = new ReplaceChannel(RGB.R, tmpImage4); } else { replaceChannel.ChannelImage = tmpImage4; } Bitmap tmpImage5 = replaceChannel.Apply(image); tmpImage4.Dispose( ); image.Dispose( ); image = tmpImage5; }
private int width;// image width /// <summary> /// The ProcessFrame /// </summary> /// <param name="image">The image<see cref="Bitmap"/></param> public Bitmap ProcessFrame(Bitmap image) { if (backgroundFrame == null) { // create initial backgroung image backgroundFrame = grayscaleFilter.Apply(image); // get image dimension width = image.Width; height = image.Height; // just return for the first time return(null); } // apply the the grayscale file var tmpImage = grayscaleFilter.Apply(image); if (++counter == 2) { counter = 0; // move background towards current frame moveTowardsFilter.OverlayImage = tmpImage; moveTowardsFilter.ApplyInPlace(backgroundFrame); } // set backgroud frame as an overlay for difference filter differenceFilter.OverlayImage = backgroundFrame; // lock temporary image to apply several filters bitmapData = tmpImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); // apply difference filter differenceFilter.ApplyInPlace(bitmapData); // apply threshold filter thresholdFilter.ApplyInPlace(bitmapData); pixelsChanged = CalculateWhitePixels(bitmapData); var tmpImage2 = openingFilter.Apply(bitmapData); // unlock temporary image tmpImage.UnlockBits(bitmapData); tmpImage.Dispose(); // apply edges filter var tmpImage2b = edgesFilter.Apply(tmpImage2); tmpImage2.Dispose(); // extract red channel from the original image var redChannel = extrachChannel.Apply(image); // merge red channel with moving object borders mergeFilter.OverlayImage = tmpImage2b; var tmpImage3 = mergeFilter.Apply(redChannel); redChannel.Dispose(); tmpImage2b.Dispose(); // replace red channel in the original image replaceChannel.ChannelImage = tmpImage3; var tmpImage4 = replaceChannel.Apply(image); tmpImage3.Dispose(); image.Dispose(); image = tmpImage4; return(image); }