【问题标题】:What is the imfilter() equivalent of a nlfilter() function?与 nlfilter() 函数等效的 imfilter() 是什么?
【发布时间】: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


    【解决方案1】:

    对于二值图像(只有 0 和 1),您所做的只是在滑动窗口中进行简单求和。因此,这里可以采用imfilter的平均过滤器为:

    h  = fspecial( 'average', 50 );
    I2 = imfilter( double( buffer ), h );
    

    【讨论】:

    • 我运行代码。问题是:您应该将缓冲区转换为双精度。
    猜你喜欢
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 2021-07-21
    • 1970-01-01
    • 2020-10-22
    • 2022-08-15
    • 1970-01-01
    相关资源
    最近更新 更多