Pregunta

I am newbie to Image processing. So I might be asking a noob question here.

I am on VS2010, .Net 4, Windows application.

I want to show the differences between two images by rectangles (or any other shape). I tried to refer the class in the link below.

http://www.aforgenet.com/framework/features/template_matching.html

However, the first photo (of Rose with two yello rectangles) is what I really want, the code in the above link tells you what all things match and not the differences. I actually want to find the differences and highlight/draw rectangles around the differences.

I tried the Difference and ThresholdedDifference classes as well in AForge library, but in that I can create a new image which just shows the differences, however, I want to draw rectangles around those differences. I am not sure how to get the coordinates for the differneces to draw rectangles?

Any input on what classes/functions I can use here?

I've tried EyeOpen library but it does not have many options compared to Aforge unless I am missing anything here. I am okay to try any other library other than Aforge.Net in C#.

Regards, Rumit

¿Fue útil?

Solución 2

Let me know if I understand your question correctly: You would like to compare two images and if there is a difference between them then show this difference by drawing rectangle around it.

If this is the only thing you are trying to achieve then I would not use any external libraries and instead I would just compare the images pixel by pixel and then draw a rectangle around the area that doesn't match.

Assuming the two images are the same size, you can use simple loops to get the coordinates of the pixel that is different:

//the images are loaded in Bitmap image1, image2;
for (int x = 0; x < image1.Width; x++)
{
    for (int y = 0; y < image1.Height; y++)
    {
        if (image1.GetPixel(x, y) != image2.GetPixel(x, y))
        {
            posX = x; posY = y; //position of the pixel that is different
        }
    }
}

Then you just draw a rectangle around that pixel specified by posX and posY using DrawRectangle(). If you want to detect all differences you can create an array of pixel coordinates, add item to it every time you discover a difference and afterwards draw rectangles around all of them.

I am afraid using GetPixel() is pretty slow. If you are aiming for speed then I recommend using LockBits() and UnlockBits() for pixel manipulation (see MSDN Library).

Otros consejos

I posted an answer here, which highlights the delta between two images.

enter image description here

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top