コード例 #1
0
        public static void DrawSonogram(BaseSonogram sonogram, string path, double[] array1, double[] array2, List <double[]> scores)
        {
            Log.WriteLine("# Draw image of sonogram.");
            bool doHighlightSubband = false; bool add1kHzLines = true;
            //sonogram.FramesPerSecond = 1 / sonogram.FrameOffset;
            int length = sonogram.FrameCount;

            int maxIndex1 = DataTools.GetMaxIndex(array1);
            int maxIndex2 = DataTools.GetMaxIndex(array2);

            using (System.Drawing.Image img = sonogram.GetImage(doHighlightSubband, add1kHzLines))
                using (Image_MultiTrack image = new Image_MultiTrack(img))
                {
                    //img.Save(@"C:\SensorNetworks\WavFiles\temp1\testimage1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                    image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));
                    image.AddTrack(ImageTrack.GetScoreTrack(DataTools.ScaleArray(array1, length), 0.0, array1[maxIndex1], 5));
                    image.AddTrack(ImageTrack.GetScoreTrack(DataTools.ScaleArray(array2, length), 0.0, array2[maxIndex2], 0.5));
                    for (int i = 0; i < scores.Count; i++)
                    {
                        int    maxIndex = DataTools.GetMaxIndex(scores[i]);
                        double max      = scores[i][maxIndex];
                        if (max <= 0.0)
                        {
                            max = 1.0;
                        }
                        image.AddTrack(ImageTrack.GetScoreTrack(DataTools.ScaleArray(scores[i], length), 0.0, max, 0.1));
                    }
                    image.Save(path);
                }// using
        }
コード例 #2
0
        static Image DrawSonogram(BaseSonogram sonogram, double[,] hits, double[] scores, List <AcousticEvent> predictedEvents, double eventThreshold)
        {
            Image_MultiTrack image = new Image_MultiTrack(sonogram.GetImage());

            //System.Drawing.Image img = sonogram.GetImage(doHighlightSubband, add1kHzLines);
            //img.Save(@"C:\SensorNetworks\temp\testimage1.png", System.Drawing.Imaging.ImageFormat.Png);

            //Image_MultiTrack image = new Image_MultiTrack(img);
            image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));
            image.AddTrack(ImageTrack.GetSegmentationTrack(sonogram));
            if (scores != null)
            {
                image.AddTrack(ImageTrack.GetScoreTrack(scores, 0.0, 0.5, eventThreshold));
            }
            //if (hits != null) image.OverlayRedTransparency(hits);
            if (hits != null)
            {
                image.OverlayRainbowTransparency(hits);
            }
            if (predictedEvents.Count > 0)
            {
                image.AddEvents(predictedEvents, sonogram.NyquistFrequency, sonogram.Configuration.FreqBinCount, sonogram.FramesPerSecond);
            }
            return(image.GetImage());
        } //DrawSonogram()
コード例 #3
0
        } // CreateScorePlots()

        static Image DrawSonogram(BaseSonogram sonogram, double[,] hits, List <Plot> plots, List <AcousticEvent> predictedEvents)
        {
            bool             doHighlightSubband = false; bool add1kHzLines = false;
            Image_MultiTrack image = new Image_MultiTrack(sonogram.GetImage(doHighlightSubband, add1kHzLines));

            //System.Drawing.Image img = sonogram.GetImage(doHighlightSubband, add1kHzLines);
            //img.Save(@"C:\SensorNetworks\temp\testimage1.png", System.Drawing.Imaging.ImageFormat.Png);

            //Image_MultiTrack image = new Image_MultiTrack(img);
            image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));
            image.AddTrack(ImageTrack.GetSegmentationTrack(sonogram));
            if (plots != null)
            {
                foreach (Plot plot in plots)
                {
                    image.AddTrack(ImageTrack.GetNamedScoreTrack(plot.data, 0.0, 1.0, plot.threshold, plot.title));
                }
            }
            //if (hits != null) image.OverlayRedTransparency(hits);
            if (hits != null)
            {
                image.OverlayRedMatrix(hits, 1.0);
            }
            if (predictedEvents.Count > 0)
            {
                image.AddEvents(predictedEvents, sonogram.NyquistFrequency, sonogram.Configuration.FreqBinCount, sonogram.FramesPerSecond);
            }
            return(image.GetImage());
        } //DrawSonogram()
