过滤器的速度非常快 [英] imfilter speed for volumes

查看:307
本文介绍了过滤器的速度非常快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一种算法,该算法需要过滤3D矩阵(非稀疏,512 ^ 3)才能找到边缘。
我只想在每个切片中找到边缘,所以我一直在做以下事情:

I'm working on an algorithm, which requires filtering of a 3D matrix (non-sparse, 512^3) to find edges. I only want to find edges in each slice, so I have been doing the following:

% 2D loop appaoch    
[x,y]=ndgrid(floor(-3*sigma):ceil(3*sigma),floor(-3*sigma):ceil(3*sigma));    
DGauss=-(x./(2*pi*sigma^4)).*exp(-(x.^2+y.^2)/(2*sigma^2));    
filteredVolume = zeros(size(vol))    
for n = 1:size(vol,3)      
    filteredVolume(:,:,n) = imfilter(vol(:,:,n),DGauss,'conv','symmetric');    
end

我也尝试通过在整个卷上调用imfilter来做同样的事情: / p>

I also tried to do the same by calling imfilter on the entire volume:

% 3D matrix approach    
filteredVolume = imfilter(vol,DGauss,'conv','symmetric');

我比较了这两种方法的性能,但循环版本明显更快(6.5秒到20秒)。
应该预期这种行为吗?如果是这样,为什么?

I compared the performance of both of these approaches, but the loop version is significantly faster (6.5 seconds to 20 seconds). Should this behavior be expected? If so, why?

推荐答案

3D版本需要更长时间的原因是因为 imfilter 决定过滤器是不可分离的。函数 imfilter> isSeparable 表示如下:

The reason it takes longer with the 3D version is because imfilter decides that the filter is non-separable. The function imfilter>isSeparable says the following:

function separable = isSeparable(a, h)

% check for filter separability only if the kernel has at least
% 289 elements [17x17] (non-double input) or 49 [7x7] (double input),
% both the image and the filter kernel are two-dimensional and the
% kernel is not a row or column vector, nor does it contain any NaNs of Infs

由于输入图像不是2D,因此函数返回 false 和2D过滤操作完成而不是两个连续的1D过滤器,它们更快。

Since the input image is not 2D, the function returns false and a 2D filtering operation is done instead of two sequential 1D filters, which are faster.

在旁注中, imfilter 不会受益来自JIT编译器。所有时间都花在已编译的函数 images \ private \imfilter_mex

On a side note, imfilter does not benefit from the JIT compiler. All the time is spent in the compiled function images\private\imfilter_mex.

这篇关于过滤器的速度非常快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