The algortihm is actually quiet simple: for each picture the frequency spectrum is calculated with a fourier transformation, after that each spectrum is compared to that of the picture you want to be listed first using the Pearson correlation coefficient. Then it is just a matter of sorting.