用于 DSP 的快速 2D 卷积
我想实现一些图像处理算法,这些算法旨在在 beagleboard 上运行。这些算法广泛使用卷积。我正在尝试为 2D 卷积找到一个好的 C 实现(可能使用快速傅立叶变换)。我还希望该算法能够在 beagleboard 的 DSP 上运行,因为我听说 DSP 针对此类操作进行了优化(通过其乘法累加指令)。
我没有该领域的背景,所以我认为自己实现卷积不是一个好主意(我可能不会像理解其背后所有数学的人那样做得好)。我相信某个地方有一个很好的 DSP C 卷积实现,但我找不到它?
有人可以帮忙吗?
编辑:结果内核非常小。其尺寸为 2X2 或 3X3。所以我想我并不是在寻找基于 FFT 的实现。我在网上搜索卷积以查看其定义,以便我可以以直接的方式实现它(我真的不知道卷积是什么)。我发现的只是乘积分的东西,我不知道如何用矩阵来做。有人能给我一段 2X2 内核案例的代码(或伪代码)吗?
I want to implement some image-processing algorithms which are intended to run on a beagleboard. These algorithms use convolutions extensively. I'm trying to find a good C implementation for 2D convolution (probably using the Fast Fourier Transform). I also want the algorithm to be able to run on the beagleboard's DSP, because I've heard that the DSP is optimized for these kinds of operations (with its multiply-accumulate instruction).
I have no background in the field so I think it won't be a good idea to implement the convolution myself (I probably won't do it as good as someone who understands all the math behind it). I believe a good C convolution implementation for DSP exists somewhere but I wasn't able find it?
Could someone help?
EDIT: Turns out the kernel is pretty small. Its dimensions are either 2X2 or 3X3. So I guess I'm not looking for an FFT-based implementation. I was searching for convolution on the web to see its definition so I can implement it in a straight forward way (I don't really know what convolution is). All I've found is something with multiplied integrals and I have no idea how to do it with matrices. Could somebody give me a piece of code (or pseudo code) for the 2X2 kernel case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
图像和内核的尺寸是多少?如果内核很大,那么您可以使用基于 FFT 的卷积,否则对于小内核,只需使用直接卷积。
不过,DSP 可能不是实现此目的的最佳方法 - 仅仅因为它具有 MAC 指令并不意味着它会更高效。 Beagle Board 上的 ARM CPU 有 NEON SIMD 吗?如果是这样,那么这可能是正确的选择(而且也更有趣)。
对于小内核,您可以像这样进行直接卷积:
您可以修改它以支持 K 的偶数值 - 只需要注意两个内部循环的上限/下限。
What are the dimensions of the image and the kernel ? If the kernel is large then you can use FFT-based convolution, otherwise for small kernels just use direct convolution.
The DSP might not be the best way to do this though - just because it has a MAC instruction doesn't mean that it will be more efficient. Does the ARM CPU on the Beagle Board have NEON SIMD ? If so then that might be the way to go (and more fun too).
For a small kernel, you can do direct convolution like this:
You can modify this to support even values of K - it just takes a little care with the upper/lower limits on the two inner loops.
我知道这可能偏离主题,但由于 C 和 JavaScript 之间的相似性,我相信它仍然会有所帮助。 PS.:受到@Paul R 回答的启发。
JavaScript 中使用数组的二维 2D 卷积算法
您可以在 http://ec2-54-232-84-48.sa-east-1.compute.amazonaws.com/two-Dimensional -卷积算法与数组-in-javascript/
I know it might be off topic but due to the similarity between C and JavaScript I believe it could still be helpful. PS.: Inspired by @Paul R answer.
Two dimensions 2D convolution algorithm in JavaScript using arrays
You can check the full blog post at http://ec2-54-232-84-48.sa-east-1.compute.amazonaws.com/two-dimensional-convolution-algorithm-with-arrays-in-javascript/