/// <summary>
        /// THis method draws a sonogram with other useful information attached.
        /// </summary>
        /// <param name="sonogram">of BaseSonogram class.</param>
        /// <param name="events">a list of acoustic events.</param>
        /// <param name="plots">a list of plots relevant to the spectrogram scores.</param>
        /// <param name="hits">not often used - can be null.</param>
        public static Image GetSonogramPlusCharts(BaseSonogram sonogram, List <AcousticEvent> events, List <Plot> plots, double[,] hits)
        {
            var image = new Image_MultiTrack(sonogram.GetImage(doHighlightSubband: false, add1KHzLines: true, doMelScale: false));

            image.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond));
            if (plots != null)
            {
                foreach (var plot in plots)
                {
                    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 != null && events.Count > 0)
            {
                // set colour for the events
                foreach (AcousticEvent ev in events)
                {
                    ev.BorderColour = AcousticEvent.DefaultBorderColor;
                    ev.ScoreColour  = AcousticEvent.DefaultScoreColor;
                }

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

            return(image.GetImage());
        }
Esempio n. 2
0
        }//Sonogram2MultiTrackImage()

        public static Image Sonogram2Image(BaseSonogram sonogram, Dictionary <string, string> configDict, double[,] hits, List <Plot> scores, List <AcousticEvent> predictedEvents, double eventThreshold)
        {
            Image_MultiTrack multiTrackImage = Sonogram2MultiTrackImage(sonogram, configDict);

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

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

            if (predictedEvents.Count > 0)
            {
                multiTrackImage.AddEvents(predictedEvents, sonogram.NyquistFrequency, sonogram.Configuration.FreqBinCount, sonogram.FramesPerSecond);
            }

            return(multiTrackImage.GetImage());
        } //Sonogram2Image()
        /// <summary>
        /// This method draws a spectrogram with other useful information attached.
        /// </summary>
        /// <param name="sonogram">of BaseSonogram class.</param>
        /// <param name="events">a list of acoustic events.</param>
        /// <param name="plots">a list of plots relevant to the spectrogram scores.</param>
        /// <param name="hits">not often used - can be null.</param>
        public static Image <Rgb24> GetSonogramPlusCharts(
            BaseSonogram sonogram,
            List <AcousticEvent> events,
            List <Plot> plots,
            double[,] hits)
        {
            var spectrogram = sonogram.GetImage(doHighlightSubband: false, add1KHzLines: true, doMelScale: false);

            Contract.RequiresNotNull(spectrogram, nameof(spectrogram));

            var height    = spectrogram.Height;
            var frameSize = sonogram.Configuration.WindowSize;

            // init with linear frequency scale and draw freq grid lines on image
            int hertzInterval = 1000;

            if (height < 200)
            {
                hertzInterval = 2000;
            }

            var freqScale = new FrequencyScale(sonogram.NyquistFrequency, frameSize, hertzInterval);

            FrequencyScale.DrawFrequencyLinesOnImage(spectrogram, freqScale.GridLineLocations, includeLabels: true);

            // draw event outlines onto spectrogram.
            if (events != null && events.Count > 0)
            {
                // set colour for the events
                foreach (AcousticEvent ev in events)
                {
                    ev.BorderColour = AcousticEvent.DefaultBorderColor;
                    ev.ScoreColour  = AcousticEvent.DefaultScoreColor;
                    ev.DrawEvent(spectrogram, sonogram.FramesPerSecond, sonogram.FBinWidth, height);
                }
            }

            // now add in hits to the spectrogram image.
            if (hits != null)
            {
                spectrogram = Image_MultiTrack.OverlayScoresAsRedTransparency(spectrogram, hits);

                // following line needs to be reworked if want to call OverlayRainbowTransparency(hits);
                //image.OverlayRainbowTransparency(hits);
            }

            int pixelWidth = spectrogram.Width;
            var titleBar   = LDSpectrogramRGB.DrawTitleBarOfGrayScaleSpectrogram("TITLE", pixelWidth);
            var timeTrack  = ImageTrack.DrawTimeTrack(sonogram.Duration, pixelWidth);

            var imageList = new List <Image <Rgb24> >
            {
                titleBar,
                timeTrack,
                spectrogram,
                timeTrack,
            };

            if (plots != null)
            {
                foreach (var plot in plots)
                {
                    // Next line assumes plot data normalised in 0,1
                    var plotImage = plot.DrawAnnotatedPlot(ImageTrack.DefaultHeight);

                    // the following draws same plot without the title.
                    //var plotImage = ImageTrack.DrawScoreArrayTrack(plot.data, plot.threshold, pixelWidth);
                    imageList.Add(plotImage);
                }
            }

            var compositeImage = ImageTools.CombineImagesVertically(imageList);

            return(compositeImage);
        }
