Extracting green channel from FITS

classic Classic list List threaded Threaded
70 messages Options
1234
Reply | Threaded
Open this post in threaded view
|

Extracting green channel from FITS

Bill Tschumy
I'm looking into using AIJ for preparing files for photometry (the actual photometry will be using the AAVSO VPhot service).  The images were captured using a DSLR and ASIAir and are in FITS format.

Is there a feature in AIJ for extracting just the Green component of the FITS so I can work only with that and report my results as being taken with a TG filter?  With all the amazing functionality of AIJ you would think it would be possible, but I haven't found it.

Thanks,
Bill
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

karenacollins
Administrator
Hi Bill,

Does the Image_Display > Color > "Split RBG image into three 8-bit images" option do what you need?

Karen
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

Bill Tschumy
No, I've tried that but it says:  

"Multichannel Image Required."

The FITS file definitely has the 3 channels, but I suspect it is requiring they be debayered.

Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

karenacollins
Administrator
I don't work with color images much, so I'm rusty on this functionality of the top of my head. But, I think the split functionality is looking for a color RBG image, rather than a three image fits file. Can your camera provide that format.

Calling all AIJ users that have color image processing experience: if you have suggestions to help Bill, please chime in on this thread.
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

karenacollins
Administrator
I did verify that the split function works on color jpeg or png images.
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

Bill Tschumy
I'm pretty sure that debayering into an RGB image will invalidate the photometry.  You need to stick with raw images the entire time.
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

karenacollins
Administrator
Could you send an example fits file from your camera. We'll need to take a look to understand how it is structured. If the file is small enough to email, send it to karenacollins atatat outlook dotdot com. Replace the characters with the appropriate symbols.

Karen
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

Bill Tschumy
Karen,

I've uploaded one to my web server:

https://www.otherwise.com/Light_RAur_30.0s_Bin1_20220207-200746_0001.fit

When you download it, be sure it doesn't add a .txt to the file.  I've seen it do that with formats it doesn't recognize.  I've been able to open this file in all sorts of apps that handle FITS.  

Thanks for taking the time to look at this.  My guess now is that this is just not possible in AIJ.

Bill
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

karenacollins
Administrator
This post was updated on .
Hi Bill,

