Esempio n. 1
0
        public PerceptualHash Generate(Image image)
        {
            var crushed = ImageUtil.Resize(image, 8, 8);
            var gray    = ImageUtil.Grayscale(crushed);

#if DEBUG
            Crushed = crushed;
            Gray    = gray;
#endif
            var averageColor = ImageUtil.AverageColor(gray);
            var mean         = (uint)averageColor.ToArgb();
            var hash         = new Bitmap(gray.Width, gray.Height);
            using (var bitmap = new Bitmap(gray))
            {
                for (var x = 0; x < gray.Width; x++)
                {
                    for (var y = 0; y < gray.Height; y++)
                    {
                        var p = (uint)bitmap.GetPixel(x, y).ToArgb();
                        var c = p >= mean ? Color.White : Color.Black;
                        hash.SetPixel(x, y, c);
                    }
                }
            }
            var result = new PerceptualHash {
                Image = hash
            };
            return(result);
        }
Esempio n. 2
0
        public PerceptualHash Generate(Image image)
        {
            var crushed = ImageUtil.Resize(image, 8, 8);
            var gray = ImageUtil.Grayscale(crushed);
#if DEBUG
            Crushed = crushed;
            Gray = gray;
#endif
            var averageColor = ImageUtil.AverageColor(gray);
            var mean = (uint)averageColor.ToArgb();
            var hash = new Bitmap(gray.Width, gray.Height);
            using (var bitmap = new Bitmap(gray))
            {
                for (var x = 0; x < gray.Width; x++)
                {
                    for (var y = 0; y < gray.Height; y++)
                    {
                        var p = (uint)bitmap.GetPixel(x, y).ToArgb();
                        var c = p >= mean ? Color.White : Color.Black;
                        hash.SetPixel(x, y, c);
                    }
                }
            }
            var result = new PerceptualHash { Image = hash };
            return result;
        }
Esempio n. 3
0
 public Number CompareTo(PerceptualHash hash)
 {
     if(hash == null || Image == null || hash.Image == null || Image.Size != hash.Image.Size)
     {
         throw new ArgumentException("Both hashes must have images whose sizes match");
     }
     var left = ImageUtil.ConvertToNumbers(Image);
     var right = ImageUtil.ConvertToNumbers(hash.Image);
     return Distance.Hanning(left, right);
 }
Esempio n. 4
0
        public Number CompareTo(PerceptualHash hash)
        {
            if (hash == null || Image == null || hash.Image == null || Image.Size != hash.Image.Size)
            {
                throw new ArgumentException("Both hashes must have images whose sizes match");
            }
            var left  = ImageUtil.ConvertToNumbers(Image);
            var right = ImageUtil.ConvertToNumbers(hash.Image);

            return(Distance.Hanning(left, right));
        }