在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
试验很简单,取二值图像的质心,三种方法做比较 1.完全采用矩阵性能不做任何循环操作,对find后的值进行除法与取余操作,从而得到centroid2.完全采用循环操作,最简单明了3.结合1,2,对每一列进行find,省去与除法与取余的计算时间分析试验证明
所以我采用了方法2,简单明了,效率也可以。 测试代码 M = 9000; N = 1700; A = randn(M,N); A = A>0.0; %%%%%%%%%%%%%%%%%%%% 方法1 %%%%%%%%%%% fprintf('\n1: '); tic b = find(A>0); c = mod(b,M); x1 = sum(c)+numel(find(c==0))*M; y1 = sum(ceil(b./double(M))); n1 = numel(b); toc %%%%%%%%%%%%%%%%%%%% 方法2 %%%%%%%%%%% fprintf('2: '); tic sx = 0; sy = 0; n2 = 0; for i = 1:M for j = 1:N if A(i,j) > 0 sx = sx + i; sy = sy + j; n2 = n2 + 1; end end end x2 = sx; y2 = sy; toc %%%%%%%%%%%%%%%%%%%% 方法3 %%%%%%%%%%% fprintf('3: '); tic sx = 0; sy = 0; for j = 1:N c = find(A(:,j)>0); sy = sy + numel(c)*j; sx = sx + sum(c); end x3 = sx; y3 = sy; toc fprintf('(%d,%d,%d),(%d,%d,%d),(%d,%d)\n',x1,y1,n1,x2,y2,n2,x3,y3);
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论