Skip to content

Commit 5c8f66c

Browse files
committed
Add global histogram equalization test which compares result to reference output
1 parent 274cabf commit 5c8f66c

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class HistogramEqualizationTests
1717
[Theory]
1818
[InlineData(256)]
1919
[InlineData(65536)]
20-
public void HistogramEqualizationTest(int luminanceLevels)
20+
public void GlobalHistogramEqualization_WithDifferentLumanceLevels(int luminanceLevels)
2121
{
2222
// Arrange
2323
var pixels = new byte[]
@@ -45,20 +45,21 @@ public void HistogramEqualizationTest(int luminanceLevels)
4545

4646
var expected = new byte[]
4747
{
48-
0, 12, 53, 32, 146, 53, 174, 53,
49-
57, 32, 12, 227, 219, 202, 32, 154,
50-
65, 85, 93, 239, 251, 227, 65, 158,
51-
73, 146, 146, 247, 255, 235, 154, 130,
52-
97, 166, 117, 231, 243, 210, 117, 117,
53-
117, 190, 36, 190, 178, 93, 20, 170,
54-
130, 202, 73, 20, 12, 53, 85, 194,
55-
146, 206, 130, 117, 85, 166, 182, 215
48+
0, 12, 53, 32, 146, 53, 174, 53,
49+
57, 32, 12, 227, 219, 202, 32, 154,
50+
65, 85, 93, 239, 251, 227, 65, 158,
51+
73, 146, 146, 247, 255, 235, 154, 130,
52+
97, 166, 117, 231, 243, 210, 117, 117,
53+
117, 190, 36, 190, 178, 93, 20, 170,
54+
130, 202, 73, 20, 12, 53, 85, 194,
55+
146, 206, 130, 117, 85, 166, 182, 215
5656
};
5757

5858
// Act
5959
image.Mutate(x => x.HistogramEqualization(new HistogramEqualizationOptions
6060
{
61-
LuminanceLevels = luminanceLevels
61+
LuminanceLevels = luminanceLevels,
62+
Method = HistogramEqualizationMethod.Global
6263
}));
6364

6465
// Assert
@@ -75,6 +76,24 @@ public void HistogramEqualizationTest(int luminanceLevels)
7576
}
7677
}
7778

79+
[Theory]
80+
[WithFile(TestImages.Jpeg.Baseline.HistogramEqImage, PixelTypes.Rgba32)]
81+
public void GlobalHistogramEqualization_CompareToReferenceOutput<TPixel>(TestImageProvider<TPixel> provider)
82+
where TPixel : unmanaged, IPixel<TPixel>
83+
{
84+
using (Image<TPixel> image = provider.GetImage())
85+
{
86+
var options = new HistogramEqualizationOptions
87+
{
88+
Method = HistogramEqualizationMethod.Global,
89+
LuminanceLevels = 256,
90+
};
91+
image.Mutate(x => x.HistogramEqualization(options));
92+
image.DebugSave(provider);
93+
image.CompareToReferenceOutput(ValidatorComparer, provider, extension: "png");
94+
}
95+
}
96+
7897
[Theory]
7998
[WithFile(TestImages.Jpeg.Baseline.LowContrast, PixelTypes.Rgba32)]
8099
public void Adaptive_SlidingWindow_15Tiles_WithClipping<TPixel>(TestImageProvider<TPixel> provider)

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ public static class Bad
196196
public const string YcckSubsample1222 = "Jpg/baseline/ycck-subsample-1222.jpg";
197197
public const string Iptc = "Jpg/baseline/iptc.jpg";
198198
public const string App13WithEmptyIptc = "Jpg/baseline/iptc-psAPP13-wIPTCempty.jpg";
199+
public const string HistogramEqImage = "Jpg/baseline/640px-Unequalized_Hawkes_Bay_NZ.jpg";
199200

200201
public static readonly string[] All =
201202
{
31.7 KB
Loading

0 commit comments

Comments
 (0)