Skip to content

Commit

Permalink
Fix ColourMap weightings
Browse files Browse the repository at this point in the history
Fix colourMap weightings as the time scale moves from low resolution to higher. Use a log2 transformation.
  • Loading branch information
towsey committed Apr 4, 2019
1 parent f9ed53d commit 2c6578b
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 24 deletions.
56 changes: 55 additions & 1 deletion src/AnalysisPrograms/Sandpit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,7 @@ namespace AnalysisPrograms
using McMaster.Extensions.CommandLineUtils;
using Production.Arguments;
using TowseyLibrary;
using Log = TowseyLibrary.Log;

/// <summary>
/// Activity Code for this class:= sandpit
Expand Down Expand Up @@ -84,7 +86,7 @@ public override Task<int> Execute(CommandLineApplication app)
//DrawLongDurationSpectrogram();
//DrawClusterSequence();
//DrawStandardSpectrograms();
DrawZoomingSpectrogramPyramid();
//DrawZoomingSpectrogramPyramid();

//ExtractSpectralFeatures();
//HerveGlotinMethods();
Expand Down Expand Up @@ -114,6 +116,7 @@ public override Task<int> 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();
Expand Down Expand Up @@ -2924,5 +2927,56 @@ public static void ExtractFeatureVectorOfIndices(DirectoryInfo sourceDir, string
}
}
} // end CodeToExtractFeatureVectorOfIndices()

/// <summary>
/// Test of linear function.
/// Used to test blending in ZoomCommon line 131.
/// </summary>
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 2c6578b

Please sign in to comment.