コード例 #4
0
        public static void DrawSonogram(BaseSonogram sonogram, FileInfo path, List <AcousticEvent> predictedEvents, List <double> thresholdList, List <double[]> scoresList)
        {
            Log.WriteLine("# Start to draw image of sonogram.");
            bool doHighlightSubband = false; bool add1kHzLines = true;

            // DO NOT NEED FOLLOWING TWO LINES BECAUSE HAVE CHANGED CODE TO ENSURE THAT ALL TEMPLATES USE THE SAME FRAME OVERLAP
            // AND THEREFORE ALL SCORE ARRAYS ARE OF THE SAME LENGTH FOR GIVEN RECORDING
            //Log.WriteLine("# Convert score arrays to correct length for display = {0}.", sonogram.FrameCount);
            //scoresList = ConvertScoreArrayLengths(scoresList, sonogram.FrameCount);

            // DO NOT NEED FOLLOWING LINES BECAUSE HAVE CHANGED CODE TO ENSURE THAT ALL TEMPLATES USE THE SAME FRAME OVERLAP
            // AND THEREFORE ALL SCORE ARRAYS ARE OF THE SAME LENGTH FOR GIVEN RECORDING
            // Edit the events because they will not necessarily correspond to the timescale of the display image
            //Log.WriteLine("# Convert time scale of events.");
            //foreach (AcousticEvent ae in predictedEvents)
            //{
            //    Log.WriteLine("# Event frame= {0} to {1}.", ae.oblong.RowTop, ae.oblong.RowBottom);
            //    ae.FrameOffset = sonogram.FrameOffset;
            //    ae.FramesPerSecond = sonogram.FramesPerSecond;
            //    ae.oblong = AcousticEvent.ConvertEvent2Oblong(ae);
            //    Log.WriteLine("# Event time = {0:f2} to {1:f2}.", ae.StartTime, ae.EndTime);
            //    Log.WriteLine("# Event frame= {0} to {1}.", ae.oblong.RowTop, ae.oblong.RowBottom);
            //}

            using (System.Drawing.Image img = sonogram.GetImage(doHighlightSubband, add1kHzLines))
                using (Image_MultiTrack image = new Image_MultiTrack(img))
                {
                    //img.Save(@"C:\SensorNetworks\WavFiles\temp1\testimage1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                    image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));

                    // Add in score tracks
                    for (int s = 0; s < scoresList.Count; s++)
                    {
                        if (scoresList[s] == null)
                        {
                            continue;
                        }
                        double[] scores = scoresList[s];

                        double normMax = thresholdList[s] * 4; //so normalised eventThreshold = 0.25
                        for (int i = 0; i < scores.Length; i++)
                        {
                            scores[i] /= normMax;
                            if (scores[i] > 1.0)
                            {
                                scores[i] = 1.0;
                            }
                            if (scores[i] < 0.0)
                            {
                                scores[i] = 0.0;
                            }
                        }

                        image.AddTrack(ImageTrack.GetScoreTrack(scores, 0.0, 1.0, 0.25));
                    } //end adding in score tracks

                    image.AddEvents(predictedEvents, sonogram.NyquistFrequency, sonogram.Configuration.FreqBinCount, sonogram.FramesPerSecond);
                    image.Save(path.FullName);
                }// using
        } // DrawSonogram()
コード例 #5
0
        public static void DrawSonogram(BaseSonogram sonogram, string path, List <AcousticEvent> predictedEvents, double threshold, double[] scores)
        {
            Log.WriteLine("# Start to draw image of sonogram.");
            bool doHighlightSubband = false; bool add1kHzLines = true;

            using (System.Drawing.Image img = sonogram.GetImage(doHighlightSubband, add1kHzLines))
                using (Image_MultiTrack image = new Image_MultiTrack(img))
                {
                    //img.Save(@"C:\SensorNetworks\WavFiles\temp1\testimage1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                    image.AddTrack(Image_Track.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));
                    if (scores != null)
                    {
                        double normMax = threshold * 4; //so normalised eventThreshold = 0.25
                        for (int i = 0; i < scores.Length; i++)
                        {
                            scores[i] /= normMax;
                            if (scores[i] > 1.0)
                            {
                                scores[i] = 1.0;
                            }
                            if (scores[i] < 0.0)
                            {
                                scores[i] = 0.0;
                            }
                        }

                        image.AddTrack(Image_Track.GetScoreTrack(scores, 0.0, 1.0, 0.25));
                    }
                    image.AddEvents(predictedEvents);
                    image.Save(path);
                }
        }
コード例 #6
0
        private static Image DrawSonogram(BaseSonogram sonogram, double[,] hits, List <Plot> scores, List <Track> tracks)
        {
            Image_MultiTrack image = new Image_MultiTrack(sonogram.GetImage());

            image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));
            image.AddTrack(ImageTrack.GetSegmentationTrack(sonogram));

            if (scores != null)
            {
                foreach (Plot plot in scores)
                {
                    // assumes data normalized in 0,1
                    image.AddTrack(ImageTrack.GetNamedScoreTrack(plot.data, 0.0, 1.0, plot.threshold, plot.title));
                }
            }

            if (tracks != null)
            {
                image.AddTracks(tracks, sonogram.FramesPerSecond, sonogram.FBinWidth);
            }

            if (hits != null)
            {
                image.OverlayRedMatrix(hits, 1.0);
            }

            return(image.GetImage());
        }
コード例 #7
0
        }//end DetectGratingEvents()

        static Image DrawSonogram(BaseSonogram sonogram, double[,] hits, double[] scores, List <AcousticEvent> predictedEvents, double eventThreshold)
        {
            //Log.WriteLine("# Start to draw image of sonogram.");
            bool             doHighlightSubband = false; bool add1kHzLines = true;
            double           maxScore = 32.0; //assume max period = 64.
            Image_MultiTrack image = new Image_MultiTrack(sonogram.GetImage(doHighlightSubband, add1kHzLines));

            //System.Drawing.Image img = sonogram.GetImage(doHighlightSubband, add1kHzLines);
            //img.Save(@"C:\SensorNetworks\temp\testimage1.png", System.Drawing.Imaging.ImageFormat.Png);

            //Image_MultiTrack image = new Image_MultiTrack(img);
            image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));
            image.AddTrack(ImageTrack.GetSegmentationTrack(sonogram));
            if (scores != null)
            {
                image.AddTrack(ImageTrack.GetScoreTrack(scores, 0.0, 1.0, eventThreshold));
            }
            if (hits != null)
            {
                image.OverlayRedMatrix(hits, maxScore);
            }
            if (predictedEvents.Count > 0)
            {
                image.AddEvents(predictedEvents, sonogram.NyquistFrequency, sonogram.Configuration.FreqBinCount, sonogram.FramesPerSecond);
            }
            return(image.GetImage());
        } //DrawSonogram()
