public void GrayscaleImage() { using (var image = ImageUtils.GrayscaleImage(ImageUtils.ReduceImage(ImageFullSize, 9, 8))) { image.Save( IOUtils.MapServerPath("~/Images/Alyson-9x8-Gray-Generated.jpg"), ImageFormat.Jpeg); } Image grayscaleImage = Image.FromFile(IOUtils.MapServerPath( "~/Images/Alyson-9x8-Gray-Generated.jpg")); Image expectedImage = Image.FromFile(IOUtils.MapServerPath( "~/Images/Alyson-9x8-Gray.jpg")); ulong grayscaleImageHash = ImageHasher.ComputeDifferenceHash(grayscaleImage); ulong expectedImageHash = ImageHasher.ComputeDifferenceHash(expectedImage); Assert.That(grayscaleImageHash, Is.EqualTo(expectedImageHash)); double similarity = ImageHasher.ComputeSimilarity(grayscaleImageHash, expectedImageHash); int distance = ImageHasher.ComputeHammingDistance(grayscaleImageHash, expectedImageHash); Assert.That(similarity, Is.EqualTo(1.0)); Assert.That(distance, Is.EqualTo(0)); }
public void ComputeHammingDistanceWithDifferenceHash() { ulong imageHashB = ImageHasher.ComputeDifferenceHash(ImageB); ulong imageHashC = ImageHasher.ComputeDifferenceHash(ImageC); int distanceBB = ImageHasher.ComputeHammingDistance(imageHashB, imageHashB); int distanceBC = ImageHasher.ComputeHammingDistance(imageHashB, imageHashC); Assert.That(distanceBB, Is.EqualTo(0)); Assert.That(distanceBC, Is.EqualTo(1)); }
public void ComputeHammingDistanceWithAverageHash() { ulong imageHashA = ImageHasher.ComputeAverageHash(ImageA); ulong imageHashC = ImageHasher.ComputeAverageHash(ImageC); int distanceAA = ImageHasher.ComputeHammingDistance(imageHashA, imageHashA); int distanceAC = ImageHasher.ComputeHammingDistance(imageHashA, imageHashC); Assert.That(distanceAA, Is.EqualTo(0)); Assert.That(distanceAC, Is.EqualTo(10)); }
static void Main(string[] args) { if (args == null || args.Length < 2) { Console.WriteLine("not enough arguments"); } else if (!File.Exists(args[0])) { Console.WriteLine("{0} does not exist", args[0]); } else if (!File.Exists(args[1])) { Console.WriteLine("{0} does not exist", args[1]); } else { string imageAPath = args[0]; string imageBPath = args[1]; Image imageA = null; Image imageB = null; try { imageA = Image.FromFile(imageAPath); imageB = Image.FromFile(imageBPath); } catch (Exception e) { Console.WriteLine(e.Message); } if (imageA != null && imageB != null) { ulong imageAHash = ImageHasher.ComputeDifferenceHash(imageA); ulong imageBHash = ImageHasher.ComputeDifferenceHash(imageB); Console.WriteLine( "{0}: {1}", Path.GetFileName(imageAPath), imageAHash); Console.WriteLine( "{0}: {1}", Path.GetFileName(imageBPath), imageBHash); Console.WriteLine( "Similarity: {0}", ImageHasher.ComputeSimilarity(imageAHash, imageBHash)); Console.WriteLine( "Hamming Distance: {0}", ImageHasher.ComputeHammingDistance(imageAHash, imageBHash)); } } }