处理 CUDA 中的边界条件/Halo 区域 [英] Dealing with Boundary conditions / Halo regions in CUDA
问题描述
我正在使用 CUDA 进行图像处理,但我对像素处理有疑问.
I'm working on image processing with CUDA and i've a doubt about pixel processing.
在应用 m x m
卷积滤波器时,图像的边界像素通常会做什么?
What is often done with the boundary pixels of an image when applying a m x m
convolution filter?
在3 x 3
卷积核中,忽略图像的1
像素边界更容易处理,尤其是在代码使用共享内存进行改进时.实际上,在这种情况下,不需要检查给定像素是否具有所有可用的邻域(即坐标 (0, 0)
上的像素尚未离开,左上,上邻居).然而,去除原始图像的 1
像素边界可能会产生部分结果.
In a 3 x 3
convolution kernel, ignoring the 1
pixel boundary of the image is easier to deal with, especially when the code is improved with shared memory. Indeed, in this case, one does not need to check if a given pixel has all the neigbourhood available (i.e. pixel at coord (0, 0)
has not left, left-upper, upper neighbours). However, removing the 1
pixel boundary of the original image could generate partial results.
与此相反,我想处理图像中的所有像素,在使用共享内存改进时也是如此,例如,加载 16 x 16
像素,但计算内部 14 x 14
.同样在这种情况下,忽略边界像素会生成更清晰的代码.
Opposite to that, I'd like to process all the pixels within the image, also when using shared memory improvements, i.e., for example, loading 16 x 16
pixels, but computing the inner 14 x 14
. Also in this case, ignoring the boundary pixels generates a clearer code.
在这种情况下通常会怎么做?
是否有人经常使用我的方法忽略边界像素?
当然,我知道答案取决于问题的类型,即按像素添加两个图像没有这个问题.
Of course, I'm aware the answer depends on the type of problem, i.e. adding two images pixel-wise has not this problem.
提前致谢.
推荐答案
处理边框效果的常用方法是用额外的行填充原始图像 &列基于您的过滤器大小.填充值的一些常见选择是:
A common approach to dealing with border effects is to pad the original image with extra rows & columns based on your filter size. Some common choices for the padded values are:
- 一个常数(例如零)
- 根据需要多次复制第一行和最后一行/列
- 在边框处反映图像(例如 column[-1] = column[1], column[-2] = column[2])
- 包装图像值(例如 column[-1] = column[width-1], column[-2] = column[width-2])
这篇关于处理 CUDA 中的边界条件/Halo 区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!