コード例 #8
0
ファイル: AED.cs プロジェクト: Gwae1/audio-analysis
        public static Image DrawSonogram(BaseSonogram sonogram, IEnumerable <EventCommon> events)
        {
            var image = new Image_MultiTrack(sonogram.GetImage(false, true, doMelScale: false));

            image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));

            ////image.AddTrack(ImageTrack.GetWavEnvelopeTrack(sonogram, image.sonogramImage.Width));
            image.AddTrack(ImageTrack.GetSegmentationTrack(sonogram));

            //############################################################################################ TODO TODO
            //convert blob events to acoustic events for drawing purposes
            var aeEvents = new List <AcousticEvent>();

            foreach (var be in events)
            {
                aeEvents.Add(EventConverters.ConvertSpectralEventToAcousticEvent((SpectralEvent)be));
            }

            image.AddEvents(
                aeEvents,
                sonogram.NyquistFrequency,
                sonogram.Configuration.FreqBinCount,
                sonogram.FramesPerSecond);

            return(image.GetImage());
        }
コード例 #9
0
        public static void Execute(Arguments arguments)
        {
            MainEntry.WarnIfDeveloperEntryUsed();

            if (arguments == null)
            {
                throw new NoDeveloperMethodException();
            }

            // READ PARAMETER VALUES FROM INI FILE
            var config    = ConfigFile.Deserialize(arguments.Config);
            var aedConfig = Aed.GetAedParametersFromConfigFileOrDefaults(config);

            var input = arguments.Source;
            Tuple <BaseSonogram, List <AcousticEvent> > result = Detect(input, aedConfig, Default.eprNormalisedMinScore, TimeSpan.Zero);
            List <AcousticEvent> eprEvents = result.Item2;

            eprEvents.Sort((ae1, ae2) => ae1.TimeStart.CompareTo(ae2.TimeStart));

            LoggedConsole.WriteLine();
            foreach (AcousticEvent ae in eprEvents)
            {
                LoggedConsole.WriteLine(ae.TimeStart + "," + ae.EventDurationSeconds + "," + ae.LowFrequencyHertz + "," + ae.HighFrequencyHertz);
            }

            LoggedConsole.WriteLine();
            string       outputFolder = arguments.Config.ToFileInfo().DirectoryName;
            string       wavFilePath  = input.FullName;
            BaseSonogram sonogram     = result.Item1;
            string       imagePath    = Path.Combine(outputFolder, Path.GetFileNameWithoutExtension(wavFilePath) + ".png");
            var          image        = Aed.DrawSonogram(sonogram, eprEvents.ConvertAcousticEventsToSpectralEvents());

            image.Save(imagePath);
        }
コード例 #10
0
        }//end CaneToadRecogniser

        public static void DrawSonogram(BaseSonogram sonogram, string path, double[,] hits, double[] scores,
                                        List <AcousticEvent> predictedEvents, double eventThreshold, double[] intensity)
        {
            Log.WriteLine("# Start to draw image of sonogram.");
            bool doHighlightSubband = false;
            bool add1kHzLines       = true;

            //double maxScore = 50.0; //assumed max posisble oscillations per second

            using (System.Drawing.Image img = sonogram.GetImage(doHighlightSubband, add1kHzLines, doMelScale: false))
                using (Image_MultiTrack image = new Image_MultiTrack(img))
                {
                    //img.Save(@"C:\SensorNetworks\WavFiles\temp1\testimage1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                    image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));
                    image.AddTrack(ImageTrack.GetSegmentationTrack(sonogram));
                    image.AddTrack(ImageTrack.GetScoreTrack(scores, 0.0, 1.0, eventThreshold));

                    //double maxScore = 100.0;
                    //image.AddSuperimposedMatrix(hits, maxScore);
                    if (intensity != null)
                    {
                        double min, max;
                        DataTools.MinMax(intensity, out min, out max);
                        double threshold_norm = eventThreshold / max; //min = 0.0;
                        intensity = DataTools.normalise(intensity);
                        image.AddTrack(ImageTrack.GetScoreTrack(intensity, 0.0, 1.0, eventThreshold));
                    }

                    image.AddEvents(predictedEvents, sonogram.NyquistFrequency, sonogram.Configuration.FreqBinCount, sonogram.FramesPerSecond);
                    image.Save(path);
                }
        }
コード例 #11
0
        /// <summary>
        /// Performs Spectral Peak Tracking on a recording
        /// Returns a matrix derived from the sonogram
        /// </summary>
        /// <param name="sonogram">the sonogram</param>
        /// <param name="intensityThreshold">Intensity threshold in decibels above backgorund</param>
        /// <param name="smallLengthThreshold">remove event swhose length is less than this threshold</param>
        /// <returns></returns>
        public static Tuple <double[, ]> doSPT(BaseSonogram sonogram, double intensityThreshold, int smallLengthThreshold)
        {
            // Sonograms in Matlab (which F# AED was modelled on) are orientated the opposite way
            var m = MatrixModule.transpose(MatrixModule.ofArray2D(sonogram.Data));

            //Log.WriteLine("Wiener filter start");
            var w = Matlab.wiener2(7, m);

            //Log.WriteLine("Wiener filter end");

            //Log.WriteLine("Remove subband mode intensities start");
            var s = AcousticEventDetection.removeSubbandModeIntensities(w);

            //Log.WriteLine("Remove subband mode intensities end");

            Log.WriteLine("SPT start");
            int nh = 3;
            var p  = SpectralPeakTrack.spt(s, intensityThreshold, nh, smallLengthThreshold);

            Log.WriteLine("SPT finished");

            var r = MatrixModule.toArray2D(MatrixModule.transpose(p));

            return(Tuple.Create(r));
        }
