Re: Extracting green channel from FITS
Posted by johnk on Feb 17, 2022; 10:18am
URL: http://astroimagej.170.s1.nabble.com/Extracting-green-channel-from-FITS-tp1750p1762.html
You will need the RGB Bayer mask pattern for your sensor. It may start in the first row as R, then G, then R or some other pattern.
Sequence will generate a separated set of FITS files with the same size as the original. Since the mask filters are over alternate pixels with 2x as many G as R and B there's a weighting that's invoked to assign a value and I don't know what that is.
Load the image into AIJ
Find the background (for this image it was ~8500)
In the IJ menu use Process -> Math -> Subtract and remove the background
In the IJ menu use Image -> Type -> 16 bit
In the AIJ menu use Color -> Debayer and select the Bayer pattern order. This one may be R-G-R-G.
The result is an image stack with three images R, G, and B with the same number of pixels as the original. The slices represent a color assignment based on the Bayer pattern and using adjacent pixels to set the color slice flux.
In the AIJ menu use Color -> Make composite image
The result is an RGB stack
Use AIJ Contrast and set fixed brightness and contrast
Select the Red, Green, and Blue images in sequence and for each one set the range of the display. This affects the color balance.
Use File -> Save image as PNG, PDF, or JPG to create an image in a standard 8-bit color file format
Use Color -> Stack to images to separate the 3 color slices to independent frames.
Now you can store each of these and they will be named Red, Green and Blue so you could try photometry on them as you would with any filtered image though I expect using an aperture that is large enough to capture 2 or more pixels would be best.
Also, you may find that ds9 in RGB mode is an effective way to look at the resultant color image. You'd start it with the -rgb flag (e.g. ds9 -rgb) and then tick the "red" file on the RGB menu and load the red image ... With all three loaded you can adjust the colors by changing the scale. For this, ds9 has controls that change the image with out changing the data, for example applying a log stretch or other display mappings that will make the image more realistic.
There is also Python code that will separate your FITS image into 3 images I can provide if you want to try that. The code I have will reduce the FITS image size by 2x in both dimensions because it uses the R, G, and B pixels to create R, G, and B images directly. The working part for an R-G-R-G pattern is to copy the image into an array "outimage", set the output height and width
h, w = outimage.shape
oh = h//2
ow = w//2
r_image = outimage[0::2, 0::2] # [odd, odd] -> rows 0,2,4 columns 0,2,4
b_image = outimage[1::2, 1::2] # [even, even] -> rows 1,3,5 columns 1,3,5
g0_image = outimage[0::2, 1::2] # [odd, even] -> rows 0,2,4 columns 1,3,5
g1_image = outimage[1::2, 0::2] # [even, odd] -> rows 1,3,5 columns 0,2,4
# Trim to size and average the g images
r_image = r_image[:oh,:ow]
b_image = b_image[:oh,:ow]
g_image = g0_image[:oh,:ow]//2 + g1_image[:oh,:ow]//2
The idea is that since you have 2 G's contributing to each pixel in this reduced size image, the G filter will be an average of those for that pixel.
Once you create the 3 FITS files this way, you can load them into AIJ as 3 different images stacks for simultaneous photometry in R, G, and B. The usual filters on a color imager are rather close to the Johnson-Cousins B, V, and R.
I expect someone could write a macro for AIJ that would do the same thing. However let me know if you want a copy of a working Python program that takes the color fits file as a command line argument and delivers the color slices.