Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2005

Tip: Looking for answers? Try searching our database.

fast image compare?

Thread view: 
Darrel Riekhof - 04 Jan 2005 03:20 GMT
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
Andrey Kuznetsov - 04 Jan 2005 13:34 GMT
> Whats the best way to compare 2 images to see if they are exactley the
> same?
[quoted text clipped - 4 lines]
> 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

Signature

Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Antti S. Brax - 04 Jan 2005 14:32 GMT
spam0@imagero.com.invalid wrote in comp.lang.java.gui:
>> Whats the best way to compare 2 images to see if they are exactley the
>> same?
<snip>
> you could compare say 1000 random choosed pixels

    ...and get random results

Signature

Antti S. Brax                  Rullalautailu pitää lapset poissa ladulta
http://www.iki.fi/asb/         http://www.cs.helsinki.fi/u/abrax/hlb/
       "Disconnect this cable to shorten, re-connect to lengthen."
         -- Instructions on Logitech's USB mouse extension cord.

Andrey Kuznetsov - 04 Jan 2005 18:13 GMT
>>> Whats the best way to compare 2 images to see if they are exactley the
>>> same?
> <snip>
>> you could compare say 1000 random choosed pixels
>
> ...and get random results

no, because it is just for quick check - if some pixel are different then
you know that images are not same.
Comparing random pixels can help if images has big similar regions.
After that, if all pixels had same value, you can compare pixel for pixel.

Signature

Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Antti S. Brax - 04 Jan 2005 14:29 GMT
    Please set the Followup-To header when crossposting.

riekhof@lvcm.com wrote in comp.lang.java.gui:
> Whats the best way to compare 2 images to see if they are exactley the same?
>
[quoted text clipped - 3 lines]
> 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.

Signature

Antti S. Brax                  Rullalautailu pitää lapset poissa ladulta
http://www.iki.fi/asb/         http://www.cs.helsinki.fi/u/abrax/hlb/
       "Disconnect this cable to shorten, re-connect to lengthen."
         -- Instructions on Logitech's USB mouse extension cord.

Steve Horsley - 04 Jan 2005 19:17 GMT
>     Please set the Followup-To header when crossposting.
>
[quoted text clipped - 14 lines]
>     then comparing them instead of going through an API every
>     time you compare a pixel.

It might be worth checking a few pixcels using the API first - you will
eliminate most non-matching images very quickly, and save many full conversions.
Boudewijn Dijkstra - 05 Jan 2005 11:01 GMT
>> Please set the Followup-To header when crossposting.
>>
[quoted text clipped - 19 lines]
> eliminate most non-matching images very quickly, and save many full
> conversions.

Or use a small byte array of approx. one scan line.
dar7yl - 05 Jan 2005 03:44 GMT
> Whats the best way to compare 2 images to see if they are exactley the
> same?
[quoted text clipped - 6 lines]
>
> 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
Michael Borgwardt - 05 Jan 2005 12:25 GMT
> 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)?
dar7yl - 06 Jan 2005 01:17 GMT
>> 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)?

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.
Michael Borgwardt - 06 Jan 2005 17:42 GMT
>>>You might perform a hash function on each image, and then compare the
>>>resulting hash values.
[quoted text clipped - 9 lines]
> 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.
Andrey Kuznetsov - 08 Jan 2005 15:05 GMT
> 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)

Signature

Andrey Kuznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Mark Murphy - 05 Jan 2005 06:29 GMT
> Whats the best way to compare 2 images to see if they are exactley the same?
>
[quoted text clipped - 5 lines]
>
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.