コード例 #12
0
        /// <summary>
        /// AN EXPERIMENTAL SPECTROGRAM - A FALSE-COLOR VERSION OF A standard scale SPECTROGRAM.
        /// </summary>
        /// <param name="dbSpectrogramData">The original data for decibel spectrogram.</param>
        /// <param name="nrSpectrogram">The noise-reduced spectrogram.</param>
        /// <param name="sourceRecordingName">Name of the source file. Required only to add label to spectrogram.</param>
        /// <returns>Image of spectrogram.</returns>
        public static Image <Rgb24> GetDecibelSpectrogram_Ridges(
            double[,] dbSpectrogramData,
            SpectrogramStandard nrSpectrogram,
            string sourceRecordingName)
        {
            // ########################### SOBEL ridge detection
            var ridgeThreshold = 3.5;
            var matrix         = ImageTools.WienerFilter(dbSpectrogramData, 3);
            var hits           = RidgeDetection.Sobel5X5RidgeDetectionExperiment(matrix, ridgeThreshold);

            // ########################### EIGEN ridge detection
            //double ridgeThreshold = 6.0;
            //double dominanceThreshold = 0.7;
            //var rotatedData = MatrixTools.MatrixRotate90Anticlockwise(dbSpectrogramData);
            //byte[,] hits = RidgeDetection.StructureTensorRidgeDetection(rotatedData, ridgeThreshold, dominanceThreshold);
            //hits = MatrixTools.MatrixRotate90Clockwise(hits);
            // ########################### EIGEN ridge detection

            var frameStep  = nrSpectrogram.Configuration.WindowStep;
            var sampleRate = nrSpectrogram.SampleRate;
            var image      = SpectrogramTools.CreateFalseColourDecibelSpectrogram(dbSpectrogramData, nrSpectrogram.Data, hits);

            image = BaseSonogram.GetImageAnnotatedWithLinearHertzScale(
                image,
                sampleRate,
                frameStep,
                $"AN EXPERIMENTAL DECIBEL SPECTROGRAM with ridges ({sourceRecordingName})",
                ImageTags[Experimental]);

            //var image = decibelSpectrogram.GetImageFullyAnnotated("DECIBEL SPECTROGRAM - with ridges");
            return(image);
        }
コード例 #13
0
        public static Image DisplayDebugImage(BaseSonogram sonogram, List <AcousticEvent> events, List <Plot> scores, double[,] hits)
        {
            bool             doHighlightSubband = false;
            bool             add1kHzLines       = true;
            Image_MultiTrack image = new Image_MultiTrack(sonogram.GetImage(doHighlightSubband, add1kHzLines, doMelScale: false));

            image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));
            if (scores != null)
            {
                foreach (Plot plot in scores)
                {
                    image.AddTrack(ImageTrack.GetNamedScoreTrack(plot.data, 0.0, 1.0, plot.threshold, plot.title)); //assumes data normalised in 0,1
                }
            }

            if (hits != null)
            {
                image.OverlayRainbowTransparency(hits);
            }

            if (events.Count > 0)
            {
                foreach (AcousticEvent ev in events) // set colour for the events
                {
                    ev.BorderColour = AcousticEvent.DefaultBorderColor;
                    ev.ScoreColour  = AcousticEvent.DefaultScoreColor;
                }

                image.AddEvents(events, sonogram.NyquistFrequency, sonogram.Configuration.FreqBinCount, sonogram.FramesPerSecond);
            }

            return(image.GetImage());
        }
コード例 #14
0
        /// <summary>
        /// Only call this method for short recordings.
        /// If accumulating data for long recordings then call the method for long recordings - i.e.
        /// double[] spectralIndex = GenerateOscillationDataAndImages(FileInfo audioSegment, Dictionary configDict, false, false).
        /// </summary>
        public static FreqVsOscillationsResult GetFreqVsOscillationsDataAndImage(BaseSonogram sonogram, string algorithmName)
        {
            double sensitivity     = DefaultSensitivityThreshold;
            int    sampleLength    = DefaultSampleLength;
            var    freqOscilMatrix = GetFrequencyByOscillationsMatrix(sonogram.Data, sensitivity, sampleLength, algorithmName);
            var    image           = GetFreqVsOscillationsImage(freqOscilMatrix, sonogram.FramesPerSecond, sonogram.FBinWidth, sampleLength, algorithmName);
            var    sourceName      = Path.GetFileNameWithoutExtension(sonogram.Configuration.SourceFName);

            // get the OSC spectral index
            // var spectralIndex = ConvertMatrix2SpectralIndexBySummingFreqColumns(freqOscilMatrix, skipNRows: 1);
            var spectralIndex = MatrixTools.GetMaximumColumnValues(freqOscilMatrix);

            if (spectralIndex == null)
            {
                throw new ArgumentNullException(nameof(spectralIndex));
            }

            // DEBUGGING
            // Add spectralIndex into the matrix because want to add it to image.
            // This is for debugging only and can comment this line
            int rowCount = freqOscilMatrix.GetLength(0);

            MatrixTools.SetRow(freqOscilMatrix, rowCount - 2, spectralIndex);

            var result = new FreqVsOscillationsResult
            {
                SourceFileName           = sourceName,
                FreqOscillationImage     = image,
                FreqOscillationData      = freqOscilMatrix,
                OscillationSpectralIndex = spectralIndex,
            };

            return(result);
        }
