From 70277d42ac88b6368d0620a67e58002d2d982147 Mon Sep 17 00:00:00 2001 From: towsey Date: Mon, 19 Aug 2019 13:49:51 +1000 Subject: [PATCH] Clean up some build problems and other minor changes --- src/AnalysisPrograms/Sandpit.cs | 11 +++++++- .../LdSpectrogramRibbons.cs | 26 +++++++------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/AnalysisPrograms/Sandpit.cs b/src/AnalysisPrograms/Sandpit.cs index 32633d87a..4ade42513 100644 --- a/src/AnalysisPrograms/Sandpit.cs +++ b/src/AnalysisPrograms/Sandpit.cs @@ -1207,12 +1207,21 @@ public static void ReadSpectralIndicesFromTwoFalseColourSpectrogramRibbons() //string[] colourKeys2 = { "BGN", "PMN", "XXX" }; var image1 = Image.FromFile(path1.FullName); var image2 = Image.FromFile(path2.FullName); + + // default time values are for complete image width. var matrix = LdSpectrogramRibbons.ReadSpectralIndicesFromTwoFalseColourSpectrogramRibbons(image1, image2); + //var startTime = TimeSpan.Zero; + //var duration = TimeSpan.FromMinutes(image1.Width); + var startTime = TimeSpan.FromHours(2); + var duration = TimeSpan.FromMinutes(60); + //var matrix = LdSpectrogramRibbons.ReadSpectralIndicesFromTwoFalseColourSpectrogramRibbons(image1, image2, startTime, duration); + //MatrixTools.WriteMatrix2File(matrix, outputPath.FullName); Csv.WriteMatrixToCsv(outputPath, matrix); - } + // TODO: need to check that can recover ribbon image from reading this matrix. + } /// /// read a set of Spectral index files and extract values from frequency band diff --git a/src/AudioAnalysisTools/LongDurationSpectrograms/LdSpectrogramRibbons.cs b/src/AudioAnalysisTools/LongDurationSpectrograms/LdSpectrogramRibbons.cs index 64cb6d5f9..61c391f2d 100644 --- a/src/AudioAnalysisTools/LongDurationSpectrograms/LdSpectrogramRibbons.cs +++ b/src/AudioAnalysisTools/LongDurationSpectrograms/LdSpectrogramRibbons.cs @@ -1,5 +1,5 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // All code in this file and all associated files are the copyright and property of the QUT Ecoacoustics Research Group (formerly MQUTeR, and formerly QUT Bioacoustics Research Group). // // @@ -9,11 +9,10 @@ namespace AudioAnalysisTools.LongDurationSpectrograms { using System; using System.Collections.Generic; - using System.Linq; using System.Data; using System.Drawing; using System.IO; - using Acoustics.Shared.Csv; + using System.Linq; using MoreLinq.Extensions; using TowseyLibrary; @@ -22,20 +21,13 @@ public static class LdSpectrogramRibbons public const string SpectralRibbonTag = ".SpectralRibbon"; public const int RibbonPlotHeight = 32; - /// - /// Reads. - /// - public static void ReadSpectralIndicesFromTwoFalseColourSpectrogramRibbons() - { - } - /// /// Reads the entire length of spectral ribbon images into a matrix of spectral indices. - /// IMPORTANT: Assume that the two images both have a time scale, that is, one pixel = one minute AND + /// IMPORTANT: Assume that the two images both have the same time scale, that is, one pixel = one minute AND /// ASSUME they have the same pixel width i.e. span the same number of minutes. /// - /// spectrogram ribbon 1 - /// spectrogram ribbon 2 + /// spectrogram ribbon 1. + /// spectrogram ribbon 2. /// matrix of normalised spectral indices corresponding to those used to construct the ribbon images. public static double[,] ReadSpectralIndicesFromTwoFalseColourSpectrogramRibbons(Image image1, Image image2) { @@ -133,17 +125,17 @@ public static List ReadSpectralIndicesFromFalseColourSpectrogram(Bitm endMinute = image.Width; } - var dataWidth = endMinute - startMinute + 1; + var dataWidth = endMinute - startMinute; var height = image.Height; var red = new double[dataWidth, height]; var grn = new double[dataWidth, height]; var blu = new double[dataWidth, height]; - for (int w = startMinute; w < endMinute; w++) + for (int w = 0; w < dataWidth; w++) { for (int h = 0; h < height; h++) { - var pixel = image.GetPixel(w, height - h - 1); + var pixel = image.GetPixel(w + startMinute, height - h - 1); red[w, h] = pixel.R / 255D; grn[w, h] = pixel.G / 255D; blu[w, h] = pixel.B / 255D; @@ -161,7 +153,7 @@ public static List ReadSpectralIndicesFromFalseColourSpectrogram(Bitm } /// - /// returns a Long Duration spectrogram of same image length as the full-scale LDspectrogram but the frequency scale reduced to the passed vlaue of height. + /// returns a Long Duration spectrogram of same image length as the full-scale LdSpectrogram but the frequency scale reduced to the passed vlaue of height. /// This produces a LD spectrogram "ribbon" which can be used in circumstances where the full image is not appropriate. /// Note that if the height passed is a power of 2, then the full frequency scale (also a power of 2 due to FFT) can be scaled down exactly. /// A height of 32 is quite good - small but still discriminates frequency bands.