(See JohnK's message below. He has a good deal of color image processing experience. He has provided the detail that you need. Also, the latest AIJ v5 daily build update (v5.0.1.06 and later after update) now opens your 16 bit image correctly.)

I've taken a look at your fits file. I'm not sure what it's exact format is, but I think it has the red, green, and blue data encoded in a square set of 4 pixels each with some combination that includes "RGGB" according to the fits header, where the green pixel is repeated twice as part of the pattern. If you are wanting to process only the green data, I think you'll need some sort of debayer process to separate the pixels containing the green data.

You can process the image using the debayer option under the AIJ Color menu. A stack of three images is produce with each of a R, G, and B image.

I noticed in the ZWO ASIAIR User Manual a "Debayer" option labeled "7" in the image below. However, I can not see the options available as part of that function. Does it allow you to save only the green pixel data?

Karen

Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

johnk
In reply to this post by Bill Tschumy
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.

Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

karenacollins
Administrator
Thank you John!

Karen
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

Bill Tschumy
John,

Thanks for you detailed reply.

I'm a bit leery of doing what you suggest since it is not totally clear how the data will be effected.  

The other apps I use to do this take a 3 color FITS file (RGGB), extract just the green channel, and write it back to another FITS file with the same basic header (except it indicates it is now one channel).  They also halve the dimensions (effectively binning the result).

What you suggest for AIJ sounds like it is converting into an RGB image and then separates the channels.  That sounds problematic to me.

Your python script sounds like what my current tools do.  I have found this script which may be the same one you mention.

https://github.com/matafokka/ImageJ-Split-Bayer-Filter-Into-Channels

I haven't tried the script yet, but it might be what I need.  If it isn't, I will stick with my current tools.  I'm just trying to consolidate things if possible.
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

ghawkins
I did not read the thread, so apologies if this has been mentioned.  I would suggest using ASTAP for RGGB pixel extraction.  It's under 'batch processing' tools.  ASTAP also has a very fast plate solver.  Hope that helps.

Gary
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

Bill Tschumy
Gary,

I have been using ASTAP.  However, I was trying to consolidate apps and do everything with AIJ.
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

karenacollins
Administrator
Hi Bill,

Can you confirm the functionality you are looking for? We can consider implementing in AIJ. Are you wanting to extract the two green pixels in each RGGB Bayer group, average them together, and then produce an image from all of the averaged green pixel pairs which will result in being 1/2 x 1/2 the size of the original image? If you are looking for something different, please explain.

If we implement this feature, it would actually open three independent stacks of images (one R, one G, and one B) so that it would be more general purpose. However, you could simply delete or ignore the R and B stacks if you are not interested in running photometry on those.

Karen
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

Bill Tschumy
Sorry for the delay responding.  I have been out of town, focused on something else.

I asked the author of ASTAP what he does and he said it is exactly as you described it.  You average the two green pixels.  The resulting image is 1/2 x 1/2 the original size.
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

karenacollins
Administrator
Hi Bill,

In case you are interested in pursuing this in AIJ version 5, update your AIJ v5 installation to the latest daily build. Open the image stack you want to process. Then you will then see a new menu option Image_Display > Color > Photometric friendly debayer. Select this option. A small window will open allowing you to select the Bayer pattern. The default selection will be set to the value contained in the fits header Keyword "BAYERPAT", if it exists. After ensuring the correct pattern selection, click OK. Four new image stacks will be created. One labeled red which contains only the red pixels, and similarly a blue and green stack. The green stack contains the average of each pair of green sub-pixels. The fourth stack is labeled luminosity. Its pixels contain the sum of each set of 4 sub-pixels. Each image stack is 1/2 x 1/2 the original image stack size.

You can run photometry on any of the resulting stacks, or close the ones that you are not interested in.

Let us know if you give it a try and have any feedback.

Karen
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

Bill Tschumy
This post was updated on .
Karen,

Thanks so much for adding this. My initial tests suggests it is not working quite like ASTAP (not sure who is in error, or if the difference matters).  Using a single FITS file, I extracted the Green component in both programs and they do not give the same values at various locations in the image.  Not sure what to make of that.  The ASTAP converted file has greater values in general.

I saved the FITS headers from the generated files.  They differ in things like NAIXS1, NAXIS2 and XPIXSZ indicating you are not handling the extraction the same way.

ETA: Ooops, I was looking at the wrong AIJ header.  I have re-uploaded the correct one.  The NAXIS1 and NAXIS2 now agreed but there is a different in the binning and pixel size.  Again, I'm not sure if this matters in the end.  Yet the two file do nota green on pixel values at the same locations.

Header from ASTAP
ASTAP_header.txt

Hear from AIJ
AIJ_header.txt
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

Bill Tschumy
I've uploaded some files to illustrate the difference.  This directory contains the original RGGB file as well as the files generated by AIJ and ASTAP when extracting green.

What seems really strange is there is a hot pixel (I think) at x = 1097.5, y = 820.5.  It is present in the AIJ green extraction but not in the ASTAP one.  I'm not sure how to tell the pixel color using AIJ.

https://www.otherwise.com/Green_Extraction.zip
Reply | Threaded
Open this post in threaded view
|

Re: Extracting green channel from FITS

karenacollins
Administrator
Hi Bill,

We are just copying the fits header over, except the image size headers will get updated. I don't think the other small changes made by ASTAP are important for photometry.

My understanding of the Bayer RGGB is as shown below. I'm not an expert on color processing, so I've taken this info from the AAVSO DLSR guide.

 

With image flip and rotate set to none in AIJ, my interpretation is that would mean the following is your first "super-pixel" of RGGB.



The difference in the AIJ and ASTAP pixel results is that ASTAP is averaging what I have labelled as R and B instead of the two pixels I have labelled as G and G. Here I am assuming the header keyword with RGGB in your image header is correct.

Does your camera output in FITS format or are you using a program to generate the fits file? Does your camera manual specify what Bayer pattern it produces. I did a quick google search for "canon EOS 700d bayer pattern" and couldn't quickly spot an firm answer. The closest thing I could find is a PIXInsight user forum post that says the Canon EOS 5D MarkII "correct Bayer pattern is now 'GBRG'". That would match what ASTAP is doing with your images, which would mean it might be ignoring the fits header entry that says RGGB. If you override the default RGGB that AIJ is extracting from the fits header and instead choose GBRG instead, the green image will match the ASTAP green image. The hot pixel is probably occurring because AIJ and ASTAP were assuming different Bayer patterns, so were pulling different pixels from the original image.
1234