コード例 #15
0
        private void WriteDebugImage(
            AudioRecording recording,
            DirectoryInfo outputDirectory,
            BaseSonogram sonogram,
            List <AcousticEvent> acousticEvents,
            List <Plot> plots,
            double[,] hits)
        {
            //DEBUG IMAGE this recogniser only. MUST set false for deployment.
            bool displayDebugImage = MainEntry.InDEBUG;

            if (displayDebugImage)
            {
                Image debugImage1 = SpectrogramTools.GetSonogramPlusCharts(sonogram, acousticEvents, plots, hits);
                var   debugPath1  = outputDirectory.Combine(FilenameHelpers.AnalysisResultName(Path.GetFileNameWithoutExtension(recording.BaseName), this.Identifier, "png", "DebugSpectrogram1"));
                debugImage1.Save(debugPath1.FullName);

                // save new image with longer frame
                var sonoConfig2 = new SonogramConfig
                {
                    SourceFName   = recording.BaseName,
                    WindowSize    = 1024,
                    WindowOverlap = 0,

                    //NoiseReductionType = NoiseReductionType.NONE,
                    NoiseReductionType      = NoiseReductionType.Standard,
                    NoiseReductionParameter = 0.1,
                };
                BaseSonogram sonogram2 = new SpectrogramStandard(sonoConfig2, recording.WavReader);

                var   debugPath2  = outputDirectory.Combine(FilenameHelpers.AnalysisResultName(Path.GetFileNameWithoutExtension(recording.BaseName), this.Identifier, "png", "DebugSpectrogram2"));
                Image debugImage2 = SpectrogramTools.GetSonogramPlusCharts(sonogram2, acousticEvents, plots, null);
                debugImage2.Save(debugPath2.FullName);
            }
        }
コード例 #16
0
        public static List <AcousticEvent> ReadGroundParrotTemplateAsList(BaseSonogram sonogram)
        {
            var    timeScale  = sonogram.FrameStep;
            var    hzScale    = (int)sonogram.FBinWidth;
            int    rows       = GroundParrotTemplate1.GetLength(0);
            int    cols       = GroundParrotTemplate1.GetLength(1);
            double timeOffset = GroundParrotTemplate1[0, 0];
            var    gpTemplate = new List <AcousticEvent>();

            for (int r = 0; r < rows; r++)
            {
                int    t1 = (int)Math.Round((GroundParrotTemplate1[r, 0] - timeOffset) / timeScale);
                int    t2 = (int)Math.Round((GroundParrotTemplate1[r, 1] - timeOffset) / timeScale);
                int    f2 = (int)Math.Round(GroundParrotTemplate1[r, 2] / hzScale);
                int    f1 = (int)Math.Round(GroundParrotTemplate1[r, 3] / hzScale);
                Oblong o  = new Oblong(t1, f1, t2, f2);
                gpTemplate.Add(
                    new AcousticEvent(
                        TimeSpan.Zero,
                        o,
                        sonogram.NyquistFrequency,
                        sonogram.Configuration.FreqBinCount,
                        sonogram.FrameDuration,
                        sonogram.FrameStep,
                        sonogram.FrameCount));
            }

            return(gpTemplate);
        }
コード例 #17
0
ファイル: AED.cs プロジェクト: Gwae1/audio-analysis
        public override AnalysisResult2 Analyze <T>(AnalysisSettings analysisSettings, SegmentSettings <T> segmentSettings)
        {
            FileInfo audioFile = segmentSettings.SegmentAudioFile;

            var aedConfig = GetAedParametersFromConfigFileOrDefaults(analysisSettings.Configuration);

            var results = Detect(audioFile, aedConfig, segmentSettings.SegmentStartOffset);

            var analysisResults = new AnalysisResult2(analysisSettings, segmentSettings, results.Item2.Duration);

            analysisResults.AnalysisIdentifier = this.Identifier;
            analysisResults.Events             = results.Item1;
            BaseSonogram sonogram = results.Item3;

            if (analysisSettings.AnalysisDataSaveBehavior)
            {
                this.WriteEventsFile(segmentSettings.SegmentEventsFile, analysisResults.Events);
                analysisResults.EventsFile = segmentSettings.SegmentEventsFile;
            }

            if (analysisSettings.AnalysisDataSaveBehavior)
            {
                // noop
            }

            // save image of sonograms
            if (analysisSettings.AnalysisImageSaveBehavior.ShouldSave(analysisResults.Events.Length))
            {
                Image image = DrawSonogram(sonogram, results.Item1);
                image.Save(segmentSettings.SegmentImageFile.FullName);
                analysisResults.ImageFile = segmentSettings.SegmentImageFile;
            }

            return(analysisResults);
        }
