Skip to content

Commit

Permalink
Adds rendering of ALL grayscale LD spectrograms to standard indices g…
Browse files Browse the repository at this point in the history
…eneration

All single index greyscale spectrograms are now drawn. I changed the
config file to get better grey scale rendering. Changed drawing of Hertz
label so does not cover so much spectrogram real-estate.

Fixes #199
  • Loading branch information
towsey authored and atruskie committed Jan 31, 2019
1 parent e000fde commit 6ec16c6
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 40 deletions.
22 changes: 11 additions & 11 deletions src/AnalysisConfigFiles/IndexPropertiesConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,8 @@ OSC:
DataType: double[]
DefaultValue: 0.0
DoDisplay: true
NormMin: 0.0
NormMax: 10.0
NormMin: 0.1
NormMax: 5.0
CalculateNormMin: true
CalculateNormMax: true
ProjectID: Acoustic Indices
Expand Down Expand Up @@ -687,7 +687,7 @@ RHZ:
DefaultValue: 0.0
DoDisplay: true
NormMin: 0.1
NormMax: 1.5
NormMax: 1.0
CalculateNormMin: false
CalculateNormMax: false
ProjectID: Acoustic Indices
Expand All @@ -700,8 +700,8 @@ RVT:
DoDisplay: true
NormMin: 0.1
NormMax: 0.4
CalculateNormMin: false
CalculateNormMax: false
CalculateNormMin: true
CalculateNormMax: true
ProjectID: Acoustic Indices
Units: "tracks/s"
RPS:
Expand All @@ -712,8 +712,8 @@ RPS:
DoDisplay: true
NormMin: 0.0
NormMax: 0.4
CalculateNormMin: false
CalculateNormMax: false
CalculateNormMin: true
CalculateNormMax: true
ProjectID: Acoustic Indices
Units: "tracks/s"
RNG:
Expand All @@ -724,8 +724,8 @@ RNG:
DoDisplay: true
NormMin: 0.0
NormMax: 0.4
CalculateNormMin: false
CalculateNormMax: false
CalculateNormMin: true
CalculateNormMax: true
ProjectID: Acoustic Indices
Units: "tracks/s"
R3D:
Expand All @@ -736,8 +736,8 @@ R3D:
DoDisplay: true
NormMin: 0.15
NormMax: 1.0
CalculateNormMin: false
CalculateNormMax: false
CalculateNormMin: true
CalculateNormMax: true
ProjectID: Acoustic Indices
Units: "tracks/s"
SPT:
Expand Down
23 changes: 12 additions & 11 deletions src/AnalysisPrograms/Sandpit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace AnalysisPrograms
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
Expand All @@ -16,17 +15,15 @@ namespace AnalysisPrograms
using System.Threading.Tasks;
using Acoustics.Shared;
using Acoustics.Shared.Csv;
using AnalyseLongRecordings;
using AnalysisPrograms.AnalyseLongRecordings;
using AudioAnalysisTools;
using AudioAnalysisTools.DSP;
using AudioAnalysisTools.Indices;
using AudioAnalysisTools.LongDurationSpectrograms;
using AudioAnalysisTools.StandardSpectrograms;
using AudioAnalysisTools.WavTools;
using log4net.Util;
using McMaster.Extensions.CommandLineUtils;
using Production;
using Production.Arguments;
using AnalysisPrograms.Production.Arguments;
using TowseyLibrary;

/// <summary>
Expand Down Expand Up @@ -64,7 +61,7 @@ public override Task<int> Execute(CommandLineApplication app)
Log.WriteLine("# Start Time = " + tStart.ToString(CultureInfo.InvariantCulture));

//AnalyseFrogDataSet();
//Audio2CsvOverOneFile();
Audio2CsvOverOneFile();
//Audio2CsvOverMultipleFiles();

// used to get files from availae for Black rail and Least Bittern papers.
Expand Down Expand Up @@ -103,8 +100,8 @@ public override Task<int> Execute(CommandLineApplication app)
//TestTernaryPlots();
//TestDirectorySearchAndFileSearch();
//TestNoiseReduction();
Oscillations2014.TESTMETHOD_DrawOscillationSpectrogram();
Oscillations2014.TESTMETHOD_GetSpectralIndex_Osc();
//Oscillations2014.TESTMETHOD_DrawOscillationSpectrogram();
//Oscillations2014.TESTMETHOD_GetSpectralIndex_Osc();
//Test_DrawFourSpectrograms();

