我喜欢在Matlab中创建算法原型,但是我需要将它们放在运行大量Python代码的服务器上。因此,我很快将代码转换为Python并将两者进行了比较。Matlab实现的运行速度快1000倍(来自定时函数调用-无需评测)。有人马上知道为什么Python的性能这么慢吗?在
% init random data
w = 800;
h = 1200;
hmap = zeros(w,h);
npts = 250;
for i=1:npts
hmap(randi(w),randi(h)) = hmap(randi(w),randi(h))+1;
end
% Params
disksize = 251;
nBreaks = 25;
saturation = .9;
floorthresh =.05;
fh = fspecial('gaussian', disksize, disksize/7);
hmap = conv2(hmap, fh, 'same');
% Scaling, paritioning etc
hmap = hmap/(max(max(hmap)));
hmap(hmap<floorthresh) = 0;
hmap = round(nBreaks * hmap)/nBreaks;
hmap = hmap * (1/saturation);
% Show the image
imshow(hmap, [0,1])
colormap('jet')
好吧,多亏了@Yves Daust的建议,问题为我解决了
滤波器
scipy.ndimage.filters.gaussian_filter
利用了内核的可分性,并将运行时间减少到matlab实现的一个数量级之内。在相关问题 更多 >
编程相关推荐