コード例 #18
0
        } //Analysis()

        //private static System.Tuple<string[], Type[], bool[]> InitOutputTableColumns()
        //{
        //    HEADERS[0] = header_count;    COL_TYPES[0] = typeof(int); DISPLAY_COLUMN[0] = false; COMBO_WEIGHTS[0] = 0.0;
        //    HEADERS[1] = header_startMin; COL_TYPES[1] = typeof(double); DISPLAY_COLUMN[1] = false; COMBO_WEIGHTS[1] = 0.0;
        //    HEADERS[2] = header_SecondsDuration; COL_TYPES[2] = typeof(double); DISPLAY_COLUMN[2] = false; COMBO_WEIGHTS[2] = 0.0;
        //    HEADERS[3] = header_avAmpdB; COL_TYPES[3] = typeof(double); DISPLAY_COLUMN[3] = true; COMBO_WEIGHTS[3] = 0.0;
        //    HEADERS[4] = header_snrdB; COL_TYPES[4] = typeof(double); DISPLAY_COLUMN[4] = true; COMBO_WEIGHTS[4] = 0.0;
        //    HEADERS[5] = header_bgdB; COL_TYPES[5] = typeof(double); DISPLAY_COLUMN[5] = true; COMBO_WEIGHTS[5] = 0.0;
        //    HEADERS[6] = header_activity; COL_TYPES[6] = typeof(double); DISPLAY_COLUMN[6] = true; COMBO_WEIGHTS[6] = 0.0;
        //    HEADERS[7] = header_hfCover; COL_TYPES[7] = typeof(double); DISPLAY_COLUMN[7] = true; COMBO_WEIGHTS[7] = 0.0;
        //    HEADERS[8] = header_mfCover; COL_TYPES[8] = typeof(double); DISPLAY_COLUMN[8] = true; COMBO_WEIGHTS[8] = 0.0;
        //    HEADERS[9] = header_lfCover; COL_TYPES[9] = typeof(double); DISPLAY_COLUMN[9] = true; COMBO_WEIGHTS[9] = 0.0;
        //    HEADERS[10] = header_HAmpl; COL_TYPES[10] = typeof(double); DISPLAY_COLUMN[10] = true; COMBO_WEIGHTS[10] = 0.0;
        //    HEADERS[11] = header_HAvSpectrum; COL_TYPES[11] = typeof(double); DISPLAY_COLUMN[11] = true; COMBO_WEIGHTS[11] = 0.4;
        //    //HEADERS[12] = header_HVarSpectrum; COL_TYPES[12] = typeof(double); DISPLAY_COLUMN[12] = false; COMBO_WEIGHTS[12] = 0.1;
        //    return Tuple.Create(HEADERS, COL_TYPES, DISPLAY_COLUMN);
        //}

        static Image DrawSonogram(BaseSonogram sonogram, List <Plot> scores)
        {
            Dictionary <string, string> configDict      = new Dictionary <string, string>();
            List <AcousticEvent>        predictedEvents = null;
            double eventThreshold = 0.0;
            Image  image          = SpectrogramTools.Sonogram2Image(sonogram, configDict, null, scores, predictedEvents, eventThreshold);

            return(image);
        }
コード例 #19
0
        private static Image DrawSonogram(double[,] data, TimeSpan xInterval, TimeSpan xAxisPixelDuration, int nyquist, int herzInterval, string title)
        {
            var image = ImageTools.GetMatrixImage(data);

            var titleBar      = BaseSonogram.DrawTitleBarOfGrayScaleSpectrogram(title, image.Width);
            var minuteOffset  = TimeSpan.Zero;
            var labelInterval = TimeSpan.FromSeconds(5);

            image = BaseSonogram.FrameSonogram(image, titleBar, minuteOffset, xInterval, xAxisPixelDuration, labelInterval, nyquist, herzInterval);
            return(image);
        }
コード例 #20
0
        protected virtual Image DrawSonogram(
            BaseSonogram sonogram,
            double[,] hits,
            List <Plot> scores,
            List <AcousticEvent> predictedEvents,
            double eventThreshold)
        {
            var image = SpectrogramTools.GetSonogramPlusCharts(sonogram, predictedEvents, scores, hits);

            return(image);
        }
コード例 #21
0
ファイル: AED.cs プロジェクト: Gwae1/audio-analysis
        public static EventCommon[] CallAed(BaseSonogram sonogram, AedConfiguration aedConfiguration, TimeSpan segmentStartOffset, TimeSpan segmentDuration)
        {
            Log.Info("AED start");

            var aedOptions = new AedOptions(sonogram.Configuration.NyquistFreq)
            {
                IntensityThreshold = aedConfiguration.IntensityThreshold,
                SmallAreaThreshold = aedConfiguration.SmallAreaThreshold,
                DoNoiseRemoval     = aedConfiguration.NoiseReductionType == NoiseReductionType.None,
            };

            if (aedConfiguration.BandpassMinimum.HasValue && aedConfiguration.BandpassMaximum.HasValue)
            {
                var bandPassFilter =
                    Tuple.Create(
                        (double)aedConfiguration.BandpassMinimum.Value,
                        (double)aedConfiguration.BandpassMaximum.Value);
                aedOptions.BandPassFilter = new FSharpOption <Tuple <double, double> >(bandPassFilter);
            }

            IEnumerable <Oblong> oblongs = AcousticEventDetection.detectEvents(aedOptions, sonogram.Data);

            Log.Info("AED finished");

            var unitConverters = new UnitConverters(
                segmentStartOffset.TotalSeconds,
                sonogram.SampleRate,
                sonogram.Configuration.WindowSize,
                sonogram.Configuration.WindowOverlap);

            var events = oblongs.Select(
                o =>
            {
                var blob = new BlobEvent()
                {
                    SegmentDurationSeconds = segmentDuration.TotalSeconds,
                    Name = "AED Event",
                };

                unitConverters.SetBounds(blob, o);

                if (aedConfiguration.IncludeHitElementsInOutput)
                {
                    o.HitElements
                    .Select(p => unitConverters.ConvertPointToSpectralPoint(p, 1.0))
                    .ForEach(sp => blob.Points.Add(sp));
                }

                return(blob);
            });

            return(events.ToArray());
        }
コード例 #22
0
        public void CropTrack(BaseSonogram sonogram, double threshold)
        {
            //int length = sonogram.FrameCount;
            int binID = (int)this.AverageBin;

            double[] freqBin = MatrixTools.GetColumn(sonogram.Data, binID);

            double[] subArray = DataTools.Subarray(freqBin, this.StartFrame, this.Length);
            int[]    bounds   = DataTools.Peaks_CropLowAmplitude(subArray, threshold);

            this.EndFrame    = this.StartFrame + bounds[1];
            this.StartFrame += bounds[0];
        }
