Author Topic: Debayering doesn't look right?  (Read 2923 times)

Offline fnord123

  • Newcomer
  • Posts: 12
Debayering doesn't look right?
« on: 2016 July 15 10:49:49 »
When I debayer it seems like the stars get smoother, but the background gets a lot noisier. I am curious if this is expected or if I am doing something wrong.

I am using an ASI1600MC OSC CMOS camera, capturing FITS files using SharpCap in 24 bit color.  Here's an example: https://drive.google.com/file/d/0Bw193BVETes-cG5LcmJjVWN2ZW8/view?usp=sharing

The attached image shows a preview from the above FITS file. The top image is unchanged (except for STF autostretch), while the bottom is VNG debayered using an GRBG pattern (and then STF autostretched).  Is this how debayering should look?

Offline fnord123

  • Newcomer
  • Posts: 12
Re: Debayering doesn't look right?
« Reply #1 on: 2016 July 15 10:58:28 »
For reference, here is a link to a post-calibrated version of the same image (no debayering performed).  I've also attached a thumbnail of the same image, with the top stf-autostretched and the bottom debayered then stf-autostretched.  The debayered image also looks more noisy to me, but is that just a function of the STF autostretching it differently?

https://drive.google.com/file/d/0Bw193BVETes-Mk5CaWhvUVNlRlk/view?usp=sharing

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
Re: Debayering doesn't look right?
« Reply #2 on: 2016 July 15 14:58:41 »
STF looks at the noise statistics of the target image to figure out how to stretch, so the noise will definitely affect the stretch.

rather than eyeballing it, you can use the "NoiseEvaluation" script on the pre- and post- debayered images to see which one has more noise (if either). i would expect the green channel of the debayered image to have less noise, around 1.4x less, than the bayered image. if the bayered image is CFA you might have to do SplitCFA in order to see the noise in each channel. otherwise you're looking at all the channels at once which is probably not what you want.

rob

Offline fnord123

  • Newcomer
  • Posts: 12
Re: Debayering doesn't look right?
« Reply #3 on: 2016 July 15 16:20:51 »
Thanks - I ran the noise evaluation against all the images I showed:

Raw FITS image:
* Channel #0
?R = 1.766e-03, N = 1076052 (26.26%), J = 4
* Channel #1
?G = 2.753e-03, N = 2904828 (70.90%), J = 4
* Channel #2
?B = 1.756e-03, N = 1036588 (25.30%), J = 4

FITS Image with VNG GRBG Debayer:
* Channel #0
?R = 2.857e-03, N = 2545616 (62.13%), J = 4
* Channel #1
?G = 2.799e-03, N = 3037841 (74.14%), J = 4
* Channel #2
?B = 2.872e-03, N = 2529374 (61.73%), J = 4

Calibrated Image:
* Channel #0
?R = 1.561e-03, N = 1202659 (29.35%), J = 4
* Channel #1
** Warning: No convergence in MRS noise evaluation routine - using k-sigma noise estimate.
?G = 0.000e+00, N = 4092669 (99.89%), J = 1
* Channel #2
?B = 1.644e-03, N = 1496364 (36.52%), J = 4
Calibrate

Calibrated Image with VNG CRBG Debayered:
* Channel #0
?R = 1.019e-03, N = 518440 (12.65%), J = 4
* Channel #1
?G = 1.777e-04, N = 207715 (5.07%), J = 4
* Channel #2
?B = 7.714e-04, N = 1936459 (47.26%), J = 2

I find it interesting that the raw image has higher noise after debayering, but the calibrated has less after debayering - and the overall winner is the calibrated, debayered image in terms of lowest noise.  Is this to be expected? My understanding is debayering is usually done after calibration, although I am a bit unclear as to why - is it that calibration removes artifacts from heat, readout, etc., allowing debayer to be more accurate in compensate for bayering?

