处理 CUDA 中的边界条件/光环区域 [英] Dealing with Boundary conditions / Halo regions in CUDA

查看:13
本文介绍了处理 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 中的边界条件/光环区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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