有没有办法在MATLAB中向量化这样的for循环?执行需要很多时间。
for i = 1:numberOfFrames-1
frameDifferencesEroded(:,:,i+1) = imabsdiff(frameDifferencesErodedTemp(:,:,i+1),frameDifferencesErodedTemp(:,:,1));
for k=1:numel(frameDifferences(1,:,i))
for m=1:numel(frameDifferences(:,1,i))
if(frameDifferencesEroded(m,k,i+1)>thresold)
frameDifferences(m,k,i+1) = 255;
else
frameDifferences(m,k,i+1) = 0;
end
end
end
end
假设您想要frameDifferencesEroded(:,:,1)
并且frameDifferences(:,:,1)
全为零,因为您没有在代码中输入值,那么这可能对您有用-
%// Replace imabsdiff with abs(bsxfun(@minus..)), which might be faster
frameDifferencesEroded = abs(bsxfun(@minus,frameDifferencesErodedTemp, frameDifferencesErodedTemp(:,:,1)))
%// Get the thresholding done next
frameDifferences = (frameDifferencesEroded>thresold).*255
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句