Example #1
0
        public Bitmap ToExtractChannel(Bitmap Im)
        {
            AForge.Imaging.Filters.ExtractChannel Img = new ExtractChannel();
            Bitmap bmImage = AForge.Imaging.Image.Clone(new Bitmap(Im), PixelFormat.Format24bppRgb);

            return(Img.Apply(bmImage));
        }
        public void ApplyTest()
        {
            Signal target = Signal.FromArray(data, 8000);

            for (int c = 0; c < 2; c++)
            {
                ExtractChannel extract = new ExtractChannel(c);

                var result = extract.Apply(target);


                Assert.AreEqual(result.Length, 6);
                Assert.AreEqual(result.Samples, 6);
                Assert.AreEqual(result.Channels, 1);
                Assert.AreEqual(result.SampleRate, 8000);

                float[] actual   = result.ToFloat();
                float[] expected = data.GetColumn(c);

                for (int i = 0; i < actual.Length; i++)
                {
                    Assert.AreEqual(expected[i], actual[i]);
                }
            }
        }
Example #3
0
        private void UpdateChannelPreviews(System.Drawing.Bitmap pic)
        {
            ExtractChannel r = new ExtractChannel(RGB.R);
            ExtractChannel g = new ExtractChannel(RGB.G);
            ExtractChannel b = new ExtractChannel(RGB.B);

            System.Drawing.Bitmap rImage = null;
            System.Drawing.Bitmap gImage = null;
            System.Drawing.Bitmap bImage = null;

            // apply the filter
            if (pic != null)
            {
                rImage = r.Apply(pic);
                gImage = g.Apply(pic);
                bImage = b.Apply(pic);
            }
            else
            {
                rImage = r.Apply(mainPhoto);
                gImage = g.Apply(mainPhoto);
                bImage = b.Apply(mainPhoto);
            }

            RedChannelbmp   = ToBitmapImage(rImage);
            GreenChannelbmp = ToBitmapImage(gImage);
            BlueChannelbmp  = ToBitmapImage(bImage);
        }
Example #4
0
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox2.SelectedIndex)
            {
            case 0:
                selected = redFilter;
                break;

            case 1:
                selected = greenFilter;
                break;

            case 2:
                selected = blueFilter;
                break;

            default:
                break;
            }
            Bitmap channel = selected.Apply((Bitmap)pictureBox1.Image);

            thresholdFilter = new Threshold(Int32.Parse(textBox1.Text));
            thresholdFilter.ApplyInPlace(channel);
            pictureBox2.Image = channel;
        }
Example #5
0
        private void button5_Click(object sender, EventArgs e)
        {
            ExtractChannel filter = new ExtractChannel(RGB.B);

            img2 = filter.Apply(img1);
            pictureBox2.Image = img2;
        }
Example #6
0
 public Util()
 {
     w                  = new CryptoQrUtilities.QrUtilitiesWrapper();
     filter             = new EuclideanColorFiltering();
     filter.CenterColor = new AForge.Imaging.RGB(Color.Black);
     filter.Radius      = 0;
     bw                 = new OtsuThreshold();
     ecR                = new ExtractChannel(RGB.R);
     ecG                = new ExtractChannel(RGB.G);
     ecB                = new ExtractChannel(RGB.B);
 }
        /// <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);
        }
        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;
        }
Example #9
0
        public TestPanel()
        {
            InitializeComponent();
            selected = redFilter;

            for (int x = 0; x < 187; x++)
            {
                comboBox1.Items.Add(x);
            }

            brownFilter.Red   = new IntRange(55, 85);
            brownFilter.Green = new IntRange(45, 75);
            brownFilter.Blue  = new IntRange(45, 75);

            comboBox2.Items.Add("Re");
            comboBox2.Items.Add("Gr");
            comboBox2.Items.Add("Bl");
        }
