UBLAS 矩阵查找单元格的周围值?
我正在寻找一种优雅的方式来实现这一点。基本上我有 amxn 矩阵。其中每个单元格代表像素值,行和列代表图像的像素行和像素列。
因为我基本上映射了 HDF 文件中的点及其相应的像素值。我们基本上有很多空像素。其中填充了 0。
现在我需要做的是取周围单元格的平均值,以对丢失单元格的像素值进行平均。
现在我可以暴力破解它,但它很快就会变得丑陋。有什么优雅的解决方案吗?
I am looking for an elegant way to implement this. Basically i have a m x n matrix. Where each cell represents the pixel value, and the rows and columns represent the pixel rows and pixel columns of the image.
Since i basically mapped points from a HDF file, along with their corresponding pixel values. We basically have alot of empty pixels. Which are filled with 0.
Now what i need to do is take the average of the surrounding cell's, to average out of a pixel value for the missing cell.
Now i can brute force this but it becomes ugly fast. Is there any sort of elegant solution for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于这个过滤问题有一个众所周知的优化。
如下所示:
其作用是:
每个单元格需要执行 4 次操作才能计算总和,而暴力破解则需要 8 次操作(假设您正在执行 3x3 平均滤波器)。
很酷的是,如果您使用普通的补码算术,则不必担心前两遍中的任何溢出;他们在最后两次传递中抵消了。
There's a well-known optimization to this filtering problem.
Like this:
What this does is:
This takes 4 operations per cell to compute the sum, as opposed to 8 for brute force (assuming you're doing a 3x3 averaging filter).
The cool thing is that if you use ordinary two's-complement arithmetic, you don't have to worry about any overflows in the first two passes; they cancel out in the last two passes.
这里的主要问题是利用所有可用的核心和缓存效率。
您可能对检查卷积的快速实现感兴趣。
但是,由于您使用 Boost 进行此操作,因此您可以在 此 Boost 示例
我相信您只需更改卷积核即可完成您的专门任务。
The main issues here are utilizing all available cores and cache effeciency.
You might be interested in checking fast implementation of convolution.
However, since you do it with Boost, you can check how this is done in this Boost example
I beleive you have to change only the convolution kernel for your specialized task.