コード例 #23
0
        public override AnalysisResult2 Analyze <T>(AnalysisSettings analysisSettings, SegmentSettings <T> segmentSettings)
        {
            FileInfo audioFile = segmentSettings.SegmentAudioFile;

            /* ###################################################################### */
            Dictionary <string, string> configuration = analysisSettings.Configuration.ToDictionary();
            KoalaMaleResults            results       = Analysis(audioFile, configuration, segmentSettings.SegmentStartOffset);

            /* ###################################################################### */
            BaseSonogram sonogram = results.Sonogram;

            double[,] hits = results.Hits;
            Plot scores = results.Plot;

            var analysisResults = new AnalysisResult2(analysisSettings, segmentSettings, results.RecordingtDuration)
            {
                AnalysisIdentifier = this.Identifier,
            };

            analysisResults.Events = results.Events.ToArray();

            if (analysisSettings.AnalysisDataSaveBehavior)
            {
                this.WriteEventsFile(segmentSettings.SegmentEventsFile, analysisResults.Events);
                analysisResults.EventsFile = segmentSettings.SegmentEventsFile;
            }

            if (analysisSettings.AnalysisDataSaveBehavior)
            {
                TimeSpan unitTime = TimeSpan.FromMinutes(1.0);
                analysisResults.SummaryIndices = this.ConvertEventsToSummaryIndices(
                    analysisResults.Events,
                    unitTime,
                    analysisResults.SegmentAudioDuration,
                    0);

                this.WriteSummaryIndicesFile(segmentSettings.SegmentSummaryIndicesFile, analysisResults.SummaryIndices);
            }

            if (analysisSettings.AnalysisImageSaveBehavior.ShouldSave(analysisResults.Events.Length))
            {
                string       imagePath      = segmentSettings.SegmentImageFile.FullName;
                const double EventThreshold = 0.1;
                Image        image          = DrawSonogram(sonogram, hits, scores, results.Events, EventThreshold);
                image.Save(imagePath, ImageFormat.Png);
                analysisResults.ImageFile = segmentSettings.SegmentImageFile;
            }

            return(analysisResults);
        }
コード例 #24
0
        /// <summary>
        /// draw the spectrogram with red marks indicating the local spectral peaks.
        /// </summary>
        public static Image DrawSonogram(BaseSonogram sonogram, double[,] hits)
        {
            Image_MultiTrack image = new Image_MultiTrack(sonogram.GetImage());

            image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));
            image.AddTrack(ImageTrack.GetSegmentationTrack(sonogram));

            if (hits != null)
            {
                image.OverlayRedMatrix(hits, 1.0);
            }

            return(image.GetImage());
        }
コード例 #25
0
        public void Setup()
        {
            this.outputDirectory = PathHelper.GetTempDir();
            this.audioRecording  = new AudioRecording(PathHelper.ResolveAsset("Recordings", "20190115_Bellingen_Feeding_minute6_OneChannel22050.wav"));
            var sonoConfig = new SonogramConfig
            {
                WindowSize              = 512,
                NoiseReductionType      = NoiseReductionType.Standard,
                NoiseReductionParameter = 3.0,
                WindowOverlap           = 0.0,
            };

            this.sonogram = new SpectrogramStandard(sonoConfig, this.audioRecording.WavReader);
        }
コード例 #26
0
ファイル: AED.cs プロジェクト: ninascarpelli/audio-analysis
        public static AcousticEvent[] CallAed(BaseSonogram sonogram, AedConfiguration aedConfiguration, TimeSpan segmentStartOffset, TimeSpan segmentDuration)
        {
            Log.Info("AED start");

            var aedOptions = new AedOptions(sonogram.Configuration.NyquistFreq)
            {
                IntensityThreshold = aedConfiguration.IntensityThreshold,
                SmallAreaThreshold = aedConfiguration.SmallAreaThreshold,
                DoNoiseRemoval     = aedConfiguration.NoiseReductionType == NoiseReductionType.None,
            };

            if (aedConfiguration.BandpassMinimum.HasValue && aedConfiguration.BandpassMaximum.HasValue)
            {
                var bandPassFilter =
                    Tuple.Create(
                        (double)aedConfiguration.BandpassMinimum.Value,
                        (double)aedConfiguration.BandpassMaximum.Value);
                aedOptions.BandPassFilter = new FSharpOption <Tuple <double, double> >(bandPassFilter);
            }

            IEnumerable <Oblong> oblongs = AcousticEventDetection.detectEvents(aedOptions, sonogram.Data);

            Log.Info("AED finished");

            var events = oblongs.Select(
                o =>
            {
                if (!aedConfiguration.IncludeHitElementsInOutput)
                {
                    o.HitElements = null;
                }

                return(new AcousticEvent(
                           segmentStartOffset,
                           o,
                           sonogram.NyquistFrequency,
                           sonogram.Configuration.FreqBinCount,
                           sonogram.FrameDuration,
                           sonogram.FrameStep,
                           sonogram.FrameCount)
                {
                    BorderColour = aedConfiguration.AedEventColor,
                    HitColour = aedConfiguration.AedHitColor,
                    SegmentDurationSeconds = segmentDuration.TotalSeconds,
                });
            }).ToArray();

            return(events);
        }
