colored image to greyscale image using CUDA parallel processing

前端 未结 12 1234
失恋的感觉
失恋的感觉 2021-02-04 19:10

I am trying to solve a problem in which i am supposed to change a colour image to a greyscale image. For this purpose i am using CUDA parallel approach.

The kerne code i

12条回答
  •  醉话见心
    2021-02-04 19:51

    I recently joined this course and tried your solution but it don't work so, i tried my own. You are almost correct. The correct solution is this:

    __global__`
    void rgba_to_greyscale(const uchar4* const rgbaImage,
                   unsigned char* const greyImage,
                   int numRows, int numCols)
    {`
    
    int pos_x = (blockIdx.x * blockDim.x) + threadIdx.x;
    int pos_y = (blockIdx.y * blockDim.y) + threadIdx.y;
    if(pos_x >= numCols || pos_y >= numRows)
        return;
    
    uchar4 rgba = rgbaImage[pos_x + pos_y * numCols];
    greyImage[pos_x + pos_y * numCols] = (.299f * rgba.x + .587f * rgba.y + .114f * rgba.z); 
    
    }
    

    The rest is same as your code.

提交回复
热议问题