×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Compare two images in Java

Compare two images in Java

Compare two images in Java

(OP)
Hi,
   I'm trying to compare 2 images to see if they are the exact same or not ....

I'm assuming I would have to compare the bytes representation of the 2 images.  I cannot find any methods in the Image, BufferedImage etc classes to get the bytes of the image.

Can anyone help?

Thanks-in-advance.


RE: Compare two images in Java

I think you would do it like this :

CODE

BufferedImage bi ...

Raster r = bi.getData();
DataBuffer db = r.getDataBuffer();
int size = db.getSize();

for (int i = 0; i < size; i++) {
  int px = db.getElem(i);
}

The first thing to do would be to check that the size of the data buffer are the same for both images, and then if they are, compare both images in the for loop.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
http://www.primrose.org.uk

RE: Compare two images in Java

(OP)


How do I initialize BufferedImage from a pre-existing image saved on the computer hardrive.  e.g, C:\test.jpg .

There doesn't seem to be a filename or path parameter in any of the constructors, or other methods.


Thanks.

Waseem

RE: Compare two images in Java

BufferedImage bi = ImageIO.read(new File("bla.jpg"));

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
http://www.primrose.org.uk

RE: Compare two images in Java

(OP)

Thanks - this works!!!

One more question.  Do you know where in the data buffer for the image is the information for the background color of the image stored.  


RE: Compare two images in Java

I think it is in the ColorModel for the Raster - just read the API documentation for the classes used - you should find your information there.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
http://www.primrose.org.uk

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login