'How to check for duplicate images ? C#

So guys that's what i have.

I have a 1 folder with around 30k pictures (a old backup from long time ago) and second folder used as the current backup.

so I just wanted to check if in the first folder I got pictures that I don't have in the second folder.. and if i got picture in folder 1 that I already have in folder 2 so it will be deleted from folder 1.

I thought maybe I should compare between the size on disk of 1 picture from folder 1 against all the pictures in folder 2. (with 2 for loops)

but I saw that I have 2 different pictures with the exact size (size on disk). so I can't really use it.

anyone got idea how should i do it? (remember that i got around 30k photos in folder 1 so the algorithm should be efficient)ץ

got diffrent hash for same picture. :

            using (var md5 = MD5.Create())
        {
            using (var stream = File.OpenRead("C:/Users/Sam/Desktop/1.jpg"))
            {
                Console.WriteLine(BitConverter.ToString(md5.ComputeHash(stream)));
            }
           using (var stream2 = File.OpenRead("C:/Users/Sam/Desktop/2.jpg"))
            {
                Console.WriteLine(BitConverter.ToString(md5.ComputeHash(stream2)));
            }
        }

Hi i did use this algoritem : Algorithm to compare two images in C#

but it's take too slow. (takes about 2-3 sec to compare 1 image to 100 others so its gonna be forever to compare all the images (around 30k) )..



Solution 1:[1]

Here's a couple of open source C# projects that do image comparison.

https://github.com/xnafan/Simple-image-comparison

https://github.com/ukushu/ImgComparator

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TripleAntigen