﻿ matlab – 以类似于’conv2’的方式获得`normxcorr2`输出的优雅方法 – (删除不需要的边) - 代码日志

#### matlab – 以类似于’conv2’的方式获得`normxcorr2`输出的优雅方法 – (删除不需要的边)

``````C = conv2(A,B,'same');
C = conv2(A,B,'valid');
``````

``````size( conv2( rand(50,50) , rand(6,6), 'valid') )
``````

ans =

``````45    45
``````
``````size( conv2( rand(50,50) , rand(6,6), 'same') )
``````

ans =

``````50    50
``````
``````size( conv2( rand(50,50) , rand(6,6)) )
``````

ans =

``````55    55
``````

``````function I = normxcorr2e(template,im,shape)
switch shape
case 'same'
I = normxcorr2(template,im);
r = size(I,1)-size(im,1);
c = size(I,2)-size(im,2);

m1=floor(r/2);
n1=floor(c/2);
m2=ceil(r/2);
n2=ceil(c/2);

I(1:m2,:) = [];
I(end-m1+1:end,:) = [];

I(:,1:n2) = [];
I(:,end-n1+1:end) = [];
case 'full'
%Do nothing
case 'valid'
%TODO - write this case...
otherwise
end

end
``````

>它允许您省略shape参数(默认为’full’).
>当shape是有效字符串时,它仅调用`normxcorr2`.
>它使用logical indexing在一行中执行索引.引导填充和所需中心区域的大小用于创建真值和假值的索引向量.不需要指定尾随填充,因为短于索引的维度的逻辑索引将仅使用false值填充.

``````function I = normxcorr2e(template, im, shape)

if (nargin == 2) || strcmp(shape,'full')
I = normxcorr2(template, im);
return
end

switch shape
case 'same'
center = size(im);
case 'valid'