我已经修改了 Sobel 过滤器示例以实现 Canny 过滤器的非最大值抑制。但是,以下代码会生成异常:
unsigned char pix00 = pCannyOriginal[ i-1 + (blockIdx.x-1) * blockDim.x];
unsigned char pix01 = pCannyOriginal[ i+0 + (blockIdx.x-1) * blockDim.x];
unsigned char pix02 = pCannyOriginal[ i+1 + (blockIdx.x-1) * blockDim.x];
unsigned char pix10 = pCannyOriginal[ i-1 + (blockIdx.x+0) * blockDim.x];
unsigned char pix11 = pCannyOriginal[ i+0 + (blockIdx.x+0) * blockDim.x];
unsigned char pix12 = pCannyOriginal[ i+1 + (blockIdx.x+0) * blockDim.x];
unsigned char pix20 = pCannyOriginal[ i-1 + (blockIdx.x+1) * blockDim.x];
unsigned char pix21 = pCannyOriginal[ i+0 + (blockIdx.x+1) * blockDim.x];
unsigned char pix22 = pCannyOriginal[ i+1 + (blockIdx.x+1) * blockDim.x];
我知道这会导致对内存的无效访问,但是原始纹理上的同一组分配不会生成一个。那么,tex2D 函数是否有无效内存访问的机制呢?我应该如何解决这个问题?
另请注意,使用原始 lena.pgm 不会产生任何异常,但用其他东西替换它会产生任何异常。原始 lena.pgm 是否包含一些额外的行和列,或者我在这里遗漏了什么?