Groups | Blog | Home
all groups > c# > march 2006 >

c# : Image Comparison


AJ
3/4/2006 11:26:02 PM
i am making a small application, which acts like a Messenger sort of
thing.

As a part of it, there is a small module in which i need to implement
an image comparison.
am not quite sure of how to proceed.
any guidance in this regard would be well appreciated.


Thanx
AJ
Michael Nemtsev
3/5/2006 12:00:00 AM
Hello AJ,

How do u want compare images?

A> i am making a small application, which acts like a Messenger sort of
A> thing.
A>
A> As a part of it, there is a small module in which i need to implement
A> an image comparison.
A> am not quite sure of how to proceed.
A> any guidance in this regard would be well appreciated.
A> Thanx
A> AJ
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

The Other Nice Man
3/5/2006 2:53:00 AM
What do you mean exactly, do you want to check for duplicate images
that have different file names, duplicate images that are of a
different image type (JPEG and PNG) or image X and image Y are bith
sunsets?

The first would be the easiest, you would need to generate and compare
hash codes for the files.
Mark R. Dawson
3/5/2006 6:21:27 AM
Hi AJ,
if you want to compare two images based on the content of the image i.e.
the value of the pixels you can either load the images into a bitmap
structure and use the GetPixel method to compare the pixel value of each
pixel in each image for equality. This could be slow for large images, since
GetPixel is not very efficient, incase you want to make it faster then you
should use the LockBits method of the Bitmap class. This will provide you
with lightening quick scan time but you have to run it inside an unsafe
region since it is accessing areas of memory, when you do that your program
needs higher privileges to be installed, so that is something you need to
consider.

My basic algorithm would be something like:

1. Are the image dimensions the same -> if no, not equal, if yes keep going
2. Are image formats the same -> if no, not equal, if yes keep going

3. Foreach pixel compare values -> if not same, not equal, if same keep going
4. After all pixels compared and all equal then the images are the same.

For more information on the LockBits method, see:
http://www.bobpowell.net/lockingbits.htm


Mark Dawson
http://www.markdawson.org


[quoted text, click to view]
Kevin Spencer
3/5/2006 10:47:21 AM
To find out if both images are identical, a simple binary comparison of the
files would work better.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

[quoted text, click to view]

AddThis Social Bookmark Button