コード例 #27
0
        public static double[] DetectEPR(List <AcousticEvent> template, BaseSonogram sonogram, double[] odScores, double odThreshold)
        {
            int length = sonogram.FrameCount;

            double[] eprScores      = new double[length];
            Oblong   ob1            = template[0].Oblong;                  // the first chirp in template
            Oblong   obZ            = template[template.Count - 1].Oblong; // the last  chirp in template
            int      templateLength = obZ.RowBottom;

            for (int frame = 0; frame < length - templateLength; frame++)
            {
                if (odScores[frame] < odThreshold)
                {
                    continue;
                }

                // get best freq band and max score for the first rectangle.
                double maxScore      = -double.MaxValue;
                int    freqBinOffset = 0;
                for (int bin = -5; bin < 15; bin++)
                {
                    Oblong ob    = new Oblong(ob1.RowTop + frame, ob1.ColumnLeft + bin, ob1.RowBottom + frame, ob1.ColumnRight + bin);
                    double score = GetLocationScore(sonogram, ob);
                    if (score > maxScore)
                    {
                        maxScore      = score;
                        freqBinOffset = bin;
                    }
                }

                //if location score exceeds threshold of 6 dB then get remaining scores.
                if (maxScore < 6.0)
                {
                    continue;
                }

                foreach (AcousticEvent ae in template)
                {
                    Oblong ob    = new Oblong(ae.Oblong.RowTop + frame, ae.Oblong.ColumnLeft + freqBinOffset, ae.Oblong.RowBottom + frame, ae.Oblong.ColumnRight + freqBinOffset);
                    double score = GetLocationScore(sonogram, ob);
                    eprScores[frame] += score;
                }

                eprScores[frame] /= template.Count;
            }

            return(eprScores);
        }
コード例 #28
0
        public override AnalysisResult2 Analyze <T>(AnalysisSettings analysisSettings, SegmentSettings <T> segmentSettings)
        {
            FileInfo audioFile = segmentSettings.SegmentAudioFile;

            // execute actual analysis
            dynamic configuration = analysisSettings.Configuration;
            var     recording     = new AudioRecording(audioFile.FullName);

            Log.Debug("Canetoad sample rate:" + recording.SampleRate);

            RecognizerResults results = Analysis(recording, configuration, segmentSettings.SegmentStartOffset, segmentSettings.SegmentOutputDirectory);

            var analysisResults = new AnalysisResult2(analysisSettings, segmentSettings, recording.Duration);

            BaseSonogram sonogram = results.Sonogram;

            double[,] hits = results.Hits;
            Plot scores = results.Plots.First();
            List <AcousticEvent> predictedEvents = results.Events;

            analysisResults.Events = predictedEvents.ToArray();

            if (analysisSettings.AnalysisDataSaveBehavior)
            {
                this.WriteEventsFile(segmentSettings.SegmentEventsFile, analysisResults.Events);
                analysisResults.EventsFile = segmentSettings.SegmentEventsFile;
            }

            if (analysisSettings.AnalysisDataSaveBehavior)
            {
                var unitTime = TimeSpan.FromMinutes(1.0);
                analysisResults.SummaryIndices = this.ConvertEventsToSummaryIndices(analysisResults.Events, unitTime, analysisResults.SegmentAudioDuration, 0);

                analysisResults.SummaryIndicesFile = segmentSettings.SegmentSummaryIndicesFile;
                this.WriteSummaryIndicesFile(segmentSettings.SegmentSummaryIndicesFile, analysisResults.SummaryIndices);
            }

            if (analysisSettings.AnalysisImageSaveBehavior.ShouldSave(analysisResults.Events.Length))
            {
                string       imagePath      = segmentSettings.SegmentImageFile.FullName;
                const double EventThreshold = 0.1;
                Image        image          = DrawSonogram(sonogram, hits, scores, predictedEvents, EventThreshold);
                image.Save(imagePath, ImageFormat.Png);
                analysisResults.ImageFile = segmentSettings.SegmentImageFile;
            }

            return(analysisResults);
        }
コード例 #29
0
ファイル: AED.cs プロジェクト: gitter-badger/audio-analysis
        public static Image DrawSonogram(BaseSonogram sonogram, IEnumerable <AcousticEvent> events)
        {
            var image = new Image_MultiTrack(sonogram.GetImage(false, true, doMelScale: false));

            image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));

            ////image.AddTrack(ImageTrack.GetWavEnvelopeTrack(sonogram, image.sonogramImage.Width));
            image.AddTrack(ImageTrack.GetSegmentationTrack(sonogram));
            image.AddEvents(
                events,
                sonogram.NyquistFrequency,
                sonogram.Configuration.FreqBinCount,
                sonogram.FramesPerSecond);

            return(image.GetImage());
        }
コード例 #30
0
        public static Image GetCepstralSpectrogram(SonogramConfig sonoConfig, AudioRecording recording, string sourceRecordingName)
        {
            // TODO at present noise reduction type must be set = Standard.
            sonoConfig.NoiseReductionType      = NoiseReductionType.Standard;
            sonoConfig.NoiseReductionParameter = 3.0;
            var      cepgram            = new SpectrogramCepstral(sonoConfig, recording.WavReader);
            var      image              = cepgram.GetImage();
            var      titleBar           = BaseSonogram.DrawTitleBarOfGrayScaleSpectrogram("CEPSTRO-GRAM " + sourceRecordingName, image.Width);
            var      startTime          = TimeSpan.Zero;
            var      xAxisTicInterval   = TimeSpan.FromSeconds(1);
            TimeSpan xAxisPixelDuration = TimeSpan.FromSeconds(sonoConfig.WindowStep / (double)sonoConfig.SampleRate);
            var      labelInterval      = TimeSpan.FromSeconds(5);

            image = BaseSonogram.FrameSonogram(image, titleBar, startTime, xAxisTicInterval, xAxisPixelDuration, labelInterval);
            return(image);
        }