【发布时间】:2012-01-07 08:51:42
【问题描述】:
我正在尝试提高此代码的速度,但我不明白如何在此处使用矢量化(而不是 for 循环)。该功能来自我使用template matching 对SAD 的实施。
function [diffs,time] = search(template,image)
[hT,wT] = size(template);
[hI,wI] = size(image);
h = hI-hT+1;
w = wI-wT+1;
diffs = zeros(h,w);
tic;
for i = 1:h
for j = 1:w
t = image(i:i+hT-1,j:j+wT-1)-template(:,:); % ???
diffs(i,j) = sum(sum(abs(t)));
end
end
time = toc;
对于 640x480 的图像,此功能的工作时间约为 22-25 秒。
【问题讨论】:
-
模板的尺寸是多少?
-
取决于图像。就我而言,它是 480x360。
标签: matlab for-loop vectorization