Attempt to optimize the code of comparing two images.