Image Diff Algorithm

I have code for the JRPG IDE that creates tilesets. One feature the team has implemented is “tilize”. It takes an images and chops it up into certain sized tiles. Sometimes the tiles will be duplicates and I would like to remove them.

How can I compare two images in code and see if it is visually equal to another image?

If the input image is lossless (gif, png, tga, bmp…) then you can just pull out the pixels and compare em. Once you found a pixel pair which doesn’t match you can stop - the tile is different.

Getting the pixel data can be either done with a PixelGrabber, with (BufferedImage’s) getRaster or with (BufferedImage’s) getRGB.

Keep in mind that you don’t need to check tile B with A if you already checked A with B (similar to collisions).

Eg if there are 4 tiles you need to check:

A vs B, C, D
B vs C, D
C vs D


I think I would do it with getRGB, simply because it’s… heh… simple and because usually the tiles doesn’t match and the loop can be exited at the very begining.

Thanks for the info. I already got something working with PixelGrabber… My images are Images not BufferedImages.
I think its working pretty good though. This should keep the size of my tilesets Down. 8).

want me to do that? I’ve actually written code to compare images in such a way for another little thing I did…

Already done actually, Just got to add dynamic size for Tileset and the tilize stuff is done 8)