I am sorry, my previous IDs have running of daily post quota....
QUOTE(weisinx7 @ Mar 11 2020, 02:54 PM)
Thanks for trying out, do you mind to share your code?
Right now my constraint is to find the suitable evaluation metric, as i can find the edges, filtered value and etc, but to give a score on the similarity, that is still a problem, since the score need to be work on all cases
Yeah, I am having difficulty calculate the percentage of similarity also (out of number of dots matched).
Bmp1
Bmp2
Bmp3
Bmp4
Bmp5
Please note that the code doesn't work well with image with different height (different width is okay, as it will resize it to 600 pixels)
Please do note the following
CODE
if (((Bitmap1Inverted[y * x] == Bitmap2Inverted[y * x])) && (Bitmap1Inverted[y * x] ==255))
SimilarityInverted++;
The number of dots matched will calculate those black dots if found in two images.
You can play around with threshold to higher value or lower value....... I hope it can be somewhat useful for you, though bitmap comparison is somewhat lower-class....
CODE
using System;
using System.Drawing;
namespace CMPBMP
{
class Program
{
static void Main(string[] args)
{
Bitmap Bmp1 = new Bitmap("C:\\bmp2.png");
Bitmap Bmp2 = new Bitmap("C:\\bmp5.png");
var Threshold = 100; // Any value between 0 ..255
double Multiplier = 600; // New size of bitmap width
double Scale = (double)(Multiplier / (double)Bmp1.Width);
int NewHeight1 = (int)(Bmp1.Height * Scale);
int NewWidth1 = (int)(Bmp1.Width * Scale);
byte[] Bitmap1 = new byte[NewWidth1 * NewHeight1];
byte[] Bitmap1Inverted = new byte[NewWidth1 * NewHeight1];
int NumberOfInvertedDots = 0;
for (var y = 0; y < NewHeight1; y++)
{
for (var x = 0; x < NewWidth1; x++)
{
var _x = (int)(x / Scale);
var _y = (int)(y / Scale);
var Color = Bmp1.GetPixel(_x, _y);
var Luminance = (byte)(Color.R * 0.3 + Color.G * 0.59 + Color.B * 0.11);
if (Luminance < Threshold)
{
Bitmap1Inverted[_x * _y] = 0;
Bitmap1[_x * _y] = 255;
}
else
{
Bitmap1Inverted[_x * _y] = 255;
NumberOfInvertedDots++;
Bitmap1[_x * _y] = 0;
};
//Bitmap1Inverted[_x * _y] = Luminance;
}
}
Scale = (double)(Multiplier / (double)Bmp2.Width);
int NewHeight2 = (int)(Bmp2.Height * Scale);
int NewWidth2 = (int)(Bmp2.Width * Scale);
byte[] Bitmap2 = new byte[NewWidth2 * NewHeight2];
byte[] Bitmap2Inverted = new byte[NewWidth2 * NewHeight2];
for (var y = 0; y < NewHeight2; y++)
{
for (var x = 0; x < NewWidth2; x++)
{
var _x = (int)(x / Scale);
var _y = (int)(y / Scale);
var Color = Bmp2.GetPixel(_x, _y);
var Luminance = (byte)(Color.R * 0.3 + Color.G * 0.59 + Color.B * 0.11);
if (Luminance < Threshold)
{
Bitmap2Inverted[_x * _y] = 0;
Bitmap2[_x * _y] = 255;
}
else
{
Bitmap2Inverted[_x * _y] = 255;
Bitmap2[_x * _y] = 0;
};
//Bitmap2Inverted[_x * _y] = Luminance;
}
}
int NewHeight = NewHeight1 > NewHeight2 ? NewHeight2 : NewHeight1;
double Similarity = 0;
double SimilarityInverted = 0;
for (int y = 0; y < NewHeight; y++)
for (int x = 0; x < NewWidth1; x++)
{
if (Bitmap1[y * x] == Bitmap2[y * x])
Similarity++;
if (((Bitmap1Inverted[y * x] == Bitmap2Inverted[y * x])) && (Bitmap1Inverted[y * x] ==255))
SimilarityInverted++;
}
Console.WriteLine("Similarity (Bitmap) = " + ((Similarity / (NewHeight * NewWidth1)) * 100).ToString("F2") + "%");
Console.WriteLine("Number of dots matched (Inverted Bitmap) = " + SimilarityInverted.ToString("F2"));
Console.ReadLine();
}
}
}