Need help with converting RAW Bayer data to RGB - RAW Shooting and Processing - CHDK Forum

Need help with converting RAW Bayer data to RGB

  • 5 Replies
  • 6705 Views
Need help with converting RAW Bayer data to RGB
« on: 12 / June / 2013, 01:55:12 »
Advertisements
I'm trying to reconstruct RGB from RAW Bayer data from a Canon DSLR but am having no luck. I've taken a peek at Dave Coffin's dcraw.c source, but its lack of comments makes it a bit tough to interpret. Anyway, I have debayering working but I need to then take this debayered data and get something that looks correct. My current code does something like this, in order:

Demosaic/debayer
Apply white balance multipliers (I'm using the following ones: 1.0, 2.045, 1.350. These work perfectly in Adobe Camera Raw as 5500K, 0 Tint.)
Multiply the result by the inverse of the camera's color matrix
Multiply the result by an XYZ to sRGB matrix fromm Bruce Lindbloom's site (the D50 sRGB one)
Set white/black point, I am using an input levels control for this
Adjust gamma
Some of what I've read says to apply the white balance and black point correction before the debayer. I've tried, but it's still broken.

Where am I going wrong here?

Re: Need help with converting RAW Bayer data to RGB
« Reply #1 on: 12 / June / 2013, 02:27:30 »
Personally, I think what you are doing wrong is trying to reinvent the wheel yourself.  Why not use something like ufraw (which is based on dcraw) to do what you want?  It has options for pretty well every feature you mentioned.  Maybe you can get a clearer picture of what to do by looking at the ufraw source code.  Then again, maybe not, because there is some duplication between the new ufraw code in C++ and the original dcraw code in C, and it can get confusing as to what is being used.

If the point _is_ to reinvent the wheel yourself, then that's fine, there's a lot to be gained by that.  But if you just want to convert your raw images, then I'd go with ufraw or Therapee or one of the commercial products out there.

Re: Need help with converting RAW Bayer data to RGB
« Reply #2 on: 12 / June / 2013, 05:17:11 »
Well, I would like to figure this out as I've already spent a lot of time on it. I feel like I'm very close, and I understand image processing to an extent but I am having trouble with the sequence of operations. I suspect each one must be performed in order and that's where my code is failing. Basically, What would help is a "checklist," in order, of which operation to perform and when to invert matrices, normalize values, etc. (assuming I'm in the ballpark here).

*

Offline PS

  • ***
  • 157
  • A610 1.00f
Re: Need help with converting RAW Bayer data to RGB
« Reply #3 on: 12 / June / 2013, 07:18:23 »
What exactly is broken? I convert CHDK raw to ppm, though without matrix transformations.
« Last Edit: 12 / June / 2013, 07:30:58 by PS »


*

Offline reyalp

  • ******
  • 14118
Re: Need help with converting RAW Bayer data to RGB
« Reply #4 on: 12 / June / 2013, 13:21:46 »
You could also look adobe's DNG SDK code http://www.adobe.com/support/downloads/dng/dng_sdk.html

I think dng4ps2 uses a version of this. You can find the dng4ps2 code at http://code.google.com/p/dng4ps2/source/browse/#svn%2Ftrunk
Don't forget what the H stands for.

Re: Need help with converting RAW Bayer data to RGB
« Reply #5 on: 13 / June / 2013, 02:22:15 »
Maybe I'm missing a step to give more weight to the red and blue channels after debayering. Because green is given more weight, there's a green tint to the raw debayered output. If I multiply the red and blue channels, that brings all the channels closer (this is before I do white balance).

Does this sound like it might be a factor?

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal