Esempio n. 1
0
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            object obj = objectProvider.GetObject();
            FxVectorF vec;
            if (obj is FxVectorF || obj is FxVector<float>)
                vec = obj as FxVectorF;
            else
                return;

            Canvas canvas = new Canvas();
            canvas.Dock = DockStyle.Fill;
            canvas.Location = new System.Drawing.Point(0, 0);
            canvas.Margin = new System.Windows.Forms.Padding(4);
            canvas.Name = "canvas1";
            canvas.Zoom = new System.Drawing.SizeF(1F, 1F);

            PloterElement plot = new PloterElement(vec);
            canvas.AddElement(plot);
            canvas.FitView();

            windowService.ShowDialog(canvas);
        }
Esempio n. 2
0
        private void ellipseDetectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

                // load image
                imMat = FxMatrixF.Load(ofd.FileName);
                ieEllipseImage = new ImageElement(imMat, new ColorMap(ColorMapDefaults.Jet));
                ieEllipseImage.lockMoving = true;
                canvas_ellipse.AddElement(ieEllipseImage);

                // add plot element 
                gpeEllipseImage = new GeometryPlotElement();
                canvas_ellipse.AddElement(gpeEllipseImage);


                var contours = new FxContour(imMat<0.2f);

                WriteLine("Num Contours : " + contours.NumChains);

                int i = 0;
                float pe_pos_y = ieEllipseImage._Position.y;
                foreach (var cont in contours.ChainList)
                {
                    // draw the rectanges in main image
                    FxVector2f start = cont.RectStart ;
                    FxVector2f end = start + cont.RectSize;
                    FxMaths.Geometry.Rectangle r = new FxMaths.Geometry.Rectangle(start, end);
                    gpeEllipseImage.AddGeometry(r, false);


                    // draw the centroids 
                    FxVector2f cen = cont.GetCentroid();
                    var l = new FxMaths.Geometry.Line(cen - new FxVector2f(0, 2), cen + new FxVector2f(0, 2));
                    l.LineWidth = 0.5f;
                    gpeEllipseImage.AddGeometry(l, false);
                    l = new FxMaths.Geometry.Line(cen - new FxVector2f(2, 0), cen + new FxVector2f(2, 0));
                    l.LineWidth = 0.5f;
                    gpeEllipseImage.AddGeometry(l, false);


                    // add the numbering of the contours
                    var t = new TextElement(i.ToString());
                    t._Position = cen;
                    t.FontColor = SharpDX.Color.Green;
                    t._TextFormat.fontSize = 16.0f;
                    canvas_ellipse.AddElement(t);

                    // show the chain vector in plot
                    {
                        FxVectorF vec_i = new FxVectorF(cont.Count);
                        FxVectorF vec_r = new FxVectorF(cont.Count);
                        vec_i[0] = cont[0].i;
                        vec_r[0] = cont[0].r;
                        for (int j = 1; j < cont.Count; j++)
                        {
                            vec_i[j] = vec_i[j - 1] + cont[j].i;
                            vec_r[j] = vec_r[j - 1] + cont[j].r;
                        }

                        // show  the plot of this vector
                        var pe = new PloterElement(vec_i, PlotType.Lines, System.Drawing.Color.Blue);
                        pe._Position.x = ieEllipseImage._Position.x + ieEllipseImage.Size.x;
                        pe._Position.y = pe_pos_y;
                        pe.AddPlot(vec_r, PlotType.Lines, System.Drawing.Color.Red);
                        pe.CenterYOrigin();
                        pe.FitPlots();
                        canvas_ellipse.AddElement(pe);

                        // update the y of pe for the next one
                        pe_pos_y += pe.Size.y;

                        // debug the ellipse

                        for (int j = 0; j < cont.Count; j++)
                        {
                            imMat[(int)(vec_r[j] + cont.StartPoint.x), (int)(vec_i[j] + cont.StartPoint.y)] = 0.8f/contours.NumChains + 0.1f;
                        }
                        ieEllipseImage.UpdateInternalImage(imMat, new ColorMap(ColorMapDefaults.Jet));

                    }



                    i++;
                }

                canvas_ellipse.ReDraw();
            }
        }
Esempio n. 3
0
        private void button9_Click( object sender, EventArgs e )
        {
            // check if we have select file
            if ( String.IsNullOrEmpty( audioFileName ) ) {
                button8_Click( sender, e );
            }

            if ( String.IsNullOrEmpty( audioFileName ) ) {
                return;
            }

            // create wave out device
            CreateWaveOut();

            // create steram file
            ISampleProvider sampleProvider = null;

            try {

                // read the file
                fileWaveStream = new Mp3FileReader( audioFileName );

                // cretae the wave channel
                var waveChannel =  new SampleChannel( this.fileWaveStream );
                waveChannel.Volume = 0.5f;

                // create the sampler
                sampleProvider = new MeteringSampleProvider( waveChannel );

            } catch ( Exception createException ) {
                MessageBox.Show( String.Format( "{0}", createException.Message ), "Error Loading File" );
                return;
            }

            try {

                // in the wave out ( give and the call back for the editing
                waveOut.Init( new SampleToWaveProvider( sampleProvider), callback);

            } catch ( Exception initException ) {
                MessageBox.Show( String.Format( "{0}", initException.Message ), "Error Initializing Output" );
                return;
            }

            if ( plot_signal_spectrum == null )
            {

                #region Plot Creation

                signal_spectrum = new FxVectorF(256);

                // insert the plot of the time filter
                filterPlot = new PloterElement(signal_spectrum);
                filterPlot.Position.X = 0;
                filterPlot.Position.Y = 410;
                filterPlot.Origin = new FxVector2f(10, 100);
                filterPlot.FitPlots();
                canvas_audio.AddElements(filterPlot);

                // create the plot for the spectrum
                plot_signal_spectrum = new PloterElement( signal_spectrum );
                plot_signal_spectrum.Position.X = 0;
                plot_signal_spectrum.Position.Y = 10;
                plot_signal_spectrum.Origin = new FxVector2f(10, 100);
                plot_signal_spectrum.FitPlots();
                plot_signal_spectrum.AddPlot(signal_spectrum, PlotType.Lines, Color.Aqua);

                // add the signal to canva
                canvas_audio.AddElements(plot_signal_spectrum);

                // create the plot for the spectrum
                plot_signal_spectrum_original = new PloterElement(signal_spectrum);
                plot_signal_spectrum_original.Position.X = 600;
                plot_signal_spectrum_original.Position.Y = 10;
                plot_signal_spectrum_original.Origin = new FxVector2f(10, 100);
                plot_signal_spectrum_original.FitPlots();

                // add the signal to canva
                canvas_audio.AddElements(plot_signal_spectrum_original);

                // create the plot for the spectrum
                plot_filter_spectrum = new PloterElement(signal_spectrum);
                plot_filter_spectrum.Position.X = 600;
                plot_filter_spectrum.Position.Y = 410;
                plot_filter_spectrum.Origin = new FxVector2f(10, 100);
                plot_filter_spectrum.FitPlots();

                // add the signal to canva
                canvas_audio.AddElements(plot_filter_spectrum);
                #endregion

                // add filter
                UpdateFilter(BiQuadFilter.BandPassFilterConstantPeakGain(44100, 20000, 0.5f));

            }

            // start play
            waveOut.Play();
        }
Esempio n. 4
0
        private void button6_Click( object sender, EventArgs e )
        {
            FxVectorF convResultFFT;

            // create a filter for testing
            FxVectorF filter = new FxVectorF( 1024 );
            filter[0] = 0.1f;
            filter[1] = 0.5f;
            filter[2] = 1.5f;
            filter[3] = 0.5f;
            filter[4] = 0.1f;
            TimeStatistics.StartClock();

            // execute the conv
            SignalTools.Convolution_FFT_F( signal, filter, out convResultFFT );
            //SignalTools.Convolution_DFT_F( signal, filter, out convResultDFT );

            TimeStatistics.StopClock( 1 );

            // create a plot base on signal
            PloterElement plot = new PloterElement( signal );
            plot.Position.X = 600;
            plot.Position.Y = 50;
            plot.Origin = new FxVector2f(10, 100);
            plot.FitPlots();

            // add the signal to the same plot
            plot.AddPlot( convResultFFT, PlotType.Lines, Color.RoyalBlue );
            //plot.AddPlot( convResultDFT, PlotType.Lines, Color.MistyRose );

            // add the signal to canva
            Signal_Canva.AddElements( plot );

            // add text for the signal plot
            TextElement text = new TextElement( "Conv Signal:" );
            text.Position.X = 610;
            text.Position.Y = 10;

            // add the text to canva
            Signal_Canva.AddElements( text );
        }