Example #10
0
        public static Tuple <Bitmap, Bitmap, Bitmap, Bitmap> getARGBA(Bitmap img)
        {
            img = ImageUtil.convert(img, PixelFormat.Format32bppArgb);

            ExtractChannel myFilter = new ExtractChannel(RGB.R);
            Bitmap         R        = myFilter.Apply(img);

            myFilter = new ExtractChannel(RGB.G);
            Bitmap G = myFilter.Apply(img);

            myFilter = new ExtractChannel(RGB.B);
            Bitmap B = myFilter.Apply(img);

            myFilter = new ExtractChannel(RGB.A);
            Bitmap A = myFilter.Apply(img);

            return(new Tuple <Bitmap, Bitmap, Bitmap, Bitmap>(R, G, B, A));
        }
        public void ExecuteTest()
        {
            Random rd = new Random(1234);

            foreach (int inch in new int[] { 11, 13 })
            {
                foreach (int outch in new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })
                {
                    foreach (int idx_ch in new int[] { 0, (inch - outch) / 2, inch - outch })
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            for (int length = i * 1024 - 2; length <= i * 1024 + 2; length++)
                            {
                                if (length < 1)
                                {
                                    continue;
                                }

                                float[] x = (new float[length * inch]).Select((_) => (float)rd.NextDouble()).ToArray();

                                OverflowCheckedTensor v1 = new OverflowCheckedTensor(Shape.Map1D(inch, length), x);
                                OverflowCheckedTensor v2 = new OverflowCheckedTensor(Shape.Map1D(outch, length));

                                ExtractChannel ope = new ExtractChannel(v1.Shape, idx_ch, v2.Shape);

                                ope.Execute(v1, v2);

                                float[] y = v2.State;

                                for (int j = 0; j < length; j++)
                                {
                                    for (int f = 0; f < outch; f++)
                                    {
                                        Assert.AreEqual(x[idx_ch + f + inch * j], y[f + outch * j], 1e-6f, $"length:{length}, idx:{j}");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #12
0
        public mSwapRGB(Bitmap BaseBitmap, int A, int R, int G, int B)
        {
            ExtractChannel cR = new ExtractChannel(RGB.R);
            ExtractChannel cG = new ExtractChannel(RGB.G);
            ExtractChannel cB = new ExtractChannel(RGB.B);

            ExtractChannel cA = new ExtractChannel(RGB.A);

            YCbCrExtractChannel cL = new YCbCrExtractChannel(YCbCr.YIndex);

            List <Bitmap> maps = new List <Bitmap>();

            Bitmap BmpA = new Bitmap(BaseBitmap.Width, BaseBitmap.Height, PixelFormat.Format16bppGrayScale);
            Bitmap BmpR = new Bitmap(BaseBitmap.Width, BaseBitmap.Height, PixelFormat.Format16bppGrayScale);
            Bitmap BmpG = new Bitmap(BaseBitmap.Width, BaseBitmap.Height, PixelFormat.Format16bppGrayScale);
            Bitmap BmpB = new Bitmap(BaseBitmap.Width, BaseBitmap.Height, PixelFormat.Format16bppGrayScale);
            Bitmap BmpL = new Bitmap(BaseBitmap.Width, BaseBitmap.Height, PixelFormat.Format16bppGrayScale);

            BmpA = cA.Apply(new Bitmap(BaseBitmap));
            BmpR = cR.Apply(new Bitmap(BaseBitmap));
            BmpG = cG.Apply(new Bitmap(BaseBitmap));
            BmpB = cB.Apply(new Bitmap(BaseBitmap));
            BmpL = cL.Apply(new Bitmap(BaseBitmap));

            maps.Add(BmpA);
            maps.Add(BmpR);
            maps.Add(BmpG);
            maps.Add(BmpB);
            maps.Add(BmpL);

            Bitmap bmp = new Bitmap(BaseBitmap.Width, BaseBitmap.Height, PixelFormat.Format32bppArgb);

            bmp.MakeTransparent();

            bmp = new ReplaceChannel(RGB.A, maps[A]).Apply(bmp);
            bmp = new ReplaceChannel(RGB.R, maps[R]).Apply(bmp);
            bmp = new ReplaceChannel(RGB.G, maps[G]).Apply(bmp);
            bmp = new ReplaceChannel(RGB.B, maps[B]).Apply(bmp);

            ModifiedBitmap = new Bitmap(bmp);
        }
Example #13
0
        public static Bitmap Sketch(Bitmap input, int redThreshold, int blueThreshold, int greenThreshold)
        {
            int[,] kernel = {
                { 1, 2, 1, },  
               { 2, 4, 2, },   
               { 1, 2, 1, },
            };
            Convolution convultionFilters = new Convolution(kernel);
            Threshold thresholdFilter = new Threshold(redThreshold);
            input = convultionFilters.Apply(input);
            // extract red channel
            ExtractChannel extractFilter = new ExtractChannel(RGB.R);
            Bitmap channel = extractFilter.Apply(input);
            // threshold channel
            thresholdFilter.ApplyInPlace(channel);
            // put the channel back
            ReplaceChannel replaceFilter = new ReplaceChannel(RGB.R, channel);
            replaceFilter.ApplyInPlace(input);

            // extract blue channel
            extractFilter = new ExtractChannel(RGB.B);
            channel = extractFilter.Apply(input);
            // threshold channel
            thresholdFilter.ThresholdValue = blueThreshold;
            thresholdFilter.ApplyInPlace(channel);
            // put the channel back
            replaceFilter = new ReplaceChannel(RGB.B, channel);
            replaceFilter.ApplyInPlace(input);
            
            // extract green channel
            extractFilter = new ExtractChannel(RGB.G);
            channel = extractFilter.Apply(input);
            // threshold channel
            thresholdFilter.ThresholdValue = greenThreshold;
            thresholdFilter.ApplyInPlace(channel);
            // put the channel back
            replaceFilter = new ReplaceChannel(RGB.G, channel);
            replaceFilter.ApplyInPlace(input);

            return input;
        }
Example #14
0
        /// <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);

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

            ExtractChannel myFilter = new ExtractChannel(RGB.R);

            DA.SetData(0, myFilter.Apply(sourceImage));

            myFilter = new ExtractChannel(RGB.G);
            DA.SetData(1, myFilter.Apply(sourceImage));

            myFilter = new ExtractChannel(RGB.B);
            DA.SetData(2, myFilter.Apply(sourceImage));

            myFilter = new ExtractChannel(RGB.A);
            DA.SetData(3, myFilter.Apply(sourceImage));
        }
        public static Bitmap PrepareForObjectDetection(this System.Drawing.Image bmpOriginalImage, int whiteLevel, bool overrideWhite)
        {
            Bitmap bmp = (Bitmap)bmpOriginalImage.Clone();

            ColorFiltering colorFilter = new ColorFiltering();

            int white = whiteLevel;

            if (!overrideWhite)
            {
                white = PreprocessingHelper.GetWhiteLevel(bmp);
            }

            colorFilter.Red              = new IntRange(0, white / 3);
            colorFilter.Green            = new IntRange(0, white / 3);
            colorFilter.Blue             = new IntRange(0, white / 3);
            colorFilter.FillOutsideRange = true;

            colorFilter.FillColor = new RGB(Color.White);
            colorFilter.ApplyInPlace(bmp);

            ExtractChannel extract_channel = new ExtractChannel(0);

            bmp = extract_channel.Apply(bmp);

            Invert invert = new Invert();

            invert.ApplyInPlace(bmp);

            Threshold threshholdFilter = new Threshold(10);

            threshholdFilter.ApplyInPlace(bmp);

            bmp = bmp.Clone(new Rectangle(0, 0, bmp.Width, bmp.Height), PixelFormat.Format24bppRgb);

            return(bmp);
        }
Example #16
0
 private void button4_Click(object sender, EventArgs e)//B
 {
     filter            = new ExtractChannel(RGB.B);
     bmp2              = filter.Apply(bmp);
     pictureBox2.Image = bmp2;
 }
        void cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap realimage = (Bitmap)eventArgs.Frame.Clone();
            Bitmap rimage    = (Bitmap)eventArgs.Frame.Clone();
            Bitmap bimage    = (Bitmap)eventArgs.Frame.Clone();
            //Red Object detection
            GrayscaleBT709 grayscale = new GrayscaleBT709();
            Subtract       sfilter   = new Subtract(grayscale.Apply(rimage));
            ExtractChannel rchannel  = new ExtractChannel(RGB.R);
            ExtractChannel bchannel  = new ExtractChannel(RGB.B);

            rimage = rchannel.Apply(rimage);
            bimage = bchannel.Apply(bimage);
            sfilter.ApplyInPlace(rimage);
            sfilter.ApplyInPlace(bimage);
            Median mfilter = new Median(5);

            mfilter.ApplyInPlace(rimage);
            mfilter.ApplyInPlace(bimage);
            Threshold thresh = new Threshold(50);

            thresh.ApplyInPlace(rimage);
            thresh.ApplyInPlace(bimage);
            BlobCounter rblob = new BlobCounter();

            rblob.ObjectsOrder = ObjectsOrder.Area;
            rblob.ProcessImage(rimage);
            BlobCounter bblob = new BlobCounter();

            bblob.ObjectsOrder = ObjectsOrder.Area;
            bblob.ProcessImage(bimage);

            Rectangle[] rrect = rblob.GetObjectsRectangles();
            Rectangle[] brect = bblob.GetObjectsRectangles();

            p   = new int[rrect.Length + brect.Length];
            arr = 0;
            if (rrect.Length > 0)
            {
                for (int i = 0; i < rrect.Length; i++)
                {
                    if (rrect[i].Height > 20 && rrect[i].Width > 20)//Object Min height width
                    {
                        Graphics g = Graphics.FromImage(realimage);
                        g.DrawRectangle(new Pen(Color.Red), rrect[i]);
                        objheight = rrect[i].Height;
                        objwidth  = rrect[i].Width;
                        objx      = rrect[i].X + (objwidth / 2);
                        objy      = rrect[i].Y + (objheight / 2);
                        p[i]      = getpartition();
                        arr++;
                        g.DrawEllipse(new Pen(Color.Yellow), objx, objy, 5, 5);
                        g.DrawString("Red Object", new Font("Arial", 10), new SolidBrush(Color.AntiqueWhite), objx, objy - 15);
                        g.DrawString("X:" + objx + "  Y:" + objy, new Font("Arial", 10), new SolidBrush(Color.LimeGreen), objx, objy);
                        g.DrawString("H:" + objheight + "  W:" + objwidth, new Font("Arial", 10), new SolidBrush(Color.LightCyan), objx, objy + 15);
                        g.DrawString("P:" + p[i], new Font("Arial", 10), new SolidBrush(Color.LightSkyBlue), objx, objy + 25);
                    }
                }


                obj = largest();
                if (obj == 0)
                {
                    obj = prevobj;
                }
                prevobj = obj;
            }

            if (brect.Length > 0)
            {
                for (int i = 0; i < brect.Length; i++)
                {
                    if (brect[i].Height > 20 && brect[i].Width > 20)//Object Min height width
                    {
                        Graphics g = Graphics.FromImage(realimage);
                        g.DrawRectangle(new Pen(Color.Red), brect[i]);
                        objheight  = brect[i].Height;
                        objwidth   = brect[i].Width;
                        objx       = brect[i].X + (objwidth / 2);
                        objy       = brect[i].Y + (objheight / 2);
                        p[i + arr] = getpartition();
                        g.DrawEllipse(new Pen(Color.Yellow), objx, objy, 5, 5);
                        g.DrawString("Blue Object", new Font("Arial", 10), new SolidBrush(Color.AntiqueWhite), objx, objy - 15);
                        g.DrawString("X:" + objx + "  Y:" + objy, new Font("Arial", 10), new SolidBrush(Color.LimeGreen), objx, objy);
                        g.DrawString("H:" + objheight + "  W:" + objwidth, new Font("Arial", 10), new SolidBrush(Color.LightCyan), objx, objy + 15);
                        g.DrawString("P:" + p[i + arr], new Font("Arial", 10), new SolidBrush(Color.LightSkyBlue), objx, objy + 25);
                    }
                }

                obj = largest();
                if (obj == 0)
                {
                    obj = prevobj;
                }
                prevobj = obj;
            }



            displayBox.Image = realimage;
        }
Example #18
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

            Text = Text + " " + version.Major + "." + version.Minor + " (build " + version.Build + ")"; //change form title

            //todo: make this user selectable.
            SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS); // Set form as top form.  Always on top.
            AForge.Vision.Motion.MotionDetector motionDetector = null;
            motionDetector          = GetDefaultMotionDetector();
            globalTimer.Elapsed    += GlobalTimer_Elapsed;
            lureTimer.Elapsed      += LureTimer_Elapsed;
            baitTimer.Elapsed      += BaitTimer_Elapsed;
            screenUpdateTimer.Tick += ScreenUpdateTimer_Tick;

            screenStateLogger.ScreenRefreshed += (sender1, data) =>
            {
                //New frame in data
                System.Drawing.Image i = System.Drawing.Image.FromStream(new MemoryStream(data));
                origScreenHeight = i.Height;
                origScreenWidth  = i.Width;
                // todo:  The percentage of scan area should be able to be set on the form
                // To help in scan speed and to eliminate some of the external noise, only scan the center of the screen.

                int       left    = (int)(i.Width * 0.40);
                int       right   = (int)(i.Width * 0.60) - left;
                int       top     = (int)(i.Height * 0.50);
                int       bottom  = (int)(i.Height * 0.70) - top;
                Rectangle srcRect = new Rectangle(left, top, right, bottom);
                Bitmap    cropped = ((Bitmap)i).Clone(srcRect, i.PixelFormat);


                // depending on the area of the game it is sometimes best to remove some colors.

                if (rbGreyScaleFilter.Checked)
                {
                    cropped = Grayscale.CommonAlgorithms.BT709.Apply(cropped);
                }


                if (rbRedFilter.Checked)
                {
                    ExtractChannel extractFilter = new ExtractChannel(RGB.R);
                    cropped = extractFilter.Apply(cropped);
                }

                if (rbBlueFilter.Checked)
                {
                    ExtractChannel extractFilter = new ExtractChannel(RGB.B);
                    cropped = extractFilter.Apply(cropped);
                }

                if (rbGreenFilter.Checked)
                {
                    ExtractChannel extractFilter = new ExtractChannel(RGB.G);
                    cropped = extractFilter.Apply(cropped);
                }


                detectMovement((Bitmap)cropped);
                pbViewPane.Image = (Bitmap)cropped;
            };
            screenStateLogger.Start();
        }
Example #19
0
        public void Video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            UnmanagedImage image = UnmanagedImage.FromManagedImage((Bitmap)eventArgs.Frame.Clone());

            var            extractChannel = new ExtractChannel(RGB.R);
            UnmanagedImage channel        = extractChannel.Apply(image);

            //		UnmanagedImage originalRed = channel.Clone();
            if (true)
            {
                var threshold = new Threshold(200);
                threshold.ApplyInPlace(channel);

                ////filter to convert RGB image to 8bpp gray scale for image processing
                //IFilter gray_filter = new GrayscaleBT709();
                //gray_image = gray_filter.Apply(gray_image);

                ////thresholding a image
                //Threshold th_filter = new Threshold(color_data.threshold);
                //th_filter.ApplyInPlace(gray_image);

                //erosion filter to filter out small unwanted pixels
                Erosion3x3 erosion = new Erosion3x3();
                erosion.ApplyInPlace(channel);

                //dilation filter
                //Dilatation3x3 dilatation = new Dilatation3x3();
                //dilatation.ApplyInPlace(channel);

                //GrayscaleToRGB filter = new GrayscaleToRGB();
                //image = filter.Apply(channel);

                //ReplaceChannel replaceFilter = new ReplaceChannel(RGB.B, channel);
                //replaceFilter.ApplyInPlace(image);
            }

            BlobCounter bc = new BlobCounter();

            //arrange blobs by area
            bc.ObjectsOrder = ObjectsOrder.Area;
            bc.FilterBlobs  = true;
            bc.MinHeight    = minObjectSize;
            bc.MinWidth     = minObjectSize;
            bc.MaxHeight    = maxObjectSize;
            bc.MaxWidth     = maxObjectSize;

            //process image for blobs
            bc.ProcessImage(channel);
            channel.Dispose();

            //	if (motionDetector.ProcessFrame(image) > 0.02) {
            //	for (int i = 0; i < blobCountingObjectsProcessing.ObjectRectangles.Length; i++) {
            Rectangle[] rectangles = bc.GetObjectsRectangles();
            Blob[]      blobs      = bc.GetObjectsInformation();
            for (int i = 0; i < bc.ObjectsCount; i++)
            {
                Rectangle rectangle = rectangles[i];
                int       width     = rectangle.Width;
                int       height    = rectangle.Height;

                //		if (width < maxObjectSize && height < maxObjectSize && width > minObjectSize && height > minObjectSize) {
                Drawing.Rectangle(image, rectangle, colorList[i % colorList.Length]);

                if (i == 0)
                {
                    Position = GetCenterOfMass(image, rectangle);
                    Drawing.FillRectangle(image, rectangle, Color.BlanchedAlmond);
                    Drawing.FillRectangle(image, new Rectangle((int)Position.U - dotSize, (int)Position.V - dotSize, dotSize * 3, dotSize * 3), Color.Indigo);
                }
                //		}
            }
            //	}

            Image = image.ToManagedImage();
            //	videoForm.ImageDestination.Image = image.ToManagedImage();
        }
