Question: Calculate the offset of the image

This question is related to the Question Image correlation

Using the two images from the branched question I tried to calculate the offset of the two images.  But it is too cumbersome and slow, can someone figure out a faster way?

Here's what I did,

I created both jpg images into a single row vector and then into an Array.  I then used a for loop with CircularShift to cycle one array and subtract it from the other.  I then took the absolute value and added all the values in the array and stored that value in another array.  The smallest value would indicate the highest probable position that both images have lined up.

Something like...

with(ArrayTools):

a:=convert(convert(img1,vector),Array)  #after img1 is padded to 184x184 from Markyan Hirnyk's answer
b:=convert(convert(img2,vector),Array)

for i from 1 to 100 do
  aa:=abs(CircularShift(a,i)-b):
  bb[i]:=add(k,k=aa):
end do:
min(convert(convert(bb,array),Array))


The problem is 100 shifts takes a long time, let alone go through the full image.  Is there a faster way to accomplish this?

Please Wait...