Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

atan on GPU

Hello,

I am developing a function that does per-pixel operations on an image and there is a step where I have to compute the arctan (atan) for each pixel. I have not found any atan function for GPU that I can embed in my code. I pasted my code below.

Is there anyone that can help me with this problem? I would like to perform atan on GPU because I have other operations to do (e.g. pixels normalization etc.) afterwards.

Thank you in advace,

Durden

cv::Mat host_img = cv::imread("/home/ubuntu/myCodes/firstTest/img/frame.png");

// CPU declarations
cv::Mat b(host_img.size(), CV_8UC1);
cv::Mat g(host_img.size(), CV_8UC1);
cv::Mat r(host_img.size(), CV_8UC1);

cv::Mat b_norm(host_img.size(), CV_64FC1);
cv::Mat g_norm(host_img.size(), CV_64FC1);
cv::Mat r_norm(host_img.size(), CV_64FC1);

vector<cv::Mat> final_img;
cv::Mat out_img(host_img.size(), CV_8UC3);

// GPU declarations
cv::gpu::GpuMat img_gpu(host_img.size(), CV_8UC3);

cv::gpu::GpuMat b_gpu(host_img.size(), CV_8UC1);
cv::gpu::GpuMat g_gpu(host_img.size(), CV_8UC1);
cv::gpu::GpuMat r_gpu(host_img.size(), CV_8UC1);

vector<cv::gpu::GpuMat> chans_gpu(3);
chans_gpu[0].create(host_img.rows, host_img.cols, CV_8UC1);
chans_gpu[1].create(host_img.rows, host_img.cols, CV_8UC1);
chans_gpu[2].create(host_img.rows, host_img.cols, CV_8UC1);

img_gpu.upload(host_img);
cv::gpu::split(img_gpu, chans_gpu);

cv::gpu::max(chans_gpu[1], chans_gpu[2], b_gpu);
cv::gpu::max(chans_gpu[0], chans_gpu[2], g_gpu);
cv::gpu::max(chans_gpu[0], chans_gpu[1], r_gpu);

chans_gpu[0].convertTo(chans_gpu[0], CV_64FC1);
chans_gpu[1].convertTo(chans_gpu[1], CV_64FC1);
chans_gpu[2].convertTo(chans_gpu[2], CV_64FC1);

b_gpu.convertTo(b_gpu, CV_64FC1);
g_gpu.convertTo(g_gpu, CV_64FC1);
r_gpu.convertTo(r_gpu, CV_64FC1);

cv::gpu::divide(chans_gpu[0], b_gpu, b_gpu);
cv::gpu::divide(chans_gpu[1], g_gpu, g_gpu);
cv::gpu::divide(chans_gpu[2], r_gpu, r_gpu);

b_gpu.download(b);
g_gpu.download(g);
r_gpu.download(r);

for (int i=0 ; i<b.rows ; i++) {
    for (int j=0 ; j<b.cols ; j++) {
        b_norm.at<double>(i,j) = atan(b.at<double>(i,j));
        g_norm.at<double>(i,j) = atan(g.at<double>(i,j));
        r_norm.at<double>(i,j) = atan(r.at<double>(i,j));
    }
}