-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathProgram.cs
93 lines (83 loc) · 2.61 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Drawing;
using CommonUtils;
namespace Imghash
{
public class Program
{
// http://stackoverflow.com/questions/7395836/converting-from-bitstring-to-integer
// http://stackoverflow.com/questions/4777070/hamming-distance-on-binary-strings-in-sql
// http://www.fftw.org/doc/Real_002dto_002dReal-Transform-Kinds.html
public static void HashTester(string[] args)
{
if(args.Length == 1)
{
Bitmap theImage = new Bitmap(1,1);
try
{
theImage = new Bitmap(args[0]);
}
catch(Exception)
{
Console.WriteLine("Couldn't open the image " + args[0] + ".");
return;
}
//ulong hash1 = ImageAverageHash.AverageHash(theImage);
//Console.WriteLine(hash1.ToString("x16") + "\t" + args[0]);
ImagePHash phash = new ImagePHash(64,16);
string hash1s = phash.GetHash(theImage);
Console.WriteLine(hash1s + "\t" + args[0]);
}
else if(args.Length == 2)
{
Bitmap theImage = new Bitmap(1,1);
Bitmap theOtherImage = new Bitmap(1,1);
try
{
theImage = new Bitmap(args[0]);
}
catch(Exception)
{
Console.WriteLine("Couldn't open the image " + args[0] + ".");
return;
}
try
{
theOtherImage = new Bitmap(args[1]);
}
catch(Exception)
{
Console.WriteLine("Couldn't open the image " + args[1] + ".");
return;
}
/*
ulong hash1 = ImageAverageHash.AverageHash(theImage);
ulong hash2 = ImageAverageHash.AverageHash(theOtherImage);
Console.WriteLine(hash1.ToString("x16") + "\t" + args[0]);
Console.WriteLine(hash2.ToString("x16") + "\t" + args[1]);
Console.WriteLine("Similarity: " + ImageAverageHash.Similarity(hash1, hash2) + "%");
Console.WriteLine("\n\n");
*/
ImagePHash phash = new ImagePHash(64,16);
string hash1s = phash.GetHash(theImage);
string hash2s = phash.GetHash(theOtherImage);
Console.WriteLine(hash1s + "\t" + args[0]);
Console.WriteLine(hash2s + "\t" + args[1]);
Console.WriteLine("Similarity: {0:00.00} % ", ImagePHash.Similarity(hash1s, hash2s));
/*
ulong hash1p = phash.PHash(theImage);
ulong hash2p = phash.PHash(theOtherImage);
Console.WriteLine(hash1p + "\t" + args[0]);
Console.WriteLine(hash2p + "\t" + args[1]);
Console.WriteLine("Similarity: " + BitCounter.Hamming(hash1p, hash2p) + "");
Console.WriteLine("Similarity: " + ImageAverageHash.Similarity(hash1p, hash2p) + "%");
*/
}
else
{
Console.WriteLine("To get the hash of an image: Imghash.exe <image name>");
Console.WriteLine("To compare two images: Imghash.exe <image 1> <image 2>");
}
}
}
}