开发者

Pattern Recognition for image comparision in .net

开发者 https://www.devze.com 2022-12-30 10:28 出处:网络
Can anybody share code or algorithm(using pattern recognition) for image comparision in.net.开发者_StackOverflow社区

Can anybody share code or algorithm(using pattern recognition) for image comparision in .net.开发者_StackOverflow社区

I need to compare 2 images of different resolution and textures and the find the difference . Now i have code to find the difference between 2 images using C#

// Load the images.
Bitmap bm1 =  (Bitmap) (Image.FromFile(txtFile1.Text));
Bitmap bm2 =  (Bitmap) (Image.FromFile(txtFile2.Text));

// Make a difference image.
int wid = Math.Min(bm1.Width, bm2.Width);
int hgt = Math.Min(bm1.Height, bm2.Height);
Bitmap bm3 = new Bitmap(wid, hgt);

// Create the difference image.
bool are_identical = true;
int r1;
int g1;
int b1;
int r2;
int g2;
int b2;
int r3;
int g3;
int b3;
Color eq_color = Color.Transparent;
Color ne_color = Color.Transparent;
for (int x = 0; x <= wid - 1; x++)
{
    for (int y = 0; y <= hgt - 1; y++)
    {
        if (bm1.GetPixel(x, y).Equals(bm2.GetPixel(x, y)))
        {
            bm3.SetPixel(x, y, eq_color);
        }
        else
        {
            bm1.SetPixel(x, y, ne_color);
            are_identical = false;
        }
    }
}

// Display the result.
picResult.Image = bm1;

    Bitmap Logo = new Bitmap(picResult.Image);
    Logo.MakeTransparent(Logo.GetPixel(1, 1));
    picResult.Image = (Image)Logo;

//this.Cursor = Cursors.Default;
if ((bm1.Width != bm2.Width) || (bm1.Height != bm2.Height))
{
    are_identical = false;
}
if (are_identical)
{
    MessageBox.Show("The images are identical");
}
else
{
    MessageBox.Show("The images are different");
}

//bm1.Dispose()
// bm2.Dispose()

BUT this compare if the 2 images are of same resolution and size.if some shadow is there on one image(but the 2 images are same) it shows the difference between the image..so i am trying to compare using pattern recognition.


As nailxx said, there is no "100% working free code" or something. Some years ago I helped implementing a "face recognition" app, and one of the things we used was "Locale binary patterns". Its not too easy, but it gave quite good results. Find a paper about it here: Local binary patterns

Edit: I'm afraid I can't find the paper that I have used these days, it was shorter and fixed on the LBP itself and not how to use it with textures.


Your request is a really complex scientific (not even engineering) task. The basic obvious algorithm is the following:

  1. Somehow select all object on both comparing images. This part is relatively simple and can be solved in many ways.

  2. Compare all objects. This part is a task for scientists, considering the fact that they can be shifted, rotated, resized, and so on. :) However, this can be solved in the case of you have a fixed number of entities to recognize. Like "circle", "triangle","rectange","line".

0

精彩评论

暂无评论...
验证码 换一张
取 消