【发布时间】:2015-06-03 21:01:15
【问题描述】:
我正在尝试使用来自维基百科 (http://en.wikipedia.org/wiki/Phase_correlation) 的配方在 R 中实现 2d 相位相关算法,以跟踪 2 个图像之间的移动。这些图像(帧)是用在风中晃动的相机拍摄的,最终目标是消除这些帧和后续帧中的晃动。两个示例图像和 R 代码如下:
## we will need the tiff library
library(tiff)
## read in the tiff files
f1=as.matrix(readTIFF('f1.tiff',native=TRUE))
f2=as.matrix(readTIFF('f2.tiff',native=TRUE))
## take the fft of the first frame
F1 <- fft(f1)
## take the Conjugate fft of the second frame
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
shift <- which(r==max(r),arr.ind=TRUE)
据我了解,向量 shift 应该包含有关最能纠正这两个图像的传递移位(dx 和 dy)的信息。然而,移位变量给出 dx=1 和 dy=1,我假设这表明在 x 或 y 方向上都没有移位。对于在 x 和 y 方向上都有可见偏移或多个像素的后续帧,会发生这种情况。
你们中有人在我的代码/公式中看到错误吗?还是在进行相位相关之前,我是否需要先尝试一些更高级的方法,例如过滤图像?
男女朋友们干杯!
【问题讨论】:
-
您好,我在研究使用相位相关进行图像拼接时遇到了这个问题。我可以知道使用 R 而不仅仅是 Matlab 或 Python 背后的原因是什么(如果许可成本是不使用 Matlab 的主要原因)
标签: r image-processing fft cross-correlation