fast image compare?

D

Darrel Riekhof

Whats the best way to compare 2 images to see if they are exactley the same?

Specifically, a BufferedImage and a sun.awt.windows.WImage.

My plan is to convert the WImage into a BufferedImage. Then verify that
they are the same size. Then iterate thru each pixel rgb value. Is there a
better way?

Tx, Darrel
 
A

Andrey Kuznetsov

Whats the best way to compare 2 images to see if they are exactley the
same?

Specifically, a BufferedImage and a sun.awt.windows.WImage.

My plan is to convert the WImage into a BufferedImage. Then verify that
they are the same size. Then iterate thru each pixel rgb value. Is there
a better way?

you could compare say 1000 random choosed pixels
 
A

Antti S. Brax

Please set the Followup-To header when crossposting.

Whats the best way to compare 2 images to see if they are exactley the same?

Specifically, a BufferedImage and a sun.awt.windows.WImage.

My plan is to convert the WImage into a BufferedImage. Then verify that
they are the same size. Then iterate thru each pixel rgb value. Is there a
better way?

Are you asking for a better way to convert an image to a
BufferedImage or a better algorithm for check the pixels?

I'd recommend converting the images into byte arrays and
then comparing them instead of going through an API every
time you compare a pixel.
 
D

dar7yl

Darrel Riekhof said:
Whats the best way to compare 2 images to see if they are exactley the
same?

Specifically, a BufferedImage and a sun.awt.windows.WImage.

My plan is to convert the WImage into a BufferedImage. Then verify that
they are the same size. Then iterate thru each pixel rgb value. Is there
a better way?

Tx, Darrel

You might perform a hash function on each image, and then compare the
resulting hash values. That might be a problem if both images are
structured differently: you would have to convert each to a common format
first.

regards,
Dar7yl
 
M

Mark Murphy

Darrel said:
Whats the best way to compare 2 images to see if they are exactley the same?

Specifically, a BufferedImage and a sun.awt.windows.WImage.

My plan is to convert the WImage into a BufferedImage. Then verify that
they are the same size. Then iterate thru each pixel rgb value. Is there a
better way?

Tx, Darrel
One way to do this is with Fourier Transform. By comparing the magnitude
and phase of the transform you can determine if one image is the same as
another only under some type of transform such as scale rotation, or
translation.

Here are some sites that may be useful:
http://www.dai.ed.ac.uk/HIPR2/fourier.htm
http://www.mathworks.com/access/helpdesk/help/toolbox/images/transfo5.shtml
http://www.cs.unm.edu/~brayer/vision/fourier.html

Google for:
Fourier-Based Image Registration Techniques &
Fourier-Mellin Transforms for Image Registration

It is popular in research because it has possibilities with image
watermarking as well as image recognition for robots and the like.

Another thing you could to is simply take one image and subtract the
other. This would probably be the easiest. I know Jimage can do this and
I am sure there are alot of others. basically subtract pixel for pixel
and take the absolutes value of the result. The resultant image should
be white were the images match and colored were the images do not.
You can then count the non white pixels or do a image histogram of the
results.

Mark
 
M

Michael Borgwardt

dar7yl said:
You might perform a hash function on each image, and then compare the
resulting hash values.

How do you imagine that to be faster than comparing the actual data
(which you're going to have to do anyway if the hashcodes match)?
 
D

dar7yl

Michael Borgwardt said:
How do you imagine that to be faster than comparing the actual data
(which you're going to have to do anyway if the hashcodes match)?

You just have to choose a hash function that is cheaper than the compare
function you would use. For instance, just add the binary values a raster
line at a time. You can shortcut at any time as well.

Even if you have to repeat the total compare after the hashes match, you
would save time if the number of negative compares is significantly higher
than the postives.

regards,
Dar7yl.
 
M

Michael Borgwardt

dar7yl said:
You just have to choose a hash function that is cheaper than the compare
function you would use. For instance, just add the binary values a raster
line at a time. You can shortcut at any time as well.

Even if you have to repeat the total compare after the hashes match, you
would save time if the number of negative compares is significantly higher
than the postives.

Not if the total compare aborts with a negative result as soon as it
detects a difference, which any sane implementation will do.
 
A

Andrey Kuznetsov

You might perform a hash function on each image, and then compare the
resulting hash values. That might be a problem if both images are
structured differently: you would have to convert each to a common format
first.
for hash function you can use any digest method, e.g. md5.
if your images are in database, you can also save hash values
for every image and this could save you much time...
(because hash computed only once for each image)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top