diff --git a/src/AnalysisPrograms/Sandpit.cs b/src/AnalysisPrograms/Sandpit.cs index 81ab52564..5143f99ca 100644 --- a/src/AnalysisPrograms/Sandpit.cs +++ b/src/AnalysisPrograms/Sandpit.cs @@ -13,6 +13,7 @@ namespace AnalysisPrograms using System.Linq; using System.Text; using System.Threading.Tasks; + using Accord.Statistics.Kernels; using Acoustics.Shared; using Acoustics.Shared.Csv; using Acoustics.Tools.Wav; @@ -27,6 +28,7 @@ namespace AnalysisPrograms using McMaster.Extensions.CommandLineUtils; using Production.Arguments; using TowseyLibrary; + using Log = TowseyLibrary.Log; /// /// Activity Code for this class:= sandpit @@ -84,7 +86,7 @@ public override Task Execute(CommandLineApplication app) //DrawLongDurationSpectrogram(); //DrawClusterSequence(); //DrawStandardSpectrograms(); - DrawZoomingSpectrogramPyramid(); + //DrawZoomingSpectrogramPyramid(); //ExtractSpectralFeatures(); //HerveGlotinMethods(); @@ -114,6 +116,7 @@ public override Task Execute(CommandLineApplication app) //Oscillations2014.TESTMETHOD_DrawOscillationSpectrogram(); //Oscillations2014.TESTMETHOD_GetSpectralIndex_Osc(); //Test_DrawFourSpectrograms(); + TestLinearFunction(); Console.WriteLine("# Finished Sandpit Task! Press any key to exit."); return this.Ok(); @@ -2924,5 +2927,56 @@ public static void ExtractFeatureVectorOfIndices(DirectoryInfo sourceDir, string } } } // end CodeToExtractFeatureVectorOfIndices() + + /// + /// Test of linear function. + /// Used to test blending in ZoomCommon line 131. + /// + public static void TestLinearFunction() + { + // set up piecewise linear function to determine colour weights + //int imageScaleInMsPerPixel = 257; + int imageScaleInMsPerPixel = 16000; + //int imageScaleInMsPerPixel = 32760; + double blendWeight1; + + /* + //Linear SCALE + int upperResolution = 30000; + int lowerResolution = 200; + if (imageScaleInMsPerPixel >= upperResolution) + { + blendWeight1 = 1.0; + } + else if (imageScaleInMsPerPixel <= lowerResolution) + { + blendWeight1 = 0.0; + } + else + { + blendWeight1 = (imageScaleInMsPerPixel - lowerResolution) / (double)upperResolution; + } + */ + + //LOG SCALE + var logResolution = Math.Log(imageScaleInMsPerPixel, 2); + double upperResolution = Math.Log(32768, 2); + double lowerResolution = Math.Log(256, 2); + double range = upperResolution - lowerResolution; + if (logResolution >= upperResolution) + { + blendWeight1 = 1.0; + } + else if (logResolution <= lowerResolution) + { + blendWeight1 = 0.0; + } + else + { + blendWeight1 = (logResolution - lowerResolution) / range; + } + + double blendWeight2 = 1 - blendWeight1; + } } } diff --git a/src/AudioAnalysisTools/LongDurationSpectrograms/Zooming/ZoomCommon.cs b/src/AudioAnalysisTools/LongDurationSpectrograms/Zooming/ZoomCommon.cs index 14ae5f280..e00dc1c66 100644 --- a/src/AudioAnalysisTools/LongDurationSpectrograms/Zooming/ZoomCommon.cs +++ b/src/AudioAnalysisTools/LongDurationSpectrograms/Zooming/ZoomCommon.cs @@ -125,37 +125,50 @@ public static Image DrawIndexSpectrogramCommon( cs1.SetSpectralIndexProperties(indexProperties); // set the relevant dictionary of index properties cs1.LoadSpectrogramDictionary(spectralSelection); - var imageScaleInMsPerPixel = imageScale.TotalMilliseconds; - double blendWeight1 = 0.0; - double blendWeight2 = 1.0; - - if (imageScaleInMsPerPixel > 15_000) + // set up piecewise linear function to determine colour weights + var logResolution = Math.Log(imageScale.TotalMilliseconds, 2); + double upperResolution = Math.Log(32768, 2); + double lowerResolution = Math.Log(256, 2); + double range = upperResolution - lowerResolution; + double blendWeight1; + if (logResolution >= upperResolution) { blendWeight1 = 1.0; - blendWeight2 = 0.0; - } - else if (imageScaleInMsPerPixel > 10_000) - { - blendWeight1 = 0.9; - blendWeight2 = 0.1; } - else if (imageScaleInMsPerPixel > 5000) + else if (logResolution <= lowerResolution) { - blendWeight1 = 0.7; - blendWeight2 = 0.3; + blendWeight1 = 0.0; } - else if (imageScaleInMsPerPixel > 1000) - { - blendWeight1 = 0.2; - blendWeight2 = 0.8; - } - else if (imageScaleInMsPerPixel > 500) + else { - // > 0.5 seconds - blendWeight1 = 0.1; - blendWeight2 = 0.9; + blendWeight1 = (logResolution - lowerResolution) / range; } + double blendWeight2 = 1 - blendWeight1; + + //else if (imageScaleInMsPerPixel > 2000) + //{ + // blendWeight1 = 0.7; + // blendWeight2 = 0.3; + //} + //else if (imageScaleInMsPerPixel > 1000) + //{ + // blendWeight1 = 0.3; + // blendWeight2 = 0.7; + //} + //else if (imageScaleInMsPerPixel > 500) + //{ + // // > 0.5 seconds + // blendWeight1 = 0.2; + // blendWeight2 = 0.8; + //} + //else if (imageScaleInMsPerPixel > 300) + //{ + // // > 0.5 seconds + // blendWeight1 = 0.1; + // blendWeight2 = 0.9; + //} + var ldfcSpectrogram = cs1.DrawBlendedFalseColourSpectrogram(colorMap1, colorMap2, blendWeight1, blendWeight2); if (ldfcSpectrogram == null) {