Esempio n. 5
0
        private void button5_Click( object sender, EventArgs e )
        {
            // calc the DFT of the signal
            //SignalTools.DFT_F( dftReal, dftImag, true, out re_signal, out dftImag );
            SignalTools.FFT_Safe_F( dftReal, dftImag, true, out re_signal, out dftImag );

            // create a plot base on signal
            PloterElement plot = new PloterElement( re_signal );
            plot.Position.X = 600;
            plot.Position.Y = 50;
            plot.Origin = new FxVector2f(10, 100);
            plot.FitPlots();

            // add the signal to canva
            Signal_Canva.AddElements( plot );

            // add text for the signal plot
            TextElement text = new TextElement( "Recostructed Signal:" );
            text.Position.X = 610;
            text.Position.Y = 10;

            // add the text to canva
            Signal_Canva.AddElements( text );
        }
Esempio n. 6
0
        private void button4_Click( object sender, EventArgs e )
        {
            // init the signal
            signal = new FxMaths.Vector.FxVectorF( 1024, new Fx1DGeneratorF( SignalGenerator ), 0.1f );

            // create a plot base on signal
            PloterElement plot = new PloterElement( signal );
            plot.Position.X = 0;
            plot.Position.Y = 50;
            plot.Origin = new FxVector2f(10, 100);
            plot.FitPlots();

            // add the signal to canva
            Signal_Canva.AddElements( plot );

            // add text for the signal plot
            TextElement text= new TextElement( "Signal Plot:" );
            text.Position.X = 10;
            text.Position.Y = 10;

            // add the text to canva
            Signal_Canva.AddElements( text );
        }
Esempio n. 7
0
        private void button3_Click( object sender, EventArgs e )
        {
            // calc the DFT of the signal
            //SignalTools.DFT_F( signal, new FxVectorF( signal.Size ), true, out dftReal, out dftImag );
            SignalTools.FFT_Safe_F( signal, new FxVectorF( signal.Size ), true, out dftReal, out dftImag );

            // create a plot base on real part of DFT
            PloterElement plotDFT_Real = new PloterElement( dftReal );
            plotDFT_Real.Position.X = 0;
            plotDFT_Real.Position.Y = 450;
            plotDFT_Real.Origin = new FxVector2f(10, 100);
            plotDFT_Real.FitPlots();

            // add the signal to canva
            Signal_Canva.AddElements( plotDFT_Real );

            // add text for the signal plot
            TextElement text= new TextElement( "FFT Real:" );
            text.Position.X = 10;
            text.Position.Y = 400;

            // add the text to canva
            Signal_Canva.AddElements( text );

            // ----------------------------------------------------------------------------------------------- //

            // create a plot base on  imag part of DFT
            PloterElement plotDFT_Imag = new PloterElement( dftImag );
            plotDFT_Imag.Position.X = 600;
            plotDFT_Imag.Position.Y = 450;
            plotDFT_Imag.Origin = new FxVector2f(10, 100);
            plotDFT_Imag.FitPlots();

            // add the signal to canva
            Signal_Canva.AddElements( plotDFT_Imag );

            // add text for the signal plot
            text = new TextElement( "FFT Imag:" );
            text.Position.X = 610;
            text.Position.Y = 400;

            // add the text to canva
            Signal_Canva.AddElements( text );
        }