Example #20
0
        private static WavechartBox show(String title, bool hold, params Tuple <Signal, int>[] series)
        {
            WavechartBox form       = null;
            Thread       formThread = null;

            AutoResetEvent stopWaitHandle = new AutoResetEvent(false);

            formThread = new Thread(() =>
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // Show control in a form
                form            = new WavechartBox();
                form.Text       = title;
                form.formThread = formThread;

                if (!String.IsNullOrEmpty(title))
                {
                    form.zedGraphControl.GraphPane.Title.IsVisible = true;
                    form.zedGraphControl.GraphPane.Title.Text      = title;
                }

                var sequence = new ColorSequenceCollection(series.Length);

                for (int i = 0; i < series.Length; i++)
                {
                    var signal  = series[i].Item1;
                    int channel = series[i].Item2;

                    ComplexSignal complex = signal as ComplexSignal;

                    if (complex != null && complex.Status != ComplexSignalStatus.Normal)
                    {
                        double[] spectrum    = Accord.Audio.Tools.GetPowerSpectrum(complex.GetChannel(channel));
                        double[] frequencies = Accord.Audio.Tools.GetFrequencyVector(signal.Length, signal.SampleRate);

                        form.series.Add(new LineItem(i.ToString(), frequencies,
                                                     spectrum, sequence.GetColor(i), SymbolType.None));

                        form.zedGraphControl.GraphPane.XAxis.Title.Text = "Frequency";
                        form.zedGraphControl.GraphPane.YAxis.Title.Text = "Power";
                    }
                    else
                    {
                        double[] values;
                        if (signal.Channels == 1)
                        {
                            values = signal.ToDouble();
                        }
                        else
                        {
                            ExtractChannel extract = new ExtractChannel(channel);
                            values = extract.Apply(signal).ToDouble();
                        }

                        form.series.Add(new LineItem(i.ToString(), Matrix.Indices(0, signal.Length).ToDouble(),
                                                     values, sequence.GetColor(i), SymbolType.None));

                        form.zedGraphControl.GraphPane.XAxis.Title.Text = "Time";
                        form.zedGraphControl.GraphPane.YAxis.Title.Text = "Amplitude";
                    }
                }

                form.zedGraphControl.GraphPane.AxisChange();

                stopWaitHandle.Set();

                Application.Run(form);
            });

            formThread.SetApartmentState(ApartmentState.STA);

            formThread.Start();

            stopWaitHandle.WaitOne();

            if (!hold)
            {
                formThread.Join();
            }

            return(form);
        }