Esempio n. 4
0
        /// <summary>
        /// This method draws a spectrogram with other useful information attached.
        /// </summary>
        /// <param name="sonogram">of BaseSonogram class.</param>
        /// <param name="events">a list of acoustic events.</param>
        /// <param name="plots">a list of plots relevant to the spectrogram scores.</param>
        /// <param name="hits">not often used - can be null.</param>
        public static Image <Rgb24> GetSonogramPlusCharts(
            BaseSonogram sonogram,
            List <EventCommon> events,
            List <Plot> plots,
            double[,] hits)
        {
            var spectrogram = sonogram.GetImage(doHighlightSubband: false, add1KHzLines: true, doMelScale: false);

            Contract.RequiresNotNull(spectrogram, nameof(spectrogram));

            var height    = spectrogram.Height;
            var width     = spectrogram.Width;
            var frameSize = sonogram.Configuration.WindowSize;
            //var segmentDuration = sonogram.Duration;
            var spectrogramDuration = width * sonogram.FrameStep;

            // init with linear frequency scale and draw freq grid lines on image
            int hertzInterval = 1000;

            if (height < 200)
            {
                hertzInterval = 2000;
            }

            var nyquist   = sonogram.NyquistFrequency;
            var freqScale = new FrequencyScale(nyquist, frameSize, hertzInterval);

            FrequencyScale.DrawFrequencyLinesOnImage(spectrogram, freqScale.GridLineLocations, includeLabels: true);

            // draw event outlines onto spectrogram.
            if (events != null && events.Count > 0)
            {
                foreach (SpectralEvent ev in events)
                {
                    var options = new EventRenderingOptions(new UnitConverters(ev.SegmentStartSeconds, spectrogramDuration, nyquist, width, height));
                    spectrogram.Mutate(x => ev.Draw(x, options));
                }
            }

            // now add in hits to the spectrogram image.
            if (hits != null)
            {
                spectrogram = Image_MultiTrack.OverlayScoresAsRedTransparency(spectrogram, hits);
            }

            int pixelWidth = spectrogram.Width;
            var titleBar   = LDSpectrogramRGB.DrawTitleBarOfGrayScaleSpectrogram("TITLE", pixelWidth);
            var timeTrack  = ImageTrack.DrawTimeTrack(sonogram.Duration, pixelWidth);

            var imageList = new List <Image <Rgb24> >
            {
                titleBar,
                timeTrack,
                spectrogram,
                timeTrack,
            };

            if (plots != null)
            {
                foreach (var plot in plots)
                {
                    // Next line assumes plot data normalised in 0,1
                    var plotImage = plot.DrawAnnotatedPlot(ImageTrack.DefaultHeight);

                    // the following draws same plot without the title.
                    //var plotImage = ImageTrack.DrawScoreArrayTrack(plot.data, plot.threshold, pixelWidth);
                    imageList.Add(plotImage);
                }
            }

            var compositeImage = ImageTools.CombineImagesVertically(imageList);

            return(compositeImage);
        }
