I have two images, say P and S, of size 8192×200, and I want to calculate a custom "Euclidean distance" between them. Currently I use the following steps:
Reshape the images into a pair of column and row vectors:
Ip = Ip(:).'; Is = Is(:);Calculate a metric matrix,
G, whose entries are given by the formulaG(i,j) = 1/(2*pi*r*r) * exp((-d*d)/(2*r*r));where
ris a global parameter that varies from 0 to 20, say, anddis the distance between pixeliand pixelj. E.g., if pixeliis(k,l)and pixeljis(k1,l1), thend = sqrt((k-k1)^2 + (l-l1)^2);. Pixel 1 will be(1,1), Pixel 2 will be(1,2), and so on. Therefore, the size of matrixGwill be1638400×1638400.Compute the final (scalar) Euclidean distance between two images, using:
ImEuDist = sqrt( (Ip-Is) * G * (Ip-Is).' );
I have already written some code using a mex function, but it is taking too long before giving the results (5-6 Hours) - see this SO question for code and more discussion on this.
Please help me to optimize this; I would ideally like it to run in a matter of seconds. Note that I am not interested in solutions involving the GPU.