Sad calculation of 2 images (Video Processing)

Problem Statement :

SAD - Sum of Absolute Differences:


If there are two arrays, say {20, 45, -15, 0} and { 18, 48, 50, -5}, SAD is computed as,

SAD = abs(20-18) + abs(45-48) + abs(-15-50) + abs(0-(-5)) = 2 + 3 + 65 + 5 = 75

Given two grayscale images with size WxH, both W and H being multiples of 64. Read the images into buffers. Find the SAD of each block of size 64x64 within the image. Of all the 64x64 blocks find the block with the least SAD. 

Example:

Take an image of 128x128. It has 4 blocks of 64x64. If the SAD of 4 blocks in row-major order are 25000, 40000, 37500 and 15000 respectively. API should return (64,64) which is the coordinate of the last 64x64 block within the image. 

Drive Link for code :

Observations :

Observation.pdf