Esempio n. 5
0
        } //OverlayMatrix()

        /// <summary>
        /// superimposes a matrix of scores on top of a sonogram.
        /// </summary>
        public Image <Rgb24> OverlayRedTransparency(Image <Rgb24> bmp)
        {
            return(Image_MultiTrack.OverlayScoresAsRedTransparency(bmp, this.SuperimposedRedTransparency));
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static Image_MultiTrack Sonogram2MultiTrackImage(BaseSonogram sonogram, Dictionary <string, string> configDict)
        {
            bool doHighlightSubband = false;

            //check if doing a reduced sonogram
            //int timeReductionFactor = 1;
            //if (configDict.ContainsKey(Keys.TIME_REDUCTION_FACTOR))
            //    timeReductionFactor = ConfigDictionary.GetInt(Keys.TIME_REDUCTION_FACTOR, configDict);
            //int freqReductionFactor = 1;
            //if (configDict.ContainsKey(Keys.FREQ_REDUCTION_FACTOR))
            //    freqReductionFactor = ConfigDictionary.GetInt(Keys.FREQ_REDUCTION_FACTOR, configDict);
            //if (!((timeReductionFactor == 1) && (freqReductionFactor == 1)))
            //{
            //    sonogram.Data = ReduceDimensionalityOfSpectrogram(sonogram.Data, timeReductionFactor, freqReductionFactor);
            //    return sonogram.GetImage(doHighlightSubband, add1kHzLines);
            //}

            // (iii) NOISE REDUCTION
            //bool doNoiseReduction = false;
            //if (configDict.ContainsKey(AnalysisKeys.NoiseDoReduction))
            //    doNoiseReduction = ConfigDictionary.GetBoolean(AnalysisKeys.NoiseDoReduction, configDict);
            //if (doNoiseReduction)
            //{
            //    //LoggedConsole.WriteLine("PERFORMING NOISE REDUCTION");
            //    double bgThreshold = 3.0;
            //    if (configDict.ContainsKey(AnalysisKeys.NoiseBgThreshold))
            //        bgThreshold = ConfigDictionary.GetDouble(AnalysisKeys.NoiseBgThreshold, configDict);
            //    var tuple = SNR.NoiseReduce(sonogram.Data, NoiseReductionType.STANDARD, bgThreshold);
            //    sonogram.Data = tuple.Item1;   // store data matrix
            //}

            //ADD time and frequency scales
            bool addScale = false;

            if (configDict.ContainsKey(AnalysisKeys.AddTimeScale))
            {
                addScale = ConfigDictionary.GetBoolean(AnalysisKeys.AddTimeScale, configDict);
            }
            else
            if (configDict.ContainsKey(AnalysisKeys.AddAxes))
            {
                addScale = ConfigDictionary.GetBoolean(AnalysisKeys.AddAxes, configDict);
            }

            Image            img = sonogram.GetImage(doHighlightSubband, add1KHzLines: addScale, doMelScale: false);
            Image_MultiTrack mti = new Image_MultiTrack(img);

            if (addScale)
            {
                mti.AddTrack(ImageTrack.GetTimeTrack(sonogram.Duration, sonogram.FramesPerSecond)); //add time scale
            }

            bool addSegmentationTrack = false;

            //add segmentation track
            if (configDict.ContainsKey(AnalysisKeys.AddSegmentationTrack))
            {
                addSegmentationTrack = ConfigDictionary.GetBoolean(AnalysisKeys.AddSegmentationTrack, configDict);
            }

            if (addSegmentationTrack)
            {
                mti.AddTrack(ImageTrack.GetSegmentationTrack(sonogram)); //add segmentation track
            }

            return(mti);

            //mti.AddTrack(ImageTrack.GetWavEnvelopeTrack(sonogram)); //add segmentation track
        }//Sonogram2MultiTrackImage()