Reputation: 20895
I am using pycuda to compute the intensity of the pixels of an image. To this end, I have sent the image to the GPU as follows.
img = np.float32(np.array(img.imread('my_image.jpg')))
img_gpu = gpuarray.to_gpu(img)
Then, in a kernel (written in c of course), I want to get the RGB values as follows (in pseudocode).
__global__ void get_intensities(float* img, float* intensities) {
intensities[globalIndex] = R(x, y) + G(x, y) + B(x, y)
}
My big problem now is getting the RGB channels in C. How do I do that?
Upvotes: 1
Views: 1264
Reputation: 193
Though this ultimately depends on how the image is stored, I would take advantage of structs in this situation. For example:
image = np.uint8(np.array(img.imread('my_image.jpg')))
img_gpu = gpuarray.to_gpu(image)
__global__ void intensity(uchar3* img, int* intensities)
{
...
intensities[globalIndex] = img[globalIndex].x + img[globalIndex].y + img[globalIndex].z;
...
}
See http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#built-in-vector-types
Upvotes: 1