Home All Groups Group Topic Archive Search About

How to find equal images?

Author
30 Jun 2006 6:51 PM
Saber
There are some Images (System.Drawing.Image) with same widths and heights,
I want to find if 2 images are equal.
How can I do it?

The following code always returns false:

If  img1.Equals(img2)  Then
   MsgBox("ok!")
Else
   MsgBox("wrong!")
End If

Author
1 Jul 2006 7:52 AM
Michel Posseth [MCP]
> The following code always returns false:

yes because you are checking if the 2 pictures are identical not only in
size but also as image , if there is one bit different set it will return
false although you might not see it with the naked eye


but what you want checking the size can you easily do with a custom function

< not behind my dev pc modus  so check for typo`s >

private function ImgCheckSameSize(byval ImageA as image , ImageB as image )
as boolean

if  (ImageA.Width = ImageB.Width) AndAlso ( ImageA.Height=ImageB.Height)
then
return true
end if
end function

regards

Michel Posseth [MCP]



Show quoteHide quote
"Saber" <saber[.AT.]oxin.ir> schreef in bericht
news:%23LW69YHnGHA.4172@TK2MSFTNGP03.phx.gbl...
> There are some Images (System.Drawing.Image) with same widths and heights,
> I want to find if 2 images are equal.
> How can I do it?
>
> The following code always returns false:
>
> If  img1.Equals(img2)  Then
>   MsgBox("ok!")
> Else
>   MsgBox("wrong!")
> End If
>
>
Author
3 Jul 2006 6:37 PM
Saber
Michel,
I don't want checking the size, as I said, the size of images are exactly
equal,
and the Equals method of Object *always* returns false even when I get the
images from "one" image file.

I think I've to do Andrew's solution and compare the images pixel by pixel.

Thanks

Show quoteHide quote
"Michel Posseth [MCP]" <M***@posseth.com> wrote in message
news:udPcJNOnGHA.620@TK2MSFTNGP05.phx.gbl...
>> The following code always returns false:
>
> yes because you are checking if the 2 pictures are identical not only in
> size but also as image , if there is one bit different set it will return
> false although you might not see it with the naked eye
>
>
> but what you want checking the size can you easily do with a custom
> function
>
> < not behind my dev pc modus  so check for typo`s >
>
> private function ImgCheckSameSize(byval ImageA as image , ImageB as
> image ) as boolean
>
> if  (ImageA.Width = ImageB.Width) AndAlso ( ImageA.Height=ImageB.Height)
> then
> return true
> end if
> end function
>
> regards
>
> Michel Posseth [MCP]
>
>
>
> "Saber" <saber[.AT.]oxin.ir> schreef in bericht
> news:%23LW69YHnGHA.4172@TK2MSFTNGP03.phx.gbl...
>> There are some Images (System.Drawing.Image) with same widths and
>> heights,
>> I want to find if 2 images are equal.
>> How can I do it?
>>
>> The following code always returns false:
>>
>> If  img1.Equals(img2)  Then
>>   MsgBox("ok!")
>> Else
>>   MsgBox("wrong!")
>> End If
>>
>>
>
>
Author
3 Jul 2006 10:20 AM
Andrew Morton
Saber wrote:
> There are some Images (System.Drawing.Image) with same widths and
> heights, I want to find if 2 images are equal.
> How can I do it?
>
> The following code always returns false:
>
> If  img1.Equals(img2)  Then
>   MsgBox("ok!")
> Else
>   MsgBox("wrong!")
> End If

See the help for for System.Drawing.Image.Equals - what it's testing for is
if img1 and img2 point to the same object.

If this is some sort of image-matching game (like
http://en.wikipedia.org/wiki/Concentration_%28game%29) then it will probably
be much better to get the computer to remember which images are the same
instead of comparing them pixel-by-pixel.

Iterating over two images and comparing each value from
System.Drawing.Bitmap.GetPixel could be slow. I suspect there's a quicker
way not using the .net framework. Google could be your friend.

Andrew