The sensor matrix is:Code: [Select]R G R G R GG B G B G BR G R G R GG B G B G BAnd the raw data buffer:Code: [Select]R(0,0)G(0,1)R(0,2)G(0,3)...G(0,c-1)G(1,0)B(1,1)G(1,2)B(1,3)...B(1,c-1)R(2,0),G(2,1),R(2,2)...B(r-1,c-1)with all values 10bits
R G R G R GG B G B G BR G R G R GG B G B G B
R(0,0)G(0,1)R(0,2)G(0,3)...G(0,c-1)G(1,0)B(1,1)G(1,2)B(1,3)...B(1,c-1)R(2,0),G(2,1),R(2,2)...B(r-1,c-1)
B G B G B GG B G B G B
The sensor matrix is:Code: [Select]R G R G R GG B G B G BR G R G R GG B G B G B
Hi,The code is to implement a simple smooth filter in the image.For a fixed row (having values R1 G1 R2 G2 R3 G3 ...), R2 is set to be (R1 / 4) + (R2 / 2) + (R3 / 4) and so on.The output file is generated in such a way.
//average odd with odd and even with even in each rowvoid raw_ave() { short i,j; unsigned short pixVal0, pixVal1, pixVal2, pixVal3; unsigned char *src; // Set pointer to picture raw data in memory src = (unsigned char *) hook_raw_image_addr(); // Loop through picture rows for (i=CAM_RAW_ROWS; i;i-=2){ // Loop through picture columns for (j=CAM_RAW_ROWPIX; j; j-=8, src+=10){ pixVal0= ((0x3fc&(((unsigned short)(*(src+1)))<<2)) | (*(src+0) >> 6)); pixVal1= ((0x3f0&(((unsigned short)(*(src+0)))<<4)) | (*(src+3) >> 4)); pixVal2= ((0x3c0&(((unsigned short)(*(src+3)))<<6)) | (*(src+2) >> 2)); pixVal3= ((0x300&(((unsigned short)(*(src+2)))<<8)) | (*(src+5))); pixVal0 = (pixVal0 + pixVal2)/2; pixVal2 = pixVal0; pixVal1 = (pixVal1 + pixVal3)/2; pixVal3 = pixVal1; *(src+1) = (unsigned char) ((pixVal0>>2)); // 0 *(src+0) = (unsigned char) ((pixVal0<<6)|(pixVal1>>4)); //0, 1 *(src+3) = (unsigned char) ((pixVal1<<4)|(pixVal2>>6)); //1,2 *(src+2) = (unsigned char) ((pixVal2<<2)|(pixVal3>>8)); //2,3 =>(2,0) *(src+5) = (unsigned char) ((pixVal3)); //3 (=>0) pixVal0=((0x3fc&(((unsigned short)(*(src+4)))<<2)) | (*(src+7) >> 6)); pixVal1=((0x3f0&(((unsigned short)(*(src+7)))<<4)) | (*(src+6) >> 4)); pixVal2=((0x3c0&(((unsigned short)(*(src+6)))<<6)) | (*(src+9) >> 2)); pixVal3=((0x300&(((unsigned short)(*(src+9)))<<8)) | (*(src+8))); pixVal0 = (pixVal0 + pixVal2)/2; pixVal2 = pixVal0; pixVal1 = (pixVal1 + pixVal3)/2; pixVal3 = pixVal1; *(src+4) = (unsigned char) ((pixVal0>>2)); // 4 => 0 *(src+7) = (unsigned char) ((pixVal0<<6)|(pixVal1>>4)); // 4,5 => (0,1) *(src+6) = (unsigned char) ((pixVal1<<4)|(pixVal2>>6)); // 5,6 => (1,2) *(src+9) = (unsigned char) ((pixVal2<<2)|(pixVal3>>8)); // 6,7 =>(2,0) *(src+8) = (unsigned char) ((pixVal3)); //7 (=>0) } for (j=CAM_RAW_ROWPIX; j; j-=8, src+=10){ pixVal0=((0x3fc&(((unsigned short)(*(src+1)))<<2)) | (*(src+0) >> 6)); pixVal1=((0x3f0&(((unsigned short)(*(src+0)))<<4)) | (*(src+3) >> 4)); pixVal2=((0x3c0&(((unsigned short)(*(src+3)))<<6)) | (*(src+2) >> 2)); pixVal3=((0x300&(((unsigned short)(*(src+2)))<<8)) | (*(src+5))); pixVal0 = (pixVal0 + pixVal2)/2; pixVal2 = pixVal0; pixVal1 = (pixVal1 + pixVal3)/2; pixVal3 = pixVal1; *(src+1) = (unsigned char) ((pixVal0>>2)); // 0 *(src+0) = (unsigned char) ((pixVal0<<6)|(pixVal1>>4)); //0, 1 *(src+3) = (unsigned char) ((pixVal1<<4)|(pixVal2>>6)); //1,2 *(src+2) = (unsigned char) ((pixVal2<<2)|(pixVal3>>8)); //2,3 =>(2,0) *(src+5) = (unsigned char) ((pixVal3)); //3 (=>0) pixVal0=((0x3fc&(((unsigned short)(*(src+4)))<<2)) | (*(src+7) >> 6)); pixVal1=((0x3f0&(((unsigned short)(*(src+7)))<<4)) | (*(src+6) >> 4)); pixVal2=((0x3c0&(((unsigned short)(*(src+6)))<<6)) | (*(src+9) >> 2)); pixVal3=((0x300&(((unsigned short)(*(src+9)))<<8)) | (*(src+8))); pixVal0 = (pixVal0 + pixVal2)/2; pixVal2 = pixVal0; pixVal1 = (pixVal1 + pixVal3)/2; pixVal3 = pixVal1; *(src+4) = (unsigned char) ((pixVal0>>2)); // 4 => 0 *(src+7) = (unsigned char) ((pixVal0<<6)|(pixVal1>>4)); // 4,5 => (0,1) *(src+6) = (unsigned char) ((pixVal1<<4)|(pixVal2>>6)); // 5,6 => (1,2) *(src+9) = (unsigned char) ((pixVal2<<2)|(pixVal3>>8)); // 6,7 =>(2,0) *(src+8) = (unsigned char) ((pixVal3)); //7 (=>0) } }}
Here is some code that I wrote to average odd with odd and even with even in each row. It seemed to work, but I realized that Canon does a better job of smoothing. Just choose an ISO of 400 or 800 when you develop the raws and Canon will apply smoothing for you.
littlejohn, This is not a noise. Dark points are bad bixels which should be removed before demosaic process
I've read your code and compared to mine, it seems that our programs do almost the same thing.So I put your raw_ave() function in the firmware and test two shots.One does average-filter (according your code) and the other one does not.The attachments are the two results (100% crop from the JPEG in camera, no postprocessing).The one which is applied filter still contains noise and the noise is too sharp to be ignored.I really cannot find any reason for that, I think I would give up if no one knows why Still thank you for your help!Best Regards,John
Started by LukeSkaff RAW Shooting and Processing
Started by SvobodaT RAW Shooting and Processing
Started by carl1864 General Help and Assistance on using CHDK stable releases
Started by neronix General Help and Assistance on using CHDK stable releases
Started by sf RAW Shooting and Processing