【问题标题】:max of images correlation with xcorr2 shifted by 2 pixels compared to imfilter与 imfilter 相比,与 xcorr2 相关的最大图像偏移了 2 个像素
【发布时间】:2015-11-09 08:16:41
【问题描述】:

为实时定点实现准备实验室代码,我写了如下函数

function res =  imcorr(inIm,kernel)
% res=imfilter(inIm,kernel,'replicate'); %initial implementation
% res=imfilter(inIm,kernel); %same as we crop the result below
res=xcorr2(inIm,kernel); %faster, works with singles, but shifts result by 2 pixels

s=size(inIm);
rect=[fix((size(res,2)-s(2))/2), fix((size(res,1)-s(1))/2), s(2), s(1)];
res=imcrop(res,rect);

然后我使用来自https://gist.github.com/goulu/ba70175f870fdb2c25e3 的代码(从http://www.mathworks.com/help/signal/ref/xcorr2.html 编辑)作为测试平台,并注意到xcorr2 和imfilter 获得的结果在两个方向上都有2 个像素的偏移:

这是从哪里来的?

【问题讨论】:

  • 您可以尝试使用手动生成的矩阵吗?

标签: matlab image-processing correlation


【解决方案1】:

不知道确切原因,但似乎 imfilter 和 xcorr2 对奇数/偶数图像大小进行舍入不同,所以最后我可以通过这样的裁剪获得相同的结果:

rect=[(size(res,2)-s(2))/2+1.5 (size(res,1)-s(1))/2+1.5 s(2)-1-yoff s(1)-1-xoff];
res=imcrop(res,fix(rect)); 

【讨论】:

    猜你喜欢
    • 2012-05-11
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 1970-01-01
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多