1 | initial version |
You can check the following code for FCTH using c# and run exactly. In addition stored in the "postgresql" database
static class Program
{
static private double TanimotoClassifier(double[] Table1, double[] Table2)
{
double Result = 0;
double Temp1 = 0;
double Temp2 = 0;
double TempCount1 = 0, TempCount2 = 0, TempCount3 = 0;
for (int i = 0; i < 192; i++)
{
Temp1 += Table1[i];
Temp2 += Table2[i];
}
if (Temp1 == 0 || Temp2 == 0) Result = 100;
if (Temp1 == 0 && Temp2 == 0) Result = 0;
if (Temp1 > 0 && Temp2 > 0)
{
for (int i = 0; i < 192; i++)
{
TempCount1 += (Table1[i] / Temp1) * (Table2[i] / Temp2);
TempCount2 += (Table2[i] / Temp2) * (Table2[i] / Temp2);
TempCount3 += (Table1[i] / Temp1) * (Table1[i] / Temp1);
}
Result = (100 - 100 * (TempCount1 / (TempCount2 + TempCount3 - TempCount1)));
}
return (Result);
}
static void Main()
{
string connectionString = "Server=localhost;port=5432;Database=dbtest;User ID=postgres;Password=123";
NpgsqlConnection dbcon = new NpgsqlConnection(connectionString);
dbcon.Open();
NpgsqlCommand dbcmd = dbcon.CreateCommand();
double TotalDeviation = 0; // Here you will store the deviation of the images (pairwise)
double[] FCTHTable_Source = new double[192];
double[] FCTHTable_ToCompare = new double[192];
Bitmap ImageData1 = new Bitmap("E:\\nf\\aa.jpg");
Bitmap ImageData2 = new Bitmap("E:\\nf\\ee.jpg");
FCTH GetFCTH = new FCTH();
FCTHTable_Source = GetFCTH.Apply(ImageData1, 2);
FCTHTable_ToCompare = GetFCTH.Apply(ImageData2, 2);
TotalDeviation = TanimotoClassifier(FCTHTable_ToCompare, FCTHTable_Source); // We are Using Tanimoto in order to Compare Images
try
{
string sql1 = "INSERT INTO tbtest(dev) VALUES (" + TotalDeviation + ")";
dbcmd.CommandText = sql1;
dbcmd.ExecuteNonQuery();
}
catch (NpgsqlException ex)
{
if (ex.Data == null)
{
throw;
}
else
{
}
}
}
}