Skip to content

Commit

Permalink
drawing freq lines on image
Browse files Browse the repository at this point in the history
modified the methods for Manoosh.
Plus the inevitable collateral damage
  • Loading branch information
towsey authored and atruskie committed Jun 8, 2018
1 parent cfecb4a commit 7c5af4c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/AnalysisPrograms/Sandpit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ public override Task<int> Execute(CommandLineApplication app)
//TEST_FilterMovingAverage();
//TestImageProcessing();
//TestMatrix3dClass();
//TestsOfFrequencyScales();
TestsOfFrequencyScales();
//TestReadingFileOfSummaryIndices();
//TestStructureTensor();
//TestWavelets();
//TestFft2D();
//TestTernaryPlots();
//TestDirectorySearchAndFileSearch();
TestNoiseReduction();
//TestNoiseReduction();

Console.WriteLine("# Finished Sandpit Task! Press any key to exit.");
return this.Ok();
Expand Down Expand Up @@ -1234,6 +1234,8 @@ public static void TestsOfFrequencyScales()
// DspFilters.TestMethod_GenerateSignal1();
// DspFilters.TestMethod_GenerateSignal2();
// EventStatisticsCalculate.TestCalculateEventStatistics();

FrequencyScale.TESTMETHOD_DrawFrequencyLinesOnImage();
}

/// <summary>
Expand Down
23 changes: 19 additions & 4 deletions src/AudioAnalysisTools/DSP/FrequencyScale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public static int[] CreateLinearYaxis(int herzInterval, int nyquistFreq, int ima
return gridLines;
}

public static void DrawFrequencyLinesOnImage(Bitmap bmp, int[,] gridLineLocations)
public static void DrawFrequencyLinesOnImage(Bitmap bmp, int[,] gridLineLocations, bool includeLabels)
{
int minimumSpectrogramWidth = 10;
if (bmp.Width < minimumSpectrogramWidth)
Expand Down Expand Up @@ -386,7 +386,7 @@ public static void DrawFrequencyLinesOnImage(Bitmap bmp, int[,] gridLineLocation
}
}

if (bmp.Width < 30)
if (!includeLabels || bmp.Width < 30)
{
// there is no point placing Hertz label on a narrow image. It obscures too much spectrogram.
return;
Expand All @@ -403,9 +403,9 @@ public static void DrawFrequencyLinesOnImage(Bitmap bmp, int[,] gridLineLocation
}
} //end AddHzGridLines()

public static void DrawFrequencyLinesOnImage(Bitmap bmp, FrequencyScale freqScale)
public static void DrawFrequencyLinesOnImage(Bitmap bmp, FrequencyScale freqScale, bool includeLabels)
{
DrawFrequencyLinesOnImage(bmp, freqScale.GridLineLocations);
DrawFrequencyLinesOnImage(bmp, freqScale.GridLineLocations, includeLabels);
}

// ****************************************************************************************************************************
Expand Down Expand Up @@ -671,5 +671,20 @@ public static void TESTMETHOD_OctaveFrequencyScale2()
LoggedConsole.WriteLine("Completed Octave Frequency Scale " + testName);
Console.WriteLine("\n\n");
}

public static void TESTMETHOD_DrawFrequencyLinesOnImage()
{
string filename = @"C:\SensorNetworks\SoftwareTests\TestFrequencyScale\Clusters50.bmp";
string outputFile = @"C:\SensorNetworks\SoftwareTests\TestFrequencyScale\Clusters50WithGrid.bmp";
Image bmp = ImageTools.ReadImage2Bitmap(filename);

int nyquist = 11025;
int frameSize = 1024;
int finalBinCount = 128;
int gridInterval = 1000;
var freqScale = new FrequencyScale(FreqScaleType.Mel, nyquist, frameSize, finalBinCount, gridInterval);
DrawFrequencyLinesOnImage((Bitmap)bmp, freqScale, includeLabels: false);
bmp.Save(outputFile);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ public static Image FrameLDSpectrogram(Image bmp1, Image titleBar, LDSpectrogram
cs.FreqScale = freqScale;
}

FrequencyScale.DrawFrequencyLinesOnImage((Bitmap)bmp1, cs.FreqScale);
FrequencyScale.DrawFrequencyLinesOnImage((Bitmap)bmp1, cs.FreqScale, includeLabels: true);

// draw the composite bitmap
var imageList = new List<Image> { titleBar, timeBmp1, bmp1, timeBmp2 };
Expand Down
4 changes: 2 additions & 2 deletions src/AudioAnalysisTools/StandardSpectrograms/BaseSonogram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public Image GetImageFullyAnnotated(Image image, string title, int[,] gridLineLo
throw new ArgumentNullException(nameof(image));
}

FrequencyScale.DrawFrequencyLinesOnImage((Bitmap)image, gridLineLocations);
FrequencyScale.DrawFrequencyLinesOnImage((Bitmap)image, gridLineLocations, includeLabels: true);

var titleBar = LDSpectrogramRGB.DrawTitleBarOfGrayScaleSpectrogram(title, image.Width);
var timeBmp = ImageTrack.DrawTimeTrack(this.Duration, image.Width);
Expand Down Expand Up @@ -337,7 +337,7 @@ public Image GetImage(bool doHighlightSubband, bool add1KHzLines, bool doMelScal
gridLineLocations = FrequencyScale.GetLinearGridLineLocations(this.NyquistFrequency, kHzInterval, image.Height);
}

FrequencyScale.DrawFrequencyLinesOnImage((Bitmap)image, gridLineLocations);
FrequencyScale.DrawFrequencyLinesOnImage((Bitmap)image, gridLineLocations, includeLabels: true);
}

return image;
Expand Down
12 changes: 6 additions & 6 deletions src/AudioAnalysisTools/StandardSpectrograms/SpectrogramTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -865,14 +865,14 @@ public static double[] ExtractModalNoiseSubband(double[] modalNoise, int minHz,
/// <summary>
/// Only calls method to draw frequency lines but may in future want to add the times scale.
/// </summary>
/// <param name="bmp"></param>
/// <param name="startOffset"></param>
/// <param name="fullDuration"></param>
/// <param name="xAxisTicInterval"></param>
/// <param name="freqScale"></param>
/// <param name="bmp">the spectrogram image</param>
/// <param name="startOffset">start Offset</param>
/// <param name="fullDuration">full Duration</param>
/// <param name="xAxisTicInterval">xAxis Tic Interval</param>
/// <param name="freqScale">freq Scale</param>
public static void DrawGridLinesOnImage(Bitmap bmp, TimeSpan startOffset, TimeSpan fullDuration, TimeSpan xAxisTicInterval, FrequencyScale freqScale)
{
FrequencyScale.DrawFrequencyLinesOnImage(bmp, freqScale);
FrequencyScale.DrawFrequencyLinesOnImage(bmp, freqScale, includeLabels: true);

// we have stopped drawing temporal gridlines on these spectrograms. Create unnecessary clutter.
//DrawTimeLinesOnImage(bmp, startOffset, fullDuration, xAxisTicInterval);
Expand Down

0 comments on commit 7c5af4c

Please sign in to comment.