Author Topic: Possible workaround for color flats with DSLR  (Read 6193 times)

Offline astroedo

  • PixInsight Addict
  • ***
  • Posts: 171
  • Io ne ho viste... cose che voi umani...
    • L'arciere celeste
Possible workaround for color flats with DSLR
« on: 2012 August 16 13:28:46 »
Hello to all forum users,
My name's Edoardo Radice from Italy.

I am a beginner with pixinsight (at the moment i have only a trial licence) and i'm learning basics.
Being a DSLR user one of my first concerns was about colored flats (taken on morning sky or with light pollution filters).

I usually use Iris for frame calibration: here exists a GRAY_FLAT command that turns a colored flat in a gray one.
in Maxim exist a "boxcar filter" that does something similar.

In PI it seems that does not exist something similar (i have found a few forum topics about this, i hope i haven't missed something important  :P ).

Although many PI expert says that colored flats are not a problem (obviously i can correct color hues with color balance and background neutralization), i prefer starting with a gray flat.

Googling on the internet i have found somewhere that a low pass filter with the scheme

1 1 0
1 1 0
0 0 0

can fix the problem, so i've tried to create it with pixel math.
Following the PM tutorial i wrote this expression that works quite well

x = XPos();
y = YPos();
left = x-1;
top = y-1;
plt = Pixel( $target, left, top );
pt = Pixel( $target, x,   top );
pl = Pixel( $target, left, y   );
p = Pixel( $target, x,   y   );
(p+pl+pt+plt)/4

(you can find GrayFlat.xpsm as attachment).

Just to test the procedure, i opened a master flat from my canon 350D with an Astronomik CLS filter.

in sflat_RGB_VNG.jpg   you can see the debayered version of the flat with the blue hue caused by the filter.

in sflat_RGB_VNG_gray.jpg  you can see the debayered version of the flat after application of the pixel math instace.

finally sflat_flattened_with_gray.jpg you can see the debayered version of the "blue" flat flattened with the gray flat: there is no change in color hue after flattening and the field appears well flattened.

Obviously applying a low pass filter some information in your original flat is loosen, so you cannot anymore use your calibrated frames for scientific uses like photometry.
But if your goal is only to produce a nice picture to share with friends this procedure can be useful.

Comments and advice are welcome

Bye

Edoardo


Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
Re: Possible workaround for color flats with DSLR
« Reply #1 on: 2012 August 16 14:34:11 »
i'm not sure why you would do this. when i use camera lenses for AP, i can see that the shape of the vignetting is different in each channel, if i debayer my master flat.

by combining all the channels together you are making a new illumination profile that does not correspond to any one of the channels.

i hear people talking about greyscale flats together with OSCs and i just don't understand. maybe i'm missing something.


Offline astroedo

  • PixInsight Addict
  • ***
  • Posts: 171
  • Io ne ho viste... cose che voi umani...
    • L'arciere celeste
Re: Possible workaround for color flats with DSLR
« Reply #2 on: 2012 August 19 03:47:06 »
Hello pfile, thanks for reply,
i want to explain you my concerns so you, maybe, can explain me where i'm wrong.
Given that my idea is not a real "solution", my problem is that using a colored flat introduce a strong color bias in images.
In fact lets call Lxy our light frame calibrated with bias and dark (xy subscript says that L is "pixel dependent") we can write

Lxy=(Sxy+Bxy)*Exy

where Sxy is signal from source, Bxy is Background signal and Exy is "Efficiency factor" that contains Pixel by pixel Quantum efficiency differences, vignetting and

"dust effect".

Our flat frame will be

Fxy=K*Exy.

In the above expression K is a constant depending mainly on light source intensity, exposure time and, if the flat is colored, wavelength (or to simplify, color

channel).

Calibrating My Light frame i obtain my calibrated light frame Cxy

Cxy=Lxy/Fxy=(Sxy+Bxy)/K

since i'm interested in Sxy, solving the above equation

Sxy=K*Cxy-Bxy

or, in the very simple case with a constant background

Sxy=K*Cxy-B

Remember that the above expression is "vectorial" in fact i have a similar equation for each color channel

If K depends on color channel i introduce a color bias to my final image.
Color balancing this image means finding K and B
Since we have two variables we need two independent equations (or six if we write explicit equations for color layers) to solve the problem.

This is the reason fo wich i have to use a white reference and a background reference in color calibration process:

If
Cw is the average (or median) level in my White reference and Wr is expected white level
and
Cb is the average (or median) level in my Background reference and Br is expected level in background area (near 0) i can write the system

Wr=K*Cw - B
Br=K*Cb - B
for each color channel whose solution is

K=(Wr-Br)/(Cw-Cb)
B=(Wr-Br)/(Cw-Cb)*Cw-Wr


The problem is that many times you do not have a good white reference (for example an unsaturate G star) so calibratin color is very difficult.

I you have a neutral flat you have only to care about background effect.

A good solution can be extracting R B G values from bayer matrix, calculating average or, better, median value for each distribution an than calculating an appling the correction factor.
Where i'm wrong in my concerns?


Edoardo


 
« Last Edit: 2012 August 19 03:53:50 by astroedo »

Offline Ignacio

  • PixInsight Old Hand
  • ****
  • Posts: 375
    • PampaSkies
Re: Possible workaround for color flats with DSLR
« Reply #3 on: 2012 August 19 08:09:04 »
Have you tried neutralizing your masterflat using "background neutralization" over the whole image?

best
Ignacio

Offline astroedo

  • PixInsight Addict
  • ***
  • Posts: 171
  • Io ne ho viste... cose che voi umani...
    • L'arciere celeste
Re: Possible workaround for color flats with DSLR
« Reply #4 on: 2012 August 19 08:12:45 »
thank you Ignacio for reply.

No, i cannot, my master flat is a Color filter array image (not debayered yet) so it is gray scaled.

Color balancing has to be done on debayered images.

Best regars

Edoardo

Offline Ignacio

  • PixInsight Old Hand
  • ****
  • Posts: 375
    • PampaSkies
Re: Possible workaround for color flats with DSLR
« Reply #5 on: 2012 August 19 10:17:27 »
Of course, you are right. Guess you will have to use weights obtained from neutralizing the rgb masterflat, to rebalance your masterlight. I must say, however, that I never had too much of a problem dealing with strongly unbalanced masterlights (due to unbalanced flats, or simply due to different sensor sensitivity per channel).

Ignacio

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
Re: Possible workaround for color flats with DSLR
« Reply #6 on: 2012 August 19 10:26:00 »
maybe i misunderstood what you are trying to do. i thought you were trying to convert the flat to greyscale but i think you are just trying to 'normalize' the histogram so that the peaks of the 3 channels line up on one another, after debayering the master flat - you are manipulating the CFA data before debayering to align the histogram peaks after debayer.

i understand the problem now (i also use a CLS filter). however, since you shoot your lights thru the filter as well, i don't understand why using a "grey" flat fixes the color balance problem. the lights still have the color cast. perhaps the cast is worse after applying the flat but it should still be there.

what i've always done is just let the STF tool align the RGB channels by uncoupling the channels and applying the autoSTF. this does a surprisingly good job of getting you most of the way to the correct color balance.

now, i think the real problem with the CLS filter is this: you have a color cast because the filter has cut out a bunch of wavelengths which would ordinarily stimulate the red-filtered pixels on the CFA. in other words, the red channel is very weak compared to the G and B channels. i believe that when the G and B channels are properly exposed in a CLS flat, that the R channel is actually underexposed, and this leads to banding noise in the flat, which is then put into the calibrated light.

so, i think the best way to accomplish what you are trying to do is to use a light source which is more red, such that the flat comes out color balanced to begin with. but i have not tried this at all. i guess you could calculate the right color mix by shooting a grey card with the filter in and then asking the camera to compute the custom white balance. the scaling factors should indicate the relative R,G,B strengths of the light source you use for the flat.

Offline astroedo

  • PixInsight Addict
  • ***
  • Posts: 171
  • Io ne ho viste... cose che voi umani...
    • L'arciere celeste
Re: Possible workaround for color flats with DSLR
« Reply #7 on: 2012 August 19 13:06:05 »
Ok!  ;)

I've tried!!!  :D

You're right, it works really well if your object is quite small compared to the frame, thank you for advice.

Bye

Edoardo

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 627
    • Astronomy Pages G.W.
Re: Possible workaround for color flats with DSLR
« Reply #8 on: 2012 August 19 13:40:44 »
Hi Edo!
Had the same issue with my flats. Solved this in Pixinsight
with the  Process ChannelMatch. The basic idea is to move
all pixels half a pixel up and right. This brings the different histogrammpeaks together to one.
Steps:
1.)Convert RAW file with Process "ConverttoRGBColor" to a Pseudo RGB File
2.)Move each pixel 0.5 Pixel right and down with ChannelMatch - the settings are:
  X-Offset R 0.5, G 0.5, B 0.5     Y-Offset R -0.5, G -0.5, B -0.5
3.)Convert PseudoRGB File back to RAW with "ConvertroGrayscale"
This gets you a RAW gray flatfield for use in calibration. 
You can check the process with the histogramm on.   

It worked fine for me.

Aloha Gerald