What algorithm does OpenCV Bayer use?

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

The source code is in imgproc/src/color.cpp. I am looking for a link to it. Bayer2RGB_and Bayer2RGB_VNG_8u- these are the functions I'm looking at.

Edit: Here is the link to the source.

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

I have already implemented the bilinear interpolation algorithm, but it does not seem to work very well for my purposes. The picture looks fine, but I want to compute the HOG functions from it, and in this regard, it does not seem good.

+5
source share
3 answers

By default, 4way linear interpolation or a variable number of gradients is used if you specify the VNG version.

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

I presented a simple linear CUDA Bayer-> RGB (A) for opencv, did not follow if it was accepted, but it should be in the error trackers. It is based on code in a Cuda Bayer / CFA demo example .

Here is an example of using 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();
}
+8
source

, , DFPD ( ), . , Matlab. , DFPD debayer . , ​​.

+1

As far as I know, at the moment he uses adaptive homogeneity aimed at demosaizing. Explained in an article by Hirakawa and many other sources on the Internet.

+1
source

All Articles