Author Topic: How to extract DSLR camera white balance information and set later?  (Read 7381 times)

Offline Jason Tackett

  • Newcomer
  • Posts: 44
    • Astrobin Page
I would like to use the camera white balance associated with a .CR2 image which is easy to accomplish with the DSLR_RAW format preferences. However, prior to applying the camera white balance I would like to subtract a master dark and apply cosmetic correction. The file types which result from these processes do not seem to store camera white balance information. Hence, I would like to get my hands on whatever coefficients that describe the camera white balance and apply them after I've calibrated the raw file and debayered.

How can I extract the camera white balance information and what process can I use to apply this information to a pure-raw image?

Thanks for the help,
Jason

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
the white balance information is stored in the EXIF header of the CR2 file. find "exiftool" out there on the web and,

% exiftool IMG_0000.CR2 | grep Balance

Blue Balance                    : 1.584961
Red Balance                     : 2.027344

[i think those are the right keywords - i also see "White Balance Red" and "White Balance Green" but those seem to be 0 in all of my images and i am guessing they are set if you have set a custom white balance]

green is assumed to be 1 and red and blue are relative to green.

having said all that, it is probably easier to color balance your images using the BackgroundNeutralization and ColorCalibration processes.

rob

Offline Jason Tackett

  • Newcomer
  • Posts: 44
    • Astrobin Page
Thanks for the information, Rob. Now that I have the white balance coefficients out of the EXIF header, do I need to simply multiply each channel by the corresponding coefficient with PixelMath or is some other process required?

Thanks,
Jason

Offline Carlos Milovic

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2172
  • Join the dark side... we have cookies
    • http://www.astrophoto.cl
It should be just a multiplication.
Regards,

Carlos Milovic F.
--------------------------------
PixInsight Project Developer
http://www.pixinsight.com

Offline Jason Tackett

  • Newcomer
  • Posts: 44
    • Astrobin Page
Thanks for the clarification, Carlos. Multiplication of the WB factors moves me in the right direction. I notice that when a DSLR RAW image is read in with the debayer-RGB format that the dynamic range is scaled to span the lower and upper limits of the image, but reading in the image as pure raw does not. So I need to figure out the order of debayering, multiplying with WB factors and rescaling to span the dynamic range. I plan to post back here once I think I've found the solution. In short I hope to know all of the steps that are performed under the hood when an image is read as debayer-RGB with the camera white balance applied.

Thanks again,
Jason
« Last Edit: 2015 August 07 12:04:16 by Jason Tackett »

Offline David Serrano

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 503
So I need to figure out the order of debayering, multiplying with WB factors and rescaling to span the dynamic range. I plan to post back here once I think I've found the solution. In short I hope to know all of the steps that are performed under the hood when an image is read as debayer-RGB with the camera white balance applied.

That would be pretty interesting. If you did that and if you had a spare bitcoin address to share, I'd happily invite you to a pizza. No kidding.
--
 David Serrano

Offline Jason Tackett

  • Newcomer
  • Posts: 44
    • Astrobin Page
It seems I am still struggling with this. The attached series of images shows an example of an image taking using a custom white balance in the camera. In all cases, a linked screen stretch is used.

Figure 1 shows how the image loads using de-Bayer RGB RAW format preferences where I kept the Camera White Balance checked. This is the white balance I would like to achieve.

Figure 2 shows the image loaded using Pure Raw RGB RAW format preferences then VGN de-Bayered with the Debayer process.

Using exiftool, I extracted the following red and blue balance coefficients: 1.397461 and 1.65918.

Figures 3 and 4 show the same image as Figure 2, but multiplied (Fig. 3) and divided (Fig. 4) by the red and blue coefficients. In both cases, they don’t match the white balance of the first image.

Is there any other way I can use the balance coefficients to re-create the white balance of Figure 1? For what it is worth, the balance coefficients are consistent with WB RGGB Levels reported by exif tool, so these should be the correct coefficients.

For those interested, the .CR2 file I am working with is here:

https://www.dropbox.com/s/fn6vl2od5qeb5nq/IMG_9612.CR2?dl=0

Thank you for any help,
Jason

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
i am into the territory of wild-ass guesses here.

i wonder if these multipliers in the EXIF are not meant for linear data... because for instance if you look at the image that's been debayered and had it's white balance applied thru DCRAW, the red channel mean is actually 0.979 * the green channel mean. likewise with the blue channel. the scaling between the channels is pretty mild, nowhere near the 1.397461 and 1.65918 shown in the EXIF.

rob



Offline vicent_peris

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 988
    • http://www.astrofoto.es/
Hi Jason,

Apply the preprocessing to the raw image. Then, open again that image but, this time, having your camera white balance and debayering it, without doing any preprocessing.

Now go to LinearFit, put your image with white balance as reference and apply it to your preprocessed image.


Best regards,
Vicent.

Offline Jason Tackett

  • Newcomer
  • Posts: 44
    • Astrobin Page
Thank you for the suggestion, Vicent. Linear fit gets me very close so that is a good work-around. I get the feeling that the mathematics of how camera white balance is set is handled by dcraw so I will have a look at the dcraw tutorial page which has some information about the multipliers.

Best,
Jason

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
btw, and this is just my opinion, but while i was messing with this i did a linear fit of the red and blue channels to the green channel. to me this yielded what seemed like a better white balance than what the camera computed; the sand looked white and the sky looked dark blue.

rob

Offline msmythers

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1178
    • astrobin
This is a fascinating discussion to me. I have an old Sony Nex-5(not great camera) that is modified. The camera does have a replacement IR/UV cut filter. I use a custom white balance on the camera shot from a white, black and 18% gray card during outside on a cloudless day. Camera generated jpgs always look fine and images white balanced through normal methods in PI always look fine.

I decided to look at the EXIF data and try to manual custom white balance via pixelmath and the exif wb numbers. My best results come from multiplying the red and blue channels and then linear fitting those channels to the green channel.

What I found interesting was what happened with using DSLR DCRaw format with AutoWB and CameraWB. Just looking the Auto is very close to the manual pixelmath/linearfit image but the camerawb is not. I'm not sure if dcraw is using the custom whitebalance from my camera. The truth is I don't think it matters(for me) since I have not had any bad white balance problems using PI's many methods of white balancing an image.

And just for grins I have screen dump of all the images next to each other. The lower right image is using AutoSTF on the camera white balance image.


Mike 

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729

I decided to look at the EXIF data and try to manual custom white balance via pixelmath and the exif wb numbers. My best results come from multiplying the red and blue channels and then linear fitting those channels to the green channel.


i think though that doing the linear fit will essentially undo the prior multiplication. i'd guess that the final result would be the same whether or not you do the exif WB multiplication or not.

rob

Offline msmythers

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1178
    • astrobin
rob

Like I said this is fascinating. For myself though the normal BN and CC is fine. I've used it with non-linear daytime images from old faded scanned film pictures. Just need a darker black area and a light gray to white area area. Works very well.


Mike

Offline miska

  • Newcomer
  • Posts: 28
This is really interesting. Since I am using a DSLR, I have always wanted to see how my BPP processed images would look like, if I could preserve the original WB associated with a raw file (for example, use the "Daylight" setting).
The BPP processed file would probably still need tweaking (esp if there is light pollution) but that might be easier than to start from scratch (although color calibration & background neutralization usually work quite well).