Also, I tried the SplitCFA tool, which produced four images (R, G, G, B I assume).  I analyzed the noise levels of those and got results I don't understand at all:
R (from CFA0 folder):
* Channel #0
?R = 2.559e-03, N = 891592 (87.04%), J = 4
* Channel #1
?G = 3.770e-03, N = 979201 (95.60%), J = 4
* Channel #2
?B = 2.603e-03, N = 909637 (88.80%), J = 4

G1 Channel (CFA1 file)
* Channel #0
?R = 1.839e-03, N = 697302 (68.07%), J = 4
* Channel #1
?G = 2.144e-03, N = 901068 (87.97%), J = 4
* Channel #2
?B = 3.517e-03, N = 988900 (96.54%), J = 4

G2 channel (CFA2 file)
* Channel #0
?R = 3.447e-03, N = 976155 (95.30%), J = 4
* Channel #1
?G = 2.145e-03, N = 902547 (88.11%), J = 4
* Channel #2
?B = 1.854e-03, N = 707482 (69.07%), J = 4

B channel (CFA3 file)
* Channel #0
?R = 2.558e-03, N = 892103 (87.09%), J = 4
* Channel #1
?G = 3.772e-03, N = 979428 (95.62%), J = 4
* Channel #2
?B = 2.607e-03, N = 908318 (88.68%), J = 4

The CFA noise evaluations were all over the map, and had noise levels when I didn't expect them.  Why doesn't e.g. the B channel have 0 noise on the R and G channels?
« Last Edit: 2016 July 15 18:15:57 by fnord123 »

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
Re: Debayering doesn't look right?
« Reply #4 on: 2016 July 15 20:52:42 »

I find it interesting that the raw image has higher noise after debayering, but the calibrated has less after debayering - and the overall winner is the calibrated, debayered image in terms of lowest noise.  Is this to be expected? My understanding is debayering is usually done after calibration, although I am a bit unclear as to why - is it that calibration removes artifacts from heat, readout, etc., allowing debayer to be more accurate in compensate for bayering?


i think it makes sense; the calibrated image will have less fixed pattern noise since that should be removed by dark subtraction. of course there's some shot noise in the dark signal contained in the master dark which is injected into the calibrated frame, but clearly in this case the removed FPN must have been of greater magnitude than the dark shot noise.

the reason you need to calibrate before debayering is that you need to calibrate the raw data from the sensor. each pixel has its own quantum efficiency, it's own bias voltage, and its own response to thermal input (magnitude of dark signal as a function of time). any debayering method which interpolates pixels basically mixes up all these signals slightly differently between the light and the dark, which then makes proper calibration impossible. some debayering methods even consider the G channel while constructing R and B. for a well-exposed daytime picture this probably works great but for an astronomical image with super low signal, it could lead to wildly different behavior when debayering a light vs. a dark.

you might argue that superpixel debayering is OK, and it *almost* is, but it averages together the two green pixels in a bayer quad, which has a similar effect to interpolation.

as for the SplitCFA results, i think i'll have to run thru it with one of my old DSLR files. i don't understand why your split out files are seemingly RGB; thought they should be mono. i just tried it and i indeed get mono xisf files out which are 1/2 the X/Y dimensions which is what i would expect. are your fits truly CFA (mono) files, or are they bayer RGB?

rob

Offline fnord123

  • Newcomer
  • Posts: 12
Re: Debayering doesn't look right?
« Reply #5 on: 2016 July 17 09:39:09 »
Thanks for the explanation on ordering, it helps my understanding.  I've already been through The Deep Sky Imaging Primer once quickly, and am now re-reading and between that and these forums am learning a lot.

One thing I realized was I was pulling a stupid in terms of image capture setup - I had DSS set to capture RGB24, under the assumption that since my camera is OSC that I should use a color setting.  Between this thread and the Primer I now assume I should be capturing bias, lights, darks, flats, etc., all in RAW16.  This will allow me to use the (presumably better?) debayering of PI rather than using the camera's built in debayering which I assume is what happens if I select RGB24, and also allows better calibration as you described.  Thanks so much for your help and patient explanation :)