It compares the difference of the color of the pixels. If it falls under some threshold, the pixels are considered similar, if it doesn't the pixels are considered not similar. It also outputs an image of the same size that gives you a visual indicator of where the difference lies.

If you are trying to determine if they are identical, you don't need to do this much work. You could check the sizes of the files and also compute an MD5 hash of the file.