Skip to content

Commit

Permalink
Tweak tolerances to make it more reliable at detecting differences.
Browse files Browse the repository at this point in the history
  • Loading branch information
BlythMeister committed Jul 22, 2020
1 parent b47475c commit 91bddef
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
9 changes: 3 additions & 6 deletions src/BingImageDownload/HistogramHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,16 @@ internal bool Equal(HistogramHash other)
var otherVal = other.Rgb.FirstOrDefault(x => x.X.Equals(val.X) && x.Y.Equals(val.Y));
if (otherVal == null) return false;

var differenceR = Math.Abs(val.R - otherVal.R);
var differenceG = Math.Abs(val.G - otherVal.G);
var differenceB = Math.Abs(val.B - otherVal.B);

if (differenceR > 3 || differenceG > 3 || differenceB > 3)
var difference = Math.Abs(val.RGB - otherVal.RGB);
if (difference > 3)
{
differencesOverTolerance++;
}
}

var differencePercent = differencesOverTolerance / Rgb.Count * 100;

return differencePercent < 1;
return differencePercent < 1f;
}
}
}
2 changes: 1 addition & 1 deletion src/BingImageDownload/ImageHashing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private HistogramHash GetRgbHistogramHash(string filePath)
for (var y = 0; y < image.Height; y++)
{
var pixel = image[x, y];
Rgb.Add(new RgbPixelData(x, y, pixel.R, pixel.G, pixel.B));
Rgb.Add(new RgbPixelData(x, y, pixel.R + pixel.G + pixel.B));
}
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/BingImageDownload/RgbPixelData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ namespace BingImageDownload
{
public class RgbPixelData
{
public byte R { get; }
public byte G { get; }
public byte B { get; }
public int RGB { get; }
public int X { get; }
public int Y { get; }

public RgbPixelData(int x, int y, byte r, byte g, byte b)
public RgbPixelData(int x, int y, int rgb)
{
R = r;
G = g;
B = b;
RGB = rgb;
X = x;
Y = y;
}
Expand Down

0 comments on commit 91bddef

Please sign in to comment.