Author Topic: PixInsight Method to "Extract Bayer Plane"  (Read 6496 times)

Offline jdupton

  • Newcomer
  • Posts: 19
PixInsight Method to "Extract Bayer Plane"
« on: 2012 September 29 18:03:58 »
Hello,

   Is there a straightforward way to "split" a RAW CFA image into separate "raw" R, G, and B images?  I am guessing that it can be done using PixelMath but I'm not yet adept at using that PixInsight feature.  It's also possible I have missed an existing PI Tool that does this directly.

   What I want to do is create three (pseudo)raw images from a single RAW CFA image.  The result would be one image containing only the raw Red pixels from the original CFA, one containing only Green (an average of the two green pixels from each super-pixel), and a final image containing only Blue pixels from the starting CFA.  Each of the three resulting images would be only half the dimensions of the original.

   This operation is equivalent to what is known as "Extract Bayer Plane" in MaxIm DL.  I found a number of related posts regarding processing CFA flats in the forum here but nothing that addressed making a separate image from each CFA color channel.


John

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: PixInsight Method to "Extract Bayer Plane"
« Reply #1 on: 2012 September 30 01:04:37 »
Maybe the ChannelExtraction process?
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline jdupton

  • Newcomer
  • Posts: 19
Re: PixInsight Method to "Extract Bayer Plane"
« Reply #2 on: 2012 September 30 06:52:38 »
Georg,

   Thanks for the suggestion but I had already tried various methods of using the ChannelExtraction process.

   The ChannelExtraction process needs an RGB image to work with.  Otherwise you get an error.  You can DeBayer the original raw CFA and apply the ChannelExtraction tool to the result but you end up something different than you would have gotten by simply splitting out the CFA channels.  (The colors will have been munged by the DeBayer interpolation process.)

   I had also already tried various methods using the in-place Gray to RGB color-space conversion tool but again, you don't get a real separation of the original CFA plans as I desire.

   Any other ideas anyone can suggest?


John

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Re: PixInsight Method to "Extract Bayer Plane"
« Reply #3 on: 2012 September 30 07:11:24 »
Ah, you want to do it before debayer?
Maybe using the FormatExplorer and setting the DSLR_RAW preferences to "Create RAW Bayer image" or "Create RAW Bayer CFA image" does what you want.

Georg
 
« Last Edit: 2012 September 30 07:39:47 by georg.viehoever »
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 627
    • Astronomy Pages G.W.
Re: PixInsight Method to "Extract Bayer Plane"
« Reply #4 on: 2012 September 30 07:33:05 »
Hi John!
It think it could be possible to get the extra planes without Standard Debayering.
However, you will never get better data than with the debayer und channel extract methode, because
the algorythm for the debayering is sophisticated.

What would i do if i could see a win.
I would take an image of plain green paper, one seperately from a plain red paper and one from a plain
blue paper.

You load these 3 images into PI as B/W-raws and you will see in the red B/W at the red position a bright pixel
and on the other positions a more or less black pixel.
This is valid also for the BLUE B/W picture it will have one bright pixel per 4-matrix and 3 dark pixels.
On the green B/W image there will be 2 bright and 2 dark pixel in each matrix of 4.

There are different tools to put the bright pixels in each image to the value 1 and the darker ones to the value 0.
(RangeSelection, PixelMath etc.)  -  iif($T >0.5,1,0)

This gets you for each color a separate mask where for example on the blue mask there are only the blue pixel
POSITIONS on 1 and the others on Zero in each matrix of four.

So you will end up with 3 images with the same size than the original. one for red, one for blue and one for green.
I call them Masks.

Finally  with Pixelmath you take the RAW astro image Image  $T with an iif expression
you ask  simplified iif(RedMask = 1, put the sáme pixel of thé raw image to the 3 neighbouring pixels in the Raw Image $T)
(xpos+1,ypos,
xpos,ypos,
xpos,ypos+1) .

This will fill the 3 neighbouring pixel of the red with the same red value.
Create with the result a new image as RED

Load the unmodified RAW again and do the same using the BLUE mask.
Here the neighbouring pixels in matrix of four are in the vice versa position.

For green you have to fíll, after you have saved before the blue raw image,
only 2 pixel (averaged) in the matrix. Using the the Green Mask as logic.

You should receive gray images the same size as the original RAW for each color channel.

Now you can do your linear processing of the channels seperately, than combine the channels with RGB channelcombination
after doing a Linear Fit  to each channel. Would not recommend any stretching of these RAWs.

However, your image will be always less sharp because you more or less trashed one important
green pixel, and you have Super Pixels of 4 for each channel seperately. Means less resolution generally.

Hope this idea helps. Would be interested what you really want to achieve?

Aloha
Gerald

« Last Edit: 2012 September 30 07:38:43 by oldwexi »

Offline martin_magnan

  • Member
  • *
  • Posts: 68
    • Messager Céleste
Re: PixInsight Method to "Extract Bayer Plane"
« Reply #5 on: 2012 September 30 07:56:00 »
Hi

you could use de debayer command with the superpixel option. It combine the 4 RGGB pixels into one RGB pixel and then use the extract layer command.

You will end up with 3 images R, G, B with no interpolation and half the size (a quarter the area) of the original image.

MArtin
TEC140 / AP1200GTO / QSI583wsg - Astrodon LRGB 2 filters / Lodestar X2 Guider / Robofocus
http://www.messagerceleste.com

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 627
    • Astronomy Pages G.W.
Re: PixInsight Method to "Extract Bayer Plane"
« Reply #6 on: 2012 September 30 12:36:35 »
Hi Martin!
Thats a short and perfect solution!

Aloha
Gerald

Offline bitli

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 513
Re: PixInsight Method to "Extract Bayer Plane"
« Reply #7 on: 2012 September 30 12:51:20 »
Alternatively the script attached should extract 4 images from the raw file (2 r, g, b). It was an old script, it seems to work but without warranty.
-- bitli

Offline jdupton

  • Newcomer
  • Posts: 19
Re: PixInsight Method to "Extract Bayer Plane"
« Reply #8 on: 2012 September 30 20:00:54 »
Martin,

   That is such a simple and elegant method.  Thanks!  It results in just what I wanted -- an unchanged extraction of each of the original Bayer planes to a separate image.  (It also results in averaging the two green elements of each super-pixel just as I envisioned.)

   Thanks to bitli also for the script.  This will help me delve more deeply into the more powerful aspects of PixInsight.


John

Offline martin_magnan

  • Member
  • *
  • Posts: 68
    • Messager Céleste
Re: PixInsight Method to "Extract Bayer Plane"
« Reply #9 on: 2012 October 01 10:33:09 »
You are welcome John. Glad to help.

Martin
TEC140 / AP1200GTO / QSI583wsg - Astrodon LRGB 2 filters / Lodestar X2 Guider / Robofocus
http://www.messagerceleste.com