In terms of performance, you should include this check in your comparison algorithm. The most expensive operation when working with images is the majority of loading a small part of the image into the cache. Once you receive it, there are many ways to work with data very quickly ( SIMD ), but the problem is that you need to evict and reload the cache with new data all the time, and it is expensive to calculate. Now, if you already went through each pixel of both images once in your algorithm, it would be advisable at the same time to calculate the SAD , while you still got the data in the cache. So in the pseudo code:
int total_sad = 0 for y = 0; y < heigth; y++ for x = 0; x < width; x+=16 xmm0 = load_data (image0 + y * width + x) xmm1 = load_data (image1 + y * width + x) store_data (result_image + y * width + x, diff (xmm0, xmm1)) total_sad += sad (xmm0, xmm1) if (total_sad == 0) print "the images are identical!"
Hope this helps.
source share