Console.WriteLine("# Finished Sandpit Task! Press any key to exit.");
Expand Down Expand Up @@ -323,6 +320,10 @@ public static void Audio2CsvOverOneFile()
//string outputPath = @"G:\SensorNetworks\Output\BradLaw\Pillaga24";
//string configPath = @"C:\Work\GitHub\audio-analysis\AudioAnalysis\AnalysisConfigFiles\Towsey.Acoustic.yml";

string recordingPath = @"C:\Ecoacoustics\WavFiles\LizZnidersic\TasmanIsland2015_Unit2_Mez\SM304256_0+1_20151114_001652.wav";
string outputPath = @"C:\Ecoacoustics\Output\Test\Test24HourRecording\TasmanIslandMez\01";
string configPath = @"C:\Work\GitHub\audio-analysis\src\AnalysisConfigFiles\Towsey.Acoustic.yml";

// Ivan Campos recordings
//string recordingPath = @"G:\SensorNetworks\WavFiles\Ivancampos\INCIPO01_20161031_024006_898.wav";
//string outputPath = @"G:\SensorNetworks\Output\IvanCampos\17";
Expand Down Expand Up @@ -380,9 +381,9 @@ public static void Audio2CsvOverOneFile()

// SERF RECORDINGS FROM 19th June 2013
// these are six hour recordings
string recordingPath = @"G:\Ecoacoustics\WavFiles\SERF\2013June19\SERF_20130619_064615_000.wav";
string outputPath = @"C:\Ecoacoustics\Output\SERF\SERFIndicesNew_2013June19";
string configPath = @"C:\Work\GitHub\audio-analysis\src\AnalysisConfigFiles\Towsey.Acoustic.yml";
//string recordingPath = @"G:\Ecoacoustics\WavFiles\SERF\2013June19\SERF_20130619_064615_000.wav";
//string outputPath = @"C:\Ecoacoustics\Output\SERF\SERFIndicesNew_2013June19";
//string configPath = @"C:\Work\GitHub\audio-analysis\src\AnalysisConfigFiles\Towsey.Acoustic.yml";

// GROUND PARROT
//string recordingPath = @"C:\SensorNetworks\WavFiles\TestRecordings\groundParrot_Perigian_TEST.wav";
Expand Down
11 changes: 9 additions & 2 deletions src/AudioAnalysisTools/DSP/FrequencyScale.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="FrequencyScale.cs" company="QutEcoacoustics">
// <copyright file="FrequencyScale.cs" company="QutEcoacoustics">
// 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).
// </copyright>

Expand Down Expand Up @@ -396,9 +396,16 @@ public static void DrawFrequencyLinesOnImage(Bitmap bmp, int[,] gridLineLocation
for (int b = 0; b < bandCount; b++)
{
int y = height - gridLineLocations[b, 0];
int hertzValue = gridLineLocations[b, 1];
if (bmp.Width < 120)
{
// convert label to kHz so does not hide too much spectrogram
hertzValue = hertzValue / 1000;
}

if (y > 1)
{
g.DrawString($"{gridLineLocations[b, 1]}", new Font("Thachoma", 8), txtColour, 1, y);
g.DrawString($"{hertzValue}", new Font("Thachoma", 8), txtColour, 1, y);
}
}
} //end AddHzGridLines()
Expand Down
73 changes: 57 additions & 16 deletions src/AudioAnalysisTools/LongDurationSpectrograms/LDSpectrogramRGB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace AudioAnalysisTools.LongDurationSpectrograms
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -476,6 +477,12 @@ public void LoadSpectrogramDictionary(Dictionary<string, double[,]> dictionary)
{
minBound = indexProperties.NormMin;
}

// Do not want OSC min set too low. Happens because min can = zero
if (key.Equals("OSC") && minBound < indexProperties.NormMin)
{
minBound = indexProperties.NormMin;
}
}

