Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8377147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:35:35+00:00 2026-06-09T15:35:35+00:00

I would like to implement a GPU Bayer to RGB image conversion algorithm, and

  • 0

I would like to implement a GPU Bayer to RGB image conversion algorithm, and I was wondering what algorithm the OpenCV cvtColor function uses. Looking at the source I see what appears to be a variable number of gradients algorithm and a basic algorithm that could maybe be bilinear interpolation? Does anyone have experience with this that they could share with me, or perhaps know of GPU code to convert from Bayer to BGR format?

The source code is in imgproc/src/color.cpp. I’m looking for a link to it. Bayer2RGB_ and Bayer2RGB_VNG_8u are the functions I’m looking at.

Edit: Here’s a link to the source.

http://code.opencv.org/projects/opencv/repository/revisions/master/entry/modules/imgproc/src/color.cpp

I’ve already implemented a bilinear interpolation algorithm, but it doesn’t seem to work very well for my purposes. The picture looks ok, but I want to compute HOG features from it and in that respect it doesn’t seem like a good fit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:35:36+00:00Added an answer on June 9, 2026 at 3:35 pm

    Default is 4way linear interpolation or variable number of gradients if you specify the VNG version.

    see ..\modules\imgproc\src\color.cpp for details.

    I submitted a simple linear CUDA Bayer->RGB(A) to opencv, haven’t followed if it’s been accepted but it should be in the bugs tracker.
    It’s based on the code in Cuda Bayer/CFA demosaicing example.

    Here is a sample of howto use cv::GPU in your own code.

    /*-------RG ccd  BGRA output ----------------------------*/
     __global__ void bayerRG(const cv::gpu::DevMem2Db in, cv::gpu::PtrStepb out)  
    { 
        // Note called for every pair, so x/y are for start of cell so need x+1,Y+1 for right/bottom pair
        // R G 
        // G B 
    
        // src
        int x = 2 * ((blockIdx.x*blockDim.x) + threadIdx.x);
        int y = 2 * ((blockIdx.y*blockDim.y) + threadIdx.y);
    
        uchar r,g,b;        
    
        // 'R'
        r = (in.ptr(y)[x]);
        g = (in.ptr(y)[x-1]+in.ptr(y)[x+1]+(in.ptr(y-1)[x]+in.ptr(y+1)[x]))/4;
        b = (in.ptr(y-1)[x-1]+in.ptr(y-1)[x+1]+(in.ptr(y+1)[x-1]+in.ptr(y+1)[x+1]))/4;  
        ((uchar4*)out.ptr(y))[x] = make_uchar4( b,g,r,0xff);
    
        // 'G' in R 
        r = (in.ptr(y)[x]+in.ptr(y)[x+2])/2;
        g = (in.ptr(y)[x+1]);
        b = (in.ptr(y-1)[x+1]+in.ptr(y+1)[x+1])/2;
        ((uchar4*)out.ptr(y))[x+1] = make_uchar4( b,g,r,0xff);
    
        // 'G' in B
        r = (in.ptr(y)[x]+in.ptr(y+2)[x])/2;
        g = (in.ptr(y+1)[x]);
        b = (in.ptr(y+1)[x-1]+in.ptr(y+1)[x+2])/2;
        ((uchar4*)out.ptr(y+1))[x] = make_uchar4( b,g,r,0xff);
    
        // 'B' 
        r = (in.ptr(y)[x]+in.ptr(y)[x+2]+in.ptr(y+2)[x]+in.ptr(y+2)[x+2])/4;;
        g = (in.ptr(y+1)[x]+in.ptr(y+1)[x+2]+in.ptr(y)[x+1]+in.ptr(y+2)[x+1])/4;
        b = (in.ptr(y+1)[x+1]);
        ((uchar4*)out.ptr(y+1))[x+1] = make_uchar4( b,g,r,0xff);    
    } 
    
    
    /* called from */
    extern "C" void cuda_bayer(const cv::gpu::DevMem2Db& img, cv::gpu::PtrStepb out)
    {
        dim3 threads(16,16);    
        dim3 grid((img.cols/2)/(threads.x), (img.rows/2)/(threads.y));  
    
        bayerGR2<<<grid,threads>>>(img,out);    
        cudaThreadSynchronize();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to implement 2D liquid simulator using GPU. I'm looking for some
I would like to implement a function with R that removes repeated characters in
I would like to implement a function that takes as input a size n
I would like to implement an algorithm which will find the bounding rectangles of
I would like to implement an interactive evolutionary algorithm for generating music (probably just
i would like to implement a good throttle algorithm by in .net (C# or
I would like to implement a distinct thread for each route in apache camel.I
I would like to implement a very simple way to store a variable containing
I would like to implement a simple queueing service specific to a project. Where
I would like to implement a switch button, android.widget.Switch (available from API v.14). <Switch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.