Skip to content

Commit

Permalink
Refactors Audio2Sonogram
Browse files Browse the repository at this point in the history
- Audio2Sonogram is now renamed Spectrogram generator
- Spectrogram generator code was split into smaller classes for maintability
- Spectrogram generator can now save any combination and any order of the defined image types

- Added ColorBrewer palettes so we can use standrd (and optimised) color scales to graphs. For the spectrogram generator we tag each image type (mainly for testing) with a different colour so it is easy to tell which image type we are looking at.
- Also mostly converted spectrogram generator config to statically deserialized config
- Augmented GeneratedImageTest so it can save extra files (especially in the case of data tests where the extra data metadata is not made available by mstest)
  • Loading branch information
atruskie committed Feb 27, 2020
1 parent 4d67dbf commit 7b4ef82
Show file tree
Hide file tree
Showing 25 changed files with 2,709 additions and 594 deletions.
34 changes: 34 additions & 0 deletions src/Acoustics.Shared/ColorScales/ColorBrewer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// <copyright file="ColorBrewer.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>

namespace Acoustics.Shared.ColorScales
{
// source changed from original
// original copyright notices:
// > /* coded by sean walsh: http://www.capesean.co.za */
// > // This product includes color specifications and designs developed by Cynthia Brewer (http://colorbrewer.org/).
// > // Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State University.

using System.Diagnostics.CodeAnalysis;

public enum Type
{
SequentialMultipleHues,
SequentialSingleHue,
Diverging,
Qualitative,
}

[SuppressMessage("ReSharper", "StringLiteralTypo", Justification = "Hex color codes causing false positives")]
public static partial class ColorBrewer
{
public static QualitativePalettes Qualitative { get; } = new QualitativePalettes();

public static SequentialSingleHuePalettes SequentialSingleHue { get; } = new SequentialSingleHuePalettes();

public static DivergingPalettes Diverging { get; } = new DivergingPalettes();

public static SequentialMultipleHuesPalettes SequentialMultipleHues { get; } = new SequentialMultipleHuesPalettes();
}
}
555 changes: 555 additions & 0 deletions src/Acoustics.Shared/ColorScales/DivergingPalettes.cs

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/Acoustics.Shared/ColorScales/Palette.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// <copyright file="Palette.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>

namespace Acoustics.Shared.ColorScales
{
using System.Collections.Generic;
using System.Linq;
using SixLabors.ImageSharp;

public class Palette
{
public string Label { get; internal set; }

public Type Type1 { get; internal set; }

public List<Color[]> Colors { get; internal set; }

public Color[] ForClassCount(int classCount) => this.Colors.FirstOrDefault(x => x.Length == classCount);
}
}
302 changes: 302 additions & 0 deletions src/Acoustics.Shared/ColorScales/QualitativePalettes.cs

Large diffs are not rendered by default.

557 changes: 557 additions & 0 deletions src/Acoustics.Shared/ColorScales/SequentialMultipleHuesPalettes.cs

Large diffs are not rendered by default.

285 changes: 285 additions & 0 deletions src/Acoustics.Shared/ColorScales/SequentialSingleHuePalettes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
// <copyright file="SequentialSingleHuePalettes.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>