Esempio n. 8
0
        private void button13_Click( object sender, EventArgs e )
        {
            // process the white noise data with the dsp
            if ( wn != null ) {

                tmpWn = new FxVectorF( wn.Size );

                // create the signal spectrum graphs
                if ( plot_signal_spectrum == null ) {

                    power = new FxVectorF( 256 );

                    #region Plot Creation

                    signal_spectrum = new FxVectorF( 256 );

                    // insert the plot of the time filter
                    filterPlot = new PloterElement( signal_spectrum );
                    filterPlot.Position.X = 0;
                    filterPlot.Position.Y = 410;
                    filterPlot.Origin = new FxVector2f(10, 100);
                    filterPlot.FitPlots();
                    canvas_audio.AddElements( filterPlot );

                    // create the plot for the spectrum
                    plot_signal_spectrum = new PloterElement( signal_spectrum );
                    plot_signal_spectrum.Position.X = 0;
                    plot_signal_spectrum.Position.Y = 10;
                    plot_signal_spectrum.Origin = new FxVector2f(10, 100);
                    plot_signal_spectrum.FitPlots();
                    plot_signal_spectrum.AddPlot( signal_spectrum, PlotType.Lines, Color.Aqua );

                    // add the signal to canva
                    canvas_audio.AddElements( plot_signal_spectrum );

                    // create the plot for the spectrum
                    plot_signal_spectrum_original = new PloterElement( signal_spectrum );
                    plot_signal_spectrum_original.Position.X = 600;
                    plot_signal_spectrum_original.Position.Y = 10;
                    plot_signal_spectrum_original.Origin = new FxVector2f(10, 100);
                    plot_signal_spectrum_original.FitPlots();

                    // add the signal to canva
                    canvas_audio.AddElements( plot_signal_spectrum_original );

                    // create the plot for the spectrum
                    plot_filter_spectrum = new PloterElement( signal_spectrum );
                    plot_filter_spectrum.Position.X = 600;
                    plot_filter_spectrum.Position.Y = 410;
                    plot_filter_spectrum.Origin = new FxVector2f(10, 100);
                    plot_filter_spectrum.FitPlots();

                    // add the signal to canva
                    canvas_audio.AddElements( plot_filter_spectrum );
                    #endregion

                    // add filter
                    UpdateFilter( BiQuadFilter.BandPassFilterConstantPeakGain( 44100, 20000, 0.5f ) );

                }

                if ( this.fil != null ) {
                    // use the filter directly
                    this.fil.Transform( wn, tmpWn );
                }

                FxVectorF tmpImag,tmpReal;

                // calc spectrum
                int mod = (int)Math.Ceiling( tmpWn.Size / ( (double)power.Size * 2 ) );

                // ===============================================================================================

                if ( ShowOutputAudioSpectrum ) {
                    power.SetValue( 0.0f );
                    FxVectorF local=tmpWn;
                    if ( Math.Pow( 2, Math.Floor( Math.Log( local.Size, 2 ) ) ) != local.Size ) {
                        int newSize;

                        // calc the size of log2
                        int sizeLog2 = (int)Math.Floor( Math.Log( local.Size, 2 ) ) - 1;

                        // calc the new size
                        newSize = (int)Math.Pow( 2, sizeLog2 );
                        if ( newSize < 512 )
                            newSize = 512;

                        local = tmpWn.GetSubVector( 0, newSize ) as FxVectorF;
                    }

                    mod = (int)Math.Ceiling( local.Size / ( (double)power.Size * 2 ) );

                    // calc the fft
                    SignalTools.FFT_F( local, null, true, out tmpReal, out tmpImag );

                    // pass all the data in form of blocks
                    for ( int i = 0; i < mod; i++ ) {
                        for ( int j = 0; j < power.Size; j++ ) {
                            power[j] += (float)( Math.Sqrt( tmpReal[j * mod + i] * tmpReal[j * mod + i] + tmpImag[j * mod + i] * tmpImag[j * mod + i] ) );
                        }
                    }

                    // normalize the result
                    power.Divide( power.Max() );

                    // refresh the plot
                    plot_signal_spectrum.RefreshPlot( power, 0 );
                    plot_signal_spectrum.FitPlots();

                    // redraw canvas if we are not going to show output spectrum
                    if ( !ShowInputAudioSpectrum )
                        canvas_audio.ReDraw();
                }

                // ===============================================================================================

                if ( ShowInputAudioSpectrum ) {
                    // calc spectrum

                    // reset the power
                    power.SetValue( 0.0f );
                    FxVectorF local=wn;

                    if ( Math.Pow( 2, Math.Floor( Math.Log( local.Size, 2 ) ) ) != local.Size ) {
                        int newSize;

                        // calc the size of log2
                        int sizeLog2 = (int)Math.Floor( Math.Log( local.Size, 2 ) ) - 1;

                        // calc the new size
                        newSize = (int)Math.Pow( 2, sizeLog2 );
                        if ( newSize < 512 )
                            newSize = 512;

                        local = wn.GetSubVector( 0, newSize ) as FxVectorF;
                    }

                    mod = (int)Math.Ceiling( local.Size / ( (double)power.Size * 2 ) );

                    // calc the fft
                    SignalTools.FFT_Safe_F( local, null, true, out tmpReal, out tmpImag );

                    // pass all the data in form of blocks
                    for ( int i = 0; i < mod; i++ ) {
                        for ( int j = 0; j < power.Size; j++ ) {
                            power[j] += (float)( Math.Sqrt( tmpReal[j * mod + i] * tmpReal[j * mod + i] + tmpImag[j * mod + i] * tmpImag[j * mod + i] ) );
                        }

                    }

                    // normalize the result
                    power.Divide( power.Max() );

                    // refresh the plot
                    plot_signal_spectrum_original.RefreshPlot( power, 0 );
                    plot_signal_spectrum_original.FitPlots();

                    // redraw canvas
                    canvas_audio.ReDraw();
                }
            }
        }