Optimize image comparison (#12537)

Change-Id: I6439aad6f9e5b0eb0dd932947cc88657c61ecbc7