Bit depth of raw files? - page 3 - RAW Shooting and Processing - CHDK Forum

Bit depth of raw files?

  • 37 Replies
  • 22182 Views
Re: Bit depth of raw files?
« Reply #20 on: 29 / July / 2008, 06:23:22 »
Advertisements
yey. i did it. the secret is really in that line of codes.  should have figured it out earlier if i looked into it harder.
thanks for the help.

*

Offline littlejohn

  • *
  • 35
  • Ixus 860is
Re: Bit depth of raw files?
« Reply #21 on: 03 / September / 2008, 11:33:21 »
The sensor matrix is:
Code: [Select]
R G R G R G
G B G B G B
R G R G R G
G B G B G B

And 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

Hi, thanks for the valuable information!
I want to apply a smoothing filter on the CHDK's RAW file, but the results went wrong somehow.
So I tested a little bit: by setting each 10-bit value to its maximum (1023) and use dng4ps2 to create a DNG file.
It's the sensor matrix I got:
Code: [Select]
B G B G B G
G B G B G B
For example, assigning 1023 0 1023 0 1023 0 ... (each 10-bit long) on each EVEN row would give me a blue image.
Assigning 0 1023 0 1023 0 1023 ... on each EVEN row would give me a green image.
Assigning 1023 0 1023 0 1023 0 ... on each ODD row would give me a green image.
And last, assigning 0 1023 0 1023 0 1023 ...on each ODD row would give me a blue image.
It's quite strange. (since I didn't see any RED image)
I've tested for hours but didn't know why.
My code is modified from trunk's raw_merge.c, so I was assuming the process didn't go wrong.
If anyone knows what's my problem, please tell me.
Any help is appreciated!  :(

PS. Assigning all zeros to a CHDK RAW file and convert to DNG. The result is a black image.
However, by setting the first 10-bit sensor data to maximum (1023) with all others 0, the result becomes a GREEN image.
I think it should be a black image with a green point inside, while it is not. @@
« Last Edit: 03 / September / 2008, 11:54:45 by littlejohn »

*

Offline littlejohn

  • *
  • 35
  • Ixus 860is
Re: Bit depth of raw files?
« Reply #22 on: 03 / September / 2008, 14:08:29 »
The sensor matrix is:
Code: [Select]
R G R G R G
G B G B G B
R G R G R G
G B G B G B

This is what I tried to implement: (take the first row for example)
Note that the RAW data collects (R)ed (G)reen (R)ed (G)reen ... at the first row.
Let the values be R1 G1 R2 G2 R3 G3 ..., etc.
My attempt is to set R2 = (R1 / 4) + (R2 / 2) + (R3 / 4) and G2 = (G1 / 4) + (G2 / 2) + (G3 / 4), and so on.
I was thinking that would smooth the whole image since the sharper pixel would be averaged out. (I guess)
Don't know if it is correct or not.
Thanks

*

Offline littlejohn

  • *
  • 35
  • Ixus 860is
Re: Bit depth of raw files?
« Reply #23 on: 04 / September / 2008, 07:08:13 »
Hi,

This is my source code: (I think it's readable)
http://oz.nthu.edu.tw/~d924324/c.c
Also I have a CHDK RAW here for testing (CRW_2211.CR2): zSHARE - crw_2211.cr2
Of course you can switch to any RAW file by modifying one line of the C code.
This will generate another RAW file named CRW_OUT.CR2, which can be transformed to DNG by dng4ps2.

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.

However, the output file (CRW_OUT.CR2) has some noise which the original RAW does't have.
If anyone is able to check this out and know what's the problem, please tell me.  :)
Thanks a lot.


Re: Bit depth of raw files?
« Reply #24 on: 04 / September / 2008, 10:51:21 »
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.


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.
Code: [Select]

//average odd with odd and even with even in each row
void 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)
}
}
}



*

Offline littlejohn

  • *
  • 35
  • Ixus 860is
Re: Bit depth of raw files?
« Reply #25 on: 04 / September / 2008, 11:04:10 »
Thank you, Jon!  :D
I'll study your code carefully.
I'm doing this for the mimic of 'portrait enhancer mode' of Fujifilm's DC.
So I would like to apply some "heavier" smoothing filter in camera's memory before it is saved in our SD card.

Thanks again!  :xmas

*

Offline littlejohn

  • *
  • 35
  • Ixus 860is
Re: Bit depth of raw files?
« Reply #26 on: 05 / September / 2008, 05:24:45 »
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.

Dear Jon,

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
« Last Edit: 05 / September / 2008, 05:42:35 by littlejohn »

*

Offline ArtDen

  • ***
  • 175
    • dng4ps2
Re: Bit depth of raw files?
« Reply #27 on: 05 / September / 2008, 06:48:38 »
littlejohn, This is not a noise. Dark points are bad bixels which should be removed before demosaic process


*

Offline littlejohn

  • *
  • 35
  • Ixus 860is
Re: Bit depth of raw files?
« Reply #28 on: 05 / September / 2008, 07:17:58 »
littlejohn, This is not a noise. Dark points are bad bixels which should be removed before demosaic process

Dear ArtDen,

Thanks for the information. :D
Could you give me some hints about how to remove those bad pixels?
Since all I tried to do is to assign the average value between each neighboring R/G/B,
I don't know what I can do to prevent those dark points from happening.
And I have no idea how that came out.

Thanks,
John
« Last Edit: 05 / September / 2008, 07:50:32 by littlejohn »

Re: Bit depth of raw files?
« Reply #29 on: 05 / September / 2008, 10:36:45 »
Hi John,
Those are too many points to be bad pixels.  I seems a random pattern of errors introduced by the processing.   I don't get such points on my camera, a 720is.  Perhaps some other task is interfering with the read or write of the pixel data.
Jon

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

 

Related Topics