namespace Acoustics.Shared.ColorScales
{
using System.Collections.Generic;
using SixLabors.ImageSharp;

public partial class ColorBrewer
{
public class SequentialSingleHuePalettes
{
public Palette Purples { get; } = new Palette
{
Label = "Purples",
Type1 = Type.SequentialSingleHue,
Colors = new List<Color[]>
{
new[] { Color.FromHex("efedf5"), Color.FromHex("bcbddc"), Color.FromHex("756bb1") },
new[]
{
Color.FromHex("f2f0f7"), Color.FromHex("cbc9e2"), Color.FromHex("9e9ac8"),
Color.FromHex("6a51a3")
},
new[]
{
Color.FromHex("f2f0f7"), Color.FromHex("cbc9e2"), Color.FromHex("9e9ac8"),
Color.FromHex("756bb1"), Color.FromHex("54278f")
},
new[]
{
Color.FromHex("f2f0f7"), Color.FromHex("dadaeb"), Color.FromHex("bcbddc"),
Color.FromHex("9e9ac8"), Color.FromHex("756bb1"),
Color.FromHex("54278f"),
},
new[]
{
Color.FromHex("f2f0f7"), Color.FromHex("dadaeb"), Color.FromHex("bcbddc"),
Color.FromHex("9e9ac8"), Color.FromHex("807dba"),
Color.FromHex("6a51a3"), Color.FromHex("4a1486"),
},
new[]
{
Color.FromHex("fcfbfd"), Color.FromHex("efedf5"), Color.FromHex("dadaeb"),
Color.FromHex("bcbddc"), Color.FromHex("9e9ac8"),
Color.FromHex("807dba"), Color.FromHex("6a51a3"), Color.FromHex("4a1486"),
},
new[]
{
Color.FromHex("fcfbfd"), Color.FromHex("efedf5"), Color.FromHex("dadaeb"),
Color.FromHex("bcbddc"), Color.FromHex("9e9ac8"),
Color.FromHex("807dba"), Color.FromHex("6a51a3"), Color.FromHex("54278f"),
Color.FromHex("3f007d"),
},
},
};

public Palette Blues { get; } = new Palette
{
Label = "Blues",
Type1 = Type.SequentialSingleHue,
Colors = new List<Color[]>
{
new[] { Color.FromHex("deebf7"), Color.FromHex("9ecae1"), Color.FromHex("3182bd") },
new[]
{
Color.FromHex("eff3ff"), Color.FromHex("bdd7e7"), Color.FromHex("6baed6"),
Color.FromHex("2171b5")
},
new[]
{
Color.FromHex("eff3ff"), Color.FromHex("bdd7e7"), Color.FromHex("6baed6"),
Color.FromHex("3182bd"), Color.FromHex("08519c")
},
new[]
{
Color.FromHex("eff3ff"), Color.FromHex("c6dbef"), Color.FromHex("9ecae1"),
Color.FromHex("6baed6"), Color.FromHex("3182bd"),
Color.FromHex("08519c"),
},
new[]
{
Color.FromHex("eff3ff"), Color.FromHex("c6dbef"), Color.FromHex("9ecae1"),
Color.FromHex("6baed6"), Color.FromHex("4292c6"),
Color.FromHex("2171b5"), Color.FromHex("084594"),
},
new[]
{
Color.FromHex("f7fbff"), Color.FromHex("deebf7"), Color.FromHex("c6dbef"),
Color.FromHex("9ecae1"), Color.FromHex("6baed6"),
Color.FromHex("4292c6"), Color.FromHex("2171b5"), Color.FromHex("084594"),
},
new[]
{
Color.FromHex("f7fbff"), Color.FromHex("deebf7"), Color.FromHex("c6dbef"),
Color.FromHex("9ecae1"), Color.FromHex("6baed6"),
Color.FromHex("4292c6"), Color.FromHex("2171b5"), Color.FromHex("08519c"),
Color.FromHex("08306b"),
},
},
};

public Palette Greens { get; } = new Palette
{
Label = "Greens",
Type1 = Type.SequentialSingleHue,
Colors = new List<Color[]>
{
new[] { Color.FromHex("e5f5e0"), Color.FromHex("a1d99b"), Color.FromHex("31a354") },
new[]
{
Color.FromHex("edf8e9"), Color.FromHex("bae4b3"), Color.FromHex("74c476"),
Color.FromHex("238b45")
},
new[]
{
Color.FromHex("edf8e9"), Color.FromHex("bae4b3"), Color.FromHex("74c476"),
Color.FromHex("31a354"), Color.FromHex("006d2c")
},
new[]
{
Color.FromHex("edf8e9"), Color.FromHex("c7e9c0"), Color.FromHex("a1d99b"),
Color.FromHex("74c476"), Color.FromHex("31a354"),
Color.FromHex("006d2c"),
},
new[]
{
Color.FromHex("edf8e9"), Color.FromHex("c7e9c0"), Color.FromHex("a1d99b"),
Color.FromHex("74c476"), Color.FromHex("41ab5d"),
Color.FromHex("238b45"), Color.FromHex("005a32"),
},
new[]
{
Color.FromHex("f7fcf5"), Color.FromHex("e5f5e0"), Color.FromHex("c7e9c0"),
Color.FromHex("a1d99b"), Color.FromHex("74c476"),
Color.FromHex("41ab5d"), Color.FromHex("238b45"), Color.FromHex("005a32"),
},
new[]
{
Color.FromHex("f7fcf5"), Color.FromHex("e5f5e0"), Color.FromHex("c7e9c0"),
Color.FromHex("a1d99b"), Color.FromHex("74c476"),
Color.FromHex("41ab5d"), Color.FromHex("238b45"), Color.FromHex("006d2c"),
Color.FromHex("00441b"),
},
},
};

public Palette Oranges { get; } = new Palette
{
Label = "Oranges",
Type1 = Type.SequentialSingleHue,
Colors = new List<Color[]>
{
new[] { Color.FromHex("fee6ce"), Color.FromHex("fdae6b"), Color.FromHex("e6550d") },
new[]
{
Color.FromHex("feedde"), Color.FromHex("fdbe85"), Color.FromHex("fd8d3c"),
Color.FromHex("d94701")
},
new[]
{
Color.FromHex("feedde"), Color.FromHex("fdbe85"), Color.FromHex("fd8d3c"),
Color.FromHex("e6550d"), Color.FromHex("a63603")
},
new[]
{
Color.FromHex("feedde"), Color.FromHex("fdd0a2"), Color.FromHex("fdae6b"),
Color.FromHex("fd8d3c"), Color.FromHex("e6550d"),
Color.FromHex("a63603"),
},
new[]
{
Color.FromHex("feedde"), Color.FromHex("fdd0a2"), Color.FromHex("fdae6b"),
Color.FromHex("fd8d3c"), Color.FromHex("f16913"),
Color.FromHex("d94801"), Color.FromHex("8c2d04"),
},
new[]
{
Color.FromHex("fff5eb"), Color.FromHex("fee6ce"), Color.FromHex("fdd0a2"),
Color.FromHex("fdae6b"), Color.FromHex("fd8d3c"),
Color.FromHex("f16913"), Color.FromHex("d94801"), Color.FromHex("8c2d04"),
},
new[]
{
Color.FromHex("fff5eb"), Color.FromHex("fee6ce"), Color.FromHex("fdd0a2"),
Color.FromHex("fdae6b"), Color.FromHex("fd8d3c"),
Color.FromHex("f16913"), Color.FromHex("d94801"), Color.FromHex("a63603"),
Color.FromHex("7f2704"),
},
},
};

public Palette Reds { get; } = new Palette
{
Label = "Reds",
Type1 = Type.SequentialSingleHue,
Colors = new List<Color[]>
{
new[] { Color.FromHex("fee0d2"), Color.FromHex("fc9272"), Color.FromHex("de2d26") },
new[]
{
Color.FromHex("fee5d9"), Color.FromHex("fcae91"), Color.FromHex("fb6a4a"),
Color.FromHex("cb181d")
},
new[]
{
Color.FromHex("fee5d9"), Color.FromHex("fcae91"), Color.FromHex("fb6a4a"),
Color.FromHex("de2d26"), Color.FromHex("a50f15")
},
new[]
{
Color.FromHex("fee5d9"), Color.FromHex("fcbba1"), Color.FromHex("fc9272"),
Color.FromHex("fb6a4a"), Color.FromHex("de2d26"),
Color.FromHex("a50f15"),
},
new[]
{
Color.FromHex("fee5d9"), Color.FromHex("fcbba1"), Color.FromHex("fc9272"),
Color.FromHex("fb6a4a"), Color.FromHex("ef3b2c"),
Color.FromHex("cb181d"), Color.FromHex("99000d"),
},
new[]
{
Color.FromHex("fff5f0"), Color.FromHex("fee0d2"), Color.FromHex("fcbba1"),
Color.FromHex("fc9272"), Color.FromHex("fb6a4a"),
Color.FromHex("ef3b2c"), Color.FromHex("cb181d"), Color.FromHex("99000d"),
},
new[]
{
Color.FromHex("fff5f0"), Color.FromHex("fee0d2"), Color.FromHex("fcbba1"),
Color.FromHex("fc9272"), Color.FromHex("fb6a4a"),
Color.FromHex("ef3b2c"), Color.FromHex("cb181d"), Color.FromHex("a50f15"),
Color.FromHex("67000d"),
},
},
};

public Palette Grays { get; } = new Palette
{
Label = "Greys",
Type1 = Type.SequentialSingleHue,
Colors = new List<Color[]>
{
new[] { Color.FromHex("f0f0f0"), Color.FromHex("bdbdbd"), Color.FromHex("636363") },
new[]
{
Color.FromHex("f7f7f7"), Color.FromHex("cccccc"), Color.FromHex("969696"),
Color.FromHex("525252")
},
new[]
{
Color.FromHex("f7f7f7"), Color.FromHex("cccccc"), Color.FromHex("969696"),
Color.FromHex("636363"), Color.FromHex("252525")
},
new[]
{
Color.FromHex("f7f7f7"), Color.FromHex("d9d9d9"), Color.FromHex("bdbdbd"),
Color.FromHex("969696"), Color.FromHex("636363"),
Color.FromHex("252525"),
},
new[]
{
Color.FromHex("f7f7f7"), Color.FromHex("d9d9d9"), Color.FromHex("bdbdbd"),
Color.FromHex("969696"), Color.FromHex("737373"),
Color.FromHex("525252"), Color.FromHex("252525"),
},
new[]
{
Color.FromHex("ffffff"), Color.FromHex("f0f0f0"), Color.FromHex("d9d9d9"),
Color.FromHex("bdbdbd"), Color.FromHex("969696"),
Color.FromHex("737373"), Color.FromHex("525252"), Color.FromHex("252525"),
},
new[]
{
Color.FromHex("ffffff"), Color.FromHex("f0f0f0"), Color.FromHex("d9d9d9"),
Color.FromHex("bdbdbd"), Color.FromHex("969696"),
Color.FromHex("737373"), Color.FromHex("525252"), Color.FromHex("252525"),
Color.FromHex("000000"),
},
},
};
}
}
}
26 changes: 16 additions & 10 deletions src/Acoustics.Shared/ImageSharp/Drawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Acoustics.Shared.ImageSharp
{
using System.Runtime.CompilerServices;
using SixLabors.Fonts;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
Expand Down Expand Up @@ -44,17 +43,10 @@ public static class Drawing
Antialias = false,
ColorBlendingMode = PixelColorBlendingMode.Normal,
AntialiasSubpixelDepth = 0,

//IntersectionRule = IntersectionRule.OddEven,
};

//public static readonly ShapeGraphicsOptions NoAntiAlias = new ShapeGraphicsOptions()
//{
// BlendPercentage = 1,
// Antialias = false,
// ColorBlendingMode = PixelColorBlendingMode.Normal,
// AntialiasSubpixelDepth = 0,
//};

private const string Tahoma = "Tahoma";
private const string Arial = "Arial";

Expand Down Expand Up @@ -117,11 +109,25 @@ public void DrawLine(IPen pen, params PointF[] points)
}

this.context.DrawLines(
Drawing.NoAntiAlias,
NoAntiAlias,
pen,
points);
}

public void DrawLine(Color color, float thickness, params PointF[] points)
{
for (int i = 0; i < points.Length; i++)
{
points[i].Offset(Offset);
}

this.context.DrawLines(
NoAntiAlias,
color,
thickness,
points);
}

public void DrawRectangle(Pen pen, int x1, int y1, int x2, int y2)
{
var r = RectangleF.FromLTRB(x1, y1, x2, y2);
Expand Down
Loading

0 comments on commit 7b4ef82

Please sign in to comment.