if (indexProperties.CalculateNormMax)
Expand All @@ -499,23 +506,21 @@ public void LoadSpectrogramDictionary(Dictionary<string, double[,]> dictionary)
return matrix;
}

/// <summary>
/// Draws all available spectrograms in grey scale
/// </summary>
public void DrawGreyScaleSpectrograms(DirectoryInfo opdir, string opFileName)
{
var keys = SpectralIndexValues.Keys;
//string[] keys = this.SpectrogramKeys;
this.DrawGreyScaleSpectrograms(opdir, opFileName, keys);
}

/// <summary>
/// draws only those spectrograms in the passed array of keys
/// </summary>
public void DrawGreyScaleSpectrograms(DirectoryInfo opdir, string opFileName, string[] keys)
{
// init List of track images
var listOfImages = new List<Image>();

foreach (string key in keys)
{
if (key == "SUM" || key == "DIF")
{
continue;
}

if (!this.SpectrogramMatrices.ContainsKey(key))
{
LoggedConsole.WriteErrorLine("\n\nWARNING: From method LDSpectrogram.DrawGreyScaleSpectrograms()");
Expand All @@ -540,10 +545,38 @@ public void DrawGreyScaleSpectrograms(DirectoryInfo opdir, string opFileName, st
continue;
}

// the directory for the following path must exist
var path = FilenameHelpers.AnalysisResultPath(opdir, opFileName, key, "png");
var bmp = this.DrawGreyscaleSpectrogramOfIndex(key);
bmp?.Save(path);

var header = new Bitmap(bmp.Width, 20);
Graphics g = Graphics.FromImage(header);
g.Clear(Color.LightGray);
g.SmoothingMode = SmoothingMode.AntiAlias;
//g.InterpolationMode = InterpolationMode.HighQualityBicubic;
//g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawString(key, new Font("Tahoma", 9), Brushes.Black, 4, 4);
var indexImage = ImageTools.CombineImagesVertically(new List<Image>(new Image[] { header, bmp }));

// save the image - the directory for the path must exist
//var path = FilenameHelpers.AnalysisResultPath(opdir, opFileName, key, "png");
//indexImage?.Save(path);

listOfImages.Add(indexImage);
}

// save the combined track image - the directory for the path must exist
var path = FilenameHelpers.AnalysisResultPath(opdir, opFileName, "KEYS", "png");
int imageCount = listOfImages.Count;

// check how wide combined image will be. If tracks are wider than 180 = 3 hours, then go vertical
if (listOfImages[0].Width * imageCount > 180 * imageCount)
{
var combinedImage = ImageTools.CombineImagesVertically(listOfImages);
combinedImage?.Save(path);
}
else
{
var combinedImage = ImageTools.CombineImagesInLine(listOfImages);
combinedImage?.Save(path);
}
}

Expand Down Expand Up @@ -1473,11 +1506,19 @@ public static Tuple<Image, string>[] DrawSpectrogramsFromSpectralIndices(
cs1.IndexStats = indexStatistics;

// draw gray scale spectrogram for each index.
string[] keys = colorMap1.Split('-');
cs1.DrawGreyScaleSpectrograms(outputDirectory, fileStem, keys);
keys = colorMap2.Split('-');
//string[] keys = colorMap1.Split('-');
//cs1.DrawGreyScaleSpectrograms(outputDirectory, fileStem, keys);
//keys = colorMap2.Split('-');
// draw all available gray scale index spectrograms.
var keys = SpectralIndexValues.Keys;
cs1.DrawGreyScaleSpectrograms(outputDirectory, fileStem, keys);

// //string[] keys = this.SpectrogramKeys;
//cs1.DrawGreyScaleSpectrograms(outputDirectory, fileStem, keys);
//}
//keys = colorMap2.Split('-');
//cs1.DrawGreyScaleSpectrograms(outputDirectory, fileStem, keys);

// create and save first false-colour spectrogram image
var image1NoChrome = cs1.DrawFalseColourSpectrogramChromeless(cs1.ColorMode, colorMap1);
Image image1 = null;
Expand Down

0 comments on commit 6ec16c6

Please sign in to comment.