【发布时间】:2022-01-16 22:49:52
【问题描述】:
我需要编写一个 OpenCL 内核。通过内核参数,我得到一个具有特定尺寸的输入图像(例如:width: 600px, height: 400px)。我需要运行的算法是:“最近邻插值”。
在下图中,一个从像素 (1,1) 开始(左图,绿色像素)。我的缩放因子是 3。这意味着在我的输出图像中这个像素必须出现 9 次。
现在我的问题是,如何使用下面的代码(使用 2 个 for 循环)为每个绿色像素提供 SourceImage 的值(pixelValue)。
Input dimentions: width = 600px, height: 400px
Ouput dimentions: width = 1800px, height: 1200px
草图
OpenCL 代码
__kernel
void NearestNeighbourScaling(__read_only image2d_t SourceImage, __write_only image2d_t DestinationImage, int width, int height, int scalingFactor)
{
int row = get_global_id(0);
int col = get_global_id(1);
const int scaledWidth = width * scalingFactor;
const int scaledHeight = height * scalingFactor;
// Declaring sampler
const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_FILTER_LINEAR | CLK_ADDRESS_CLAMP;
float4 pixelValue = read_imagef(SourceImage, sampler, (int2)(col, row));
for(int i = 0; i < scalingFactor; i++)
{
for(int j = 0; j < scalingFactor; j++)
{
write_imagef(DestinationImage, (int2)(?, ?), pixelValue);
}
}
}
【问题讨论】:
标签: kernel opencl interpolation nearest-neighbor image-scaling