【发布时间】:2014-02-19 13:54:33
【问题描述】:
我有一段代码使用 50x50 滑动窗口计算值 == 1 的二进制网格中像素的百分比:
f = @(x) numel(x(x==1))/numel(x);
I2 = nlfilter(buffer,[50 50],f);
我听说imfilter 是一种更有效的焦点计算方法,因此希望做一些基准测试。 上面的 nlfilter() 函数的 imfilter() 等价物是什么?
附上完整的示例数据代码
% Generate a grid of 0's to begin with.
m = zeros(400, 400, 'uint8');
% Generate 100 random "trees".
numRandom = 100;
linearIndices = randi(numel(m), 1, numRandom);
% Assign a radius value of 1-12 to each tree
m(linearIndices) = randi(12, [numel(linearIndices) 1]);
buffer = false(size(m));
for radius =1:12 % update to actual range
im_r = m==radius;
se = strel('disk',radius);
im_rb = imfilter(im_r, double(se.getnhood()));
buffer = buffer | im_rb;
end
% The imfilter approach
% The nlfilter approach
f = @(x) numel(x(x==1))/numel(x);
I2 = nlfilter(buffer,[50 50],f);
imshowpair(buffer,I2, 'montage')
【问题讨论】:
标签: image matlab image-processing