我正在使用 OpenCL 进行一些线性插值,但结果不如预期。于是我做了一个简单的测试,内核代码如下所示:
const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR | CLK_ADDRESS_CLAMP_TO_EDGE;
// Kernel block.
kernel void interpolate(
global float4*input,
image3d_t image,
global float4*output)
{
size_t i = get_global_id(0);
float4 coord = input[i];
float4 tap = read_imagef(image, sampler, coord);
output[i] = tap;
}
2x2x2 图像的像素(RGBA)如下:
cl_float4 image_data[8] = {
{0, 0, 0, 0},
{100, 0, 0, 0},
{0, 100, 0, 0},
{100, 100, 0, 0},
{0, 0, 100, 0},
{100, 0, 100, 0},
{0, 100, 100, 0},
{100, 100, 100, 0},
};
我使用 11 个坐标 ((0, 0, 0), (0.1, 0.1, 0.1)...(1, 1, 1), 从 0 到 1,步骤 0.1) 来读取图像,我希望结果是 (0, 0, 0), (10, 10, 10)...(100, 100, 100),但我得到:
coordinate:0.000000, result: 0.000000
coordinate:0.100000, result: 0.000000
coordinate:0.200000, result: 0.000000
coordinate:0.300000, result: 10.156250
coordinate:0.400000, result: 30.078125
coordinate:0.500000, result: 50.000000
coordinate:0.600000, result: 69.921875
coordinate:0.700000, result: 89.843750
coordinate:0.800000, result: 100.000000
coordinate:0.900000, result: 100.000000
coordinate:1.000000, result: 100.000000
它只在坐标小于 0.25 或大于 0.75 时返回边缘值。
任何人都可以解释这一点吗?谢谢。