Example #1
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);
        }
        /// <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);
        }
Example #3
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));
        }