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));
        }
Beispiel #2
0
        public void ComputeSimilarityWithDifferenceHash()
        {
            ulong imageHashB = ImageHasher.ComputeDifferenceHash(ImageB);
            ulong imageHashC = ImageHasher.ComputeDifferenceHash(ImageC);

            double similarityBB = ImageHasher.ComputeSimilarity(imageHashB, imageHashB);
            double similarityBC = ImageHasher.ComputeSimilarity(imageHashB, imageHashC);

            Assert.That(similarityBB, Is.EqualTo(1.0));
            Assert.That(similarityBC, Is.InRange <double>(0.95, 1.0));
        }
Beispiel #3
0
        public void ComputeSimilarityWithAverageHash()
        {
            ulong imageHashA = ImageHasher.ComputeAverageHash(ImageA);
            ulong imageHashC = ImageHasher.ComputeAverageHash(ImageC);

            double similarityAA = ImageHasher.ComputeSimilarity(imageHashA, imageHashA);
            double similarityAC = ImageHasher.ComputeSimilarity(imageHashA, imageHashC);

            Assert.That(similarityAA, Is.EqualTo(1.0));
            Assert.That(similarityAC, Is.InRange <double>(0.8, 0.85));
        }
Beispiel #4
0
        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));
                }
            }
        }