Author Topic: New script: Perfect color balance from an SLR camera  (Read 6665 times)

Offline jmurphy

  • Newcomer
  • Posts: 3
New script: Perfect color balance from an SLR camera
« on: 2015 August 07 17:44:04 »
This is my first script, and my very first attempt at using Java Script. Feel free to improve the script or provide advice. I have tested it with my own SLR camera.
The script should produce excellent color balance for an SLR camera provided that no filter is used and the camera has not been modified. In either of these two cases, see the next post by Mike (msmythers) and my reply.

SLR cameras are calibrated for accurate color balance. It is therefore possible to create an integrated stack with perfect color balance. The only color correction required will be to subtract any light pollution background (e.g. use DBE or BackgroundNeutalization).

To achieve this, this script modifies the RGGB pixels in a master CFA Bayer flat so that:
   (1) Any color cast is removed from the flat
   (2) The user supplied color balance is applied to the RGGB pixels

The script requires a master flat (.fit or .xisf). It must not be DeBayered. When creating the master flat, make sure to set the raw format to pure bayer:
Format Explorer -> DSLR_Raw <double click> Pure Raw
I use the ImageCalibration tool rather than the BatchPreprocessing script, so I have not tested this script with flats calibrated with BatchPreprocessing.

To determine the color balance values, take a photo with the white balance set to 'Daylight'. The contents of this image, and the lighting is not important. Load the raw image into PixInsight. In the Console, look for:

   Camera multipliers: 2255.000000 1024.000000 1730.000000 1024.000000

These values are for the Canon 5Dmk2, and correspond to Top left (Red), Top right (Green), Bottom Right (Blue), Bottom Left (Green). However, provided you enter the correct scaling factor for the bayer positions (e.g. top left, top right, bottom right, bottom left) the actual bayer pattern should not matter. Note that a high value refers to a pixel color with lower sensitivity.

I have also attached an image processed with a sky flat that had been processed with this script. No extra color balance changes were required, only background light pollution subtraction. The image was taken with a 5Dmk2 + 100mm lens at F2.8, Astrotrac, 52 x 120 second exposures. I applied some noise reduction and a histogram stretch to the raw stack.

The script's initial aim was to remove the blue cast from sky flats (it can still do this - just set all the multipliers to 1). Now that it also compensates for the camera's white balance I should probably rename the script.

Hope it is useful
John Murphy
« Last Edit: 2015 August 08 07:38:57 by jmurphy »

Offline msmythers

  • PTeam Member
  • PixInsight Jedi
  • *****
  • Posts: 1178
    • astrobin
Re: New script: Perfect color balance from an SLR camera
« Reply #1 on: 2015 August 07 18:50:17 »
Nice John.

Let me see if this is how you would use your script with a modified camera. First set a custom white balance however like with an 18% gray card. It just needs to be a good white balance. Record an image using that custom settings. Take that image and open it with PI and read the camera multipliers for that image. Now we have the multipliers for that custom white balance for that modified camera. As long as we always use that custom white balance for all images captured with that modified camera we will be able to use those multipliers and your script should produce a very color balanced stacked image.


MIke

Offline jmurphy

  • Newcomer
  • Posts: 3
Re: New script: Perfect color balance from an SLR camera
« Reply #2 on: 2015 August 07 22:08:01 »
Hi Mike

Good thinking - yes I believe that the custom white balance values will also be displayed in the PixInsight Console. Obviously when setting up the custom white balance you will need to wait for a sunny day - ideally with full sun and a blue sky. A gray card would be ideal, but even just a white sheet of paper should do the trick. Make sure the card or paper fills the whole  field of view when creating the custom white balance. Once the custom white balance is recorded, any shot recorded with that white balance (image content does not matter, lighting does not matter) should produce the correct numbers in the PixInsight Console. Make a note of the numbers.
The raw format simply records the color balance values into the raw file. It does not modify the image. So once you know what the numbers are, you don't even need to worry what light balance the camera was set to. Hence you will even be able to reprocess old images correctly.

John