-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves image testing and test output directories
- No longer uses random directories for test output - No longer places file output for tests in deploy directory (it is now placed in the MSTest standard results directory `TestResults` which is a sibling of the solution) - OutputDirectoryTest will now place test output in a folder named after the class being tests (named `ClassOutputDirectory`) - OutputDirectoryTest will now place test output for individual tests first in a folder named after the test class, and second in a subfolder for the specific test (named TestOutputDirectory`) - It is hoped we'll move more to using ClassOutputDirectory over TestOutputDirectory as it will reduce IO and folder spam - MSTest automatically deletes output when all tests pass, so removed the MSBuild task that did extra cleaning of binary output directory (because we used to stick output in there when we should not have) - Added an `GeneratedImageTest` that inherits from `OutputDirectoryTest` (and all the aforementioned new behaviours). GeneratedImageTest is a helper class that will automatically name and save both actual and expected test images, as well as produce delta images that show where pixels differ between actual and expected! - We also add delta image processors and pixel blender to power aforementioned delta image functionality
- Loading branch information
Showing
27 changed files
with
585 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// <copyright file="DeltaImageProcessor.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.ImageSharp | ||
{ | ||
using System; | ||
using SixLabors.ImageSharp; | ||
using SixLabors.ImageSharp.Advanced; | ||
using SixLabors.ImageSharp.Advanced.ParallelUtils; | ||
using SixLabors.ImageSharp.Memory; | ||
using SixLabors.ImageSharp.PixelFormats; | ||
using SixLabors.ImageSharp.Processing.Processors; | ||
|
||
public class DeltaImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg> | ||
where TPixelBg : struct, IPixel<TPixelBg> | ||
where TPixelFg : struct, IPixel<TPixelFg> | ||
{ | ||
public DeltaImageProcessor( | ||
Configuration configuration, | ||
Image<TPixelFg> image, | ||
Image<TPixelBg> source, | ||
Rectangle sourceRectangle) | ||
: base(configuration, source, sourceRectangle) | ||
{ | ||
this.Image = image; | ||
this.Blender = new DeltaPixelBlender<TPixelBg>(); | ||
} | ||
|
||
public DeltaPixelBlender<TPixelBg> Blender { get; } | ||
|
||
public Image<TPixelFg> Image { get; } | ||
|
||
protected override void OnFrameApply(ImageFrame<TPixelBg> source) | ||
{ | ||
var targetBounds = this.Image.Bounds(); | ||
var sourceBounds = this.Source.Bounds(); | ||
var maxWidth = Math.Min(targetBounds.Width, sourceBounds.Width); | ||
|
||
void Apply(RowInterval rows) | ||
{ | ||
for (int min = rows.Min; min < rows.Max; ++min) | ||
{ | ||
Span<TPixelBg> destination = source.GetPixelRowSpan<TPixelBg>(min).Slice(0, maxWidth); | ||
Span<TPixelFg> span = this.Image.GetPixelRowSpan<TPixelFg>(min).Slice(0, maxWidth); | ||
this.Blender.Blend<TPixelFg>( | ||
this.Configuration, | ||
destination, | ||
(ReadOnlySpan<TPixelBg>)destination, | ||
(ReadOnlySpan<TPixelFg>)span, | ||
1f); | ||
} | ||
} | ||
|
||
ParallelHelper.IterateRows(this.SourceRectangle, this.Configuration, Apply); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Acoustics.Shared/ImageSharp/DeltaImageProcessor{TPixelFg}.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// <copyright file="DeltaImageProcessor{TPixelFg}.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.ImageSharp | ||
{ | ||
using SixLabors.ImageSharp; | ||
using SixLabors.ImageSharp.PixelFormats; | ||
using SixLabors.ImageSharp.Processing.Processors; | ||
|
||
public class DeltaImageProcessor<TPixelFg> : IImageProcessor | ||
where TPixelFg : struct, IPixel<TPixelFg> | ||
{ | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DeltaImageProcessor{TPixelFg}"/> class. | ||
/// </summary> | ||
/// <param name="image">The image to blend.</param> | ||
public DeltaImageProcessor( | ||
Image<TPixelFg> image) | ||
{ | ||
this.Image = image; | ||
} | ||
|
||
public Image<TPixelFg> Image { get; } | ||
|
||
public IImageProcessor<TPixelBg> CreatePixelSpecificProcessor<TPixelBg>(Configuration configuration, Image<TPixelBg> source, Rectangle sourceRectangle) | ||
where TPixelBg : struct, IPixel<TPixelBg> | ||
{ | ||
return new DeltaImageProcessor<TPixelBg, TPixelFg>(Configuration.Default, this.Image, source, sourceRectangle); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// <copyright file="DeltaPixelBlender.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.ImageSharp | ||
{ | ||
using System; | ||
using System.Numerics; | ||
using System.Runtime.CompilerServices; | ||
using SixLabors.ImageSharp.PixelFormats; | ||
|
||
/// <summary> | ||
/// Blends pixels based on their differences. | ||
/// Pixels that are equal return gray. | ||
/// Pixels where the source is less than backdrop return black. | ||
/// Pixels where the source is greater than the backdrop return white. | ||
/// </summary> | ||
/// <typeparam name="TPixel">The type of pixel to operate on.</typeparam> | ||
public class DeltaPixelBlender<TPixel> : PixelBlender<TPixel> | ||
where TPixel : struct, IPixel<TPixel> | ||
{ | ||
private static readonly Vector4 Middle = new Vector4(0.5f); | ||
private static readonly Vector4 Bottom = new Vector4(0.0f); | ||
private static readonly Vector4 Top = new Vector4(1.0f); | ||
|
||
public override TPixel Blend(TPixel background, TPixel source, float amount) | ||
{ | ||
TPixel dest = default; | ||
|
||
dest.FromScaledVector4(Delta(background.ToScaledVector4(), source.ToScaledVector4(), amount)); | ||
|
||
return dest; | ||
} | ||
|
||
protected override void BlendFunction(Span<Vector4> destination, ReadOnlySpan<Vector4> background, | ||
ReadOnlySpan<Vector4> source, float amount) | ||
{ | ||
amount = amount.Clamp(0, 1); | ||
for (int i = 0; i < destination.Length; i++) | ||
{ | ||
destination[i] = Delta(background[i], source[i], amount); | ||
} | ||
} | ||
|
||
protected override void BlendFunction(Span<Vector4> destination, ReadOnlySpan<Vector4> background, | ||
ReadOnlySpan<Vector4> source, ReadOnlySpan<float> amount) | ||
{ | ||
for (int i = 0; i < destination.Length; i++) | ||
{ | ||
destination[i] = Delta(background[i], source[i], amount[i].Clamp(0, 1)); | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private static Vector4 Delta(Vector4 backdrop, Vector4 source, float amount) | ||
{ | ||
if (backdrop == source) | ||
{ | ||
return Middle; | ||
} | ||
|
||
return source.LengthSquared() < backdrop.LengthSquared() ? Bottom : Top; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.