5 performance matlab geometry image-processing octave
我有一个矩阵(图像)和有关圈内有趣部分的信息(给出中心corrdinates和半径).我想为所有圆圈切割矩阵的各个部分,以便为每个圆圈做更多的计算.或者至少我想要一个包含所有圆圈的位掩码.
我使用Octave(但也可以使用MATLAB,但由于许可证的使用会很困难)并且具有以下脚本以及stackoverflow的一些提示.我有20个圆圈的信息,使用Octave在我的Core i5上大约需要0.7秒:
% image
dim_x = 1000;
dim_y = 1000;
A=rand(dim_x,dim_y);
% center positions and ...
c = [222 111; 878 112; 81 718; 89 112; 222 111; 878 112; 81 718; 89 112; 222 111; 878 112; 81 718; 89 112; 222 111; 878 112; 81 718; 89 112; 222 111; 878 112; 81 718; 89 112];
%... radii of the circles
r = [10 33 55 2 22 10 33 55 2 22 10 33 55 2 22 10 33 55 2 22];
tic;
for i=1:size(c,1)
% create a bitmask ...
mask = bsxfun(@plus, ((1:dim_y) - c(i,1)).^2, (transpose(1:dim_x) - c(i,2)).^2) < r(i)^2;
% ... cut the circles out of the image
B=A.*mask;
end;
toc;
Run Code Online (Sandbox Code Playgroud)
你知道一个更高性能的解决方案,因为我想拥有大约600个圆圈.
提前致谢
尝试
mask = bsxfun(@lt, ((1:dim_y) - c(i,1)).^2, r(i)^2 - ((1:dim_x).' - c(i,2)).^2);
Run Code Online (Sandbox Code Playgroud)
根据我的 MATLAB 分析器,这比您的版本快大约 4 倍。此外,B = A.*mask
排队时间与原来的排队时间大致相同mask = ...
。不确定对此您能做些什么。