我知道高斯滤波器的可分离性提高了计算复杂度. 这如何真正反映我的程序?我想与不可分离的情况相比,卷积所需的 for 循环数更少?什么真正的缺点?
高斯二维滤波器可分离性的优缺点是什么?
假设最简单的情况是正方形图像大小的和一个方形过滤器内核大小的, 原始 2D 卷积以生成裁剪后的输出图像大小的需要大约MAC。
之间的原始二维卷积和过滤器是通过使用两个 for 循环来遍历每个输出像素和两个额外的 for 循环来在该像素位置执行 2D 卷积来实现的。因此总共需要 4 个嵌套的 for 循环;复杂性
当过滤内核是可分离的,例如,那么在这种情况下,图像之间的卷积和过滤器可以通过以下方法在没有原始 2D 卷积和的情况下执行:
- 首先,在列之间执行一维卷积和一维滤波器,这需要大约MACs 来完成。应该对每列执行此操作通过沿其水平方向前进,许多,列。因此共有MAC 将需要完成第一步以生成中间图像
- Then, apply the similar algorithm, with the filter and rows of the intermediate image , which will require similar number of MACs as .
Hence as a total you will need about MACs for the separable implementation of the 2D convolution. The actual number depends on the cropping type you apply. Thus a complexity of about is attained.
It can be seen that, to implement the separable convolution algorithm, you will only need 3 nested for loops, which is where the gain comes from.
The main advantage of separable filtering is quite clear; much reduced computational cost. In fact even the 2D-FFT algorithm makes use of it as the 2D-DFT kernel is separable.
Another advantage is that since there are less number of MACs involved to produce the same output compared to the raw 2D convolution, it's less prone to numerical issues and likely to produce more accurate results.
A disadvantage of separation is that it requires an extra ram memory to store the intermediate image, which can be a concern in certain applications.