Example #21
0
        public mExtractARGBChannel(short Channel)
        {
            BitmapType = mFilter.BitmapTypes.None;

            filter = new ExtractChannel(Channel);
        }
Example #22
0
        public static byte[] ApplyFilter(byte[] imageBytes, ImageProcessingFilters filter, ImageFormat format = null)
        {
            IFilter baseFilter = null;

            switch (filter)
            {
            case ImageProcessingFilters.Default:
                return(imageBytes);

            case ImageProcessingFilters.GrayscaleBT709:
                baseFilter = new GrayscaleBT709();
                break;

            case ImageProcessingFilters.GrayscaleRMY:
                baseFilter = new GrayscaleRMY();
                break;

            case ImageProcessingFilters.GrayscaleY:
                baseFilter = new GrayscaleY();
                break;

            case ImageProcessingFilters.BayerFilter:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new ExtractChannel(RGB.B));
                ((FiltersSequence)baseFilter).Add(new BayerFilter());
                break;

            /*
             * case ImageProcessingFilters.ImageWarp:
             * baseFilter = new ImageWarp(
             * break;
             * */
            case ImageProcessingFilters.Channel_Red:
                baseFilter = new ExtractChannel(RGB.R);
                break;

            case ImageProcessingFilters.Channel_Green:
                baseFilter = new ExtractChannel(RGB.G);
                break;

            case ImageProcessingFilters.Channel_Blue:
                baseFilter = new ExtractChannel(RGB.B);
                break;

            case ImageProcessingFilters.WaterWave:
                baseFilter = new WaterWave();
                ((WaterWave)baseFilter).HorizontalWavesCount     = 10;
                ((WaterWave)baseFilter).HorizontalWavesAmplitude = 5;
                ((WaterWave)baseFilter).VerticalWavesCount       = 3;
                ((WaterWave)baseFilter).VerticalWavesAmplitude   = 15;
                break;

            case ImageProcessingFilters.Sepia:
                baseFilter = new Sepia();
                break;

            case ImageProcessingFilters.BrightnessCorrection:
                baseFilter = new BrightnessCorrection(-50);
                break;

            case ImageProcessingFilters.ContrastCorrection:
                baseFilter = new ContrastCorrection(15);
                break;

            case ImageProcessingFilters.SaturationCorrection1:
                baseFilter = new SaturationCorrection(-0.5f);
                break;

            case ImageProcessingFilters.SaturationCorrection2:
                baseFilter = new SaturationCorrection(-.25f);
                break;

            case ImageProcessingFilters.SaturationCorrection3:
                baseFilter = new SaturationCorrection(+0.5f);
                break;

            case ImageProcessingFilters.Invert:
                baseFilter = new Invert();
                break;

            case ImageProcessingFilters.Blur:
                baseFilter = new Blur();
                break;

            case ImageProcessingFilters.RotateChannels:
                baseFilter = new RotateChannels();
                break;

            case ImageProcessingFilters.RotateChannels2:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new RotateChannels());
                ((FiltersSequence)baseFilter).Add(new RotateChannels());
                break;

            case ImageProcessingFilters.AdditiveNoise:
                IRandomNumberGenerator generator = new UniformGenerator(new Range(-50, 50));
                baseFilter = new AdditiveNoise(generator);
                break;

            case ImageProcessingFilters.GammaCorrection:
                baseFilter = new GammaCorrection(0.5);
                break;

            case ImageProcessingFilters.HistogramEqualization:
                baseFilter = new HistogramEqualization();
                break;

            case ImageProcessingFilters.OrderedDithering:
                byte[,] matrix = new byte[4, 4]
                {
                    { 95, 233, 127, 255 },
                    { 159, 31, 191, 63 },
                    { 111, 239, 79, 207 },
                    { 175, 47, 143, 15 }
                };
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new GrayscaleBT709());
                ((FiltersSequence)baseFilter).Add(new OrderedDithering(matrix));
                break;

            case ImageProcessingFilters.Pixallete:
                baseFilter = new Pixellate();
                break;

            case ImageProcessingFilters.SimplePosterization:
                baseFilter = new SimplePosterization();
                break;

            case ImageProcessingFilters.Texturer_Textile:
                baseFilter = new Texturer(new AForge.Imaging.Textures.TextileTexture(), 0.3, 0.7);
                break;

            case ImageProcessingFilters.Texturer_Cloud:
                baseFilter = new Texturer(new AForge.Imaging.Textures.CloudsTexture(), 0.3, 0.7);
                break;

            case ImageProcessingFilters.Texturer_Marble:
                baseFilter = new Texturer(new AForge.Imaging.Textures.MarbleTexture(), 0.3, 0.7);
                break;

            case ImageProcessingFilters.Texturer_Wood:
                baseFilter = new Texturer(new AForge.Imaging.Textures.WoodTexture(), 0.3, 0.7);
                break;

            case ImageProcessingFilters.Texturer_Labyrinth:
                baseFilter = new Texturer(new AForge.Imaging.Textures.LabyrinthTexture(), 0.3, 0.7);
                break;

            case ImageProcessingFilters.SobelEdgeDetector:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new ExtractChannel(RGB.R));
                ((FiltersSequence)baseFilter).Add(new SobelEdgeDetector());
                break;

            case ImageProcessingFilters.SobelEdgeDetectorInvert:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new ExtractChannel(RGB.R));
                ((FiltersSequence)baseFilter).Add(new SobelEdgeDetector());
                ((FiltersSequence)baseFilter).Add(new Invert());
                break;

            case ImageProcessingFilters.SobelEdgeDetectorSepia:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new ExtractChannel(RGB.R));
                ((FiltersSequence)baseFilter).Add(new SobelEdgeDetector());
                ((FiltersSequence)baseFilter).Add(new GrayscaleToRGB());
                ((FiltersSequence)baseFilter).Add(new Sepia());
                break;

            case ImageProcessingFilters.SobelEdgeDetectorSepiaCanvas:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new ExtractChannel(RGB.R));
                ((FiltersSequence)baseFilter).Add(new SobelEdgeDetector());
                ((FiltersSequence)baseFilter).Add(new GrayscaleToRGB());
                ((FiltersSequence)baseFilter).Add(new Sepia());
                ((FiltersSequence)baseFilter).Add(new SimplePosterization());
                ((FiltersSequence)baseFilter).Add(new Texturer(new AForge.Imaging.Textures.TextileTexture(), 0.3, 0.7));
                break;

            case ImageProcessingFilters.Drawing:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new GrayscaleBT709());
                ((FiltersSequence)baseFilter).Add(new SobelEdgeDetector());
                ((FiltersSequence)baseFilter).Add(new Invert());
                ((FiltersSequence)baseFilter).Add(new SimplePosterization());
                break;

            case ImageProcessingFilters.DrawingSepia:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new GrayscaleBT709());
                ((FiltersSequence)baseFilter).Add(new SobelEdgeDetector());
                ((FiltersSequence)baseFilter).Add(new Invert());
                ((FiltersSequence)baseFilter).Add(new SimplePosterization());
                ((FiltersSequence)baseFilter).Add(new GrayscaleToRGB());
                ((FiltersSequence)baseFilter).Add(new Sepia());
                break;

            case ImageProcessingFilters.OilCanvas:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new SimplePosterization());
                ((FiltersSequence)baseFilter).Add(new Texturer(new AForge.Imaging.Textures.TextileTexture(), 0.3, 0.7));
                break;

            case ImageProcessingFilters.OilCanvasGray:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new SimplePosterization());
                ((FiltersSequence)baseFilter).Add(new Texturer(new AForge.Imaging.Textures.TextileTexture(), 0.3, 0.7));
                ((FiltersSequence)baseFilter).Add(new GrayscaleBT709());
                break;

            case ImageProcessingFilters.OilCanvasSepia:
                baseFilter = new FiltersSequence();
                ((FiltersSequence)baseFilter).Add(new SimplePosterization());
                ((FiltersSequence)baseFilter).Add(new Texturer(new AForge.Imaging.Textures.TextileTexture(), 0.3, 0.7));
                ((FiltersSequence)baseFilter).Add(new Sepia());
                break;
            }

            if (baseFilter == null)
            {
                return(null);
            }

            return(ApplyFilter(imageBytes, baseFilter, format));
        }
Example #23
0
        public Bitmap ExtractChannelFilter(Bitmap img)
        {
            ExtractChannel filter = new ExtractChannel(AForge.Imaging.RGB.G);

            return(filter.Apply(img));
        }