Here my images: first optical and then SAR
请给我一个帮助!! :)
## read my images with raster
f1 <- as.matrix(readPNG("optical.png", package="png"))
f2 <- as.matrix(readPNG("sar.png", package="png"))
## take the fft of the first frame
F1 <- fft(f1)
## take the Conjugate fft of the second frame
noise.b <- runif(length(f2),min(range(f2)),max(range(f2)))
f2 <- noise.b+f2
F2.c <- Conj(fft(f2))
## calculate the cross power spectrum according to the wiki article
R <- (F1*F2.c)/abs(F1*F2.c)
## take the inverse fft of R
r <- fft(R,inv=TRUE)/length(R)
## because the zero valued imaginary numbers are not needed
r <- Re(r)
## show the normalized cross-correlation
image(r)
## find the max in the cross correlation matrix, or the phase shift -
## between the two images
min.err <- which(r==max(r),arr.ind=TRUE)
shift <- (dim(f1)+3)/2-min.err
这是互相关的结果。