Author Topic: VNG algorithm added to the Debayer module  (Read 11053 times)

Offline zvrastil

  • PixInsight Addict
  • ***
  • Posts: 179
    • Astrophotography
VNG algorithm added to the Debayer module
« on: 2011 October 16 12:41:07 »
Hello,

I implemented VNG (Variable Number of Gradients) demosaicing method to the Debayer module. Juan will publish it in form of update soon, as well as new version of BatchDebayerScript with support of this method.

I'd like to thank Sander Pool (Nocturnal) for sharing the souce code of his Debayer module with me, so I didn't have to start from the scratch.

I felt DLSR and OSC camera users (me included) are missing some more advanced demosaicing method in PixInsight. VNG performs quite good and is relatively easy to implement. I plan to add support for AHD as well, but it'll take more time.

My implementation is based on original paper Color Filter Array Recovery Using a Threshold-based Variable Number of Gradients by Ed Chang, Shiufun Cheung and Davis Pan. According to my experiments, VNG produces sharper stars and almost no color artifacts on star edges. Also, the noise of the debayered image has different characteristics - it is not so smoothed out and it is mainly 1-px wide salt-and-pepper noise which should be easier to remove than large scale noise. It is also more luminance than chrominance noise.

Attached, you'll find small comparison. First image shows original image, artifically debayered using PixelMath. Second image shows comparison between original image, image debayered with VNG and image debayered with Bilienar method. The testing image is small portion of photo I used in LocalHistogramEqualization module tutorial http://astrofoto.euweb.cz/pixinsight/LocalHistogramEqualization/comparison.html (courtesy of Vicent Peris (OAUV) and José Luis Lamadrid (CEFCA)).

I hope you'll find the new method useful.

Zbynek

P.S. I also extended Debayer module to support CFA color images directly (all methods). Up to now, it accepted only grayscale images.

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
Re: VNG algorithm added to the Debayer module
« Reply #1 on: 2011 October 16 13:31:14 »
this is excellent, thanks. i am looking forward to trying it.

Quote
P.S. I also extended Debayer module to support CFA color images directly (all methods). Up to now, it accepted only grayscale images.

!!! even more excellent.

is backward compatibility important in the BatchDebayer script? i imagine that you might be taking out the code to convert the CFA image to a monochrome image before calling the Debayer process. if that goes away then the script will lose compatibility with earlier versions of the BatchDebayer process. can the script test what version of BatchDebayer is actually installed?

i had been thinking about superpixel debayering recently and whether or not it's the right thing to do to average both G pixels. on a OIII image captured with an OSC, we are only interested in the G channel. if there is a stuck or hot pixel in one of the 2 green pixels in the bayer matrix that pixel will kind of destroy the other pixel's good value. you mentioned that you were using pixelmath to debayer while you were testing. can you share those expressions so i can experiment with this?

Offline zvrastil

  • PixInsight Addict
  • ***
  • Posts: 179
    • Astrophotography
Re: VNG algorithm added to the Debayer module
« Reply #2 on: 2011 October 16 23:46:12 »
is backward compatibility important in the BatchDebayer script? i imagine that you might be taking out the code to convert the CFA image to a monochrome image before calling the Debayer process. if that goes away then the script will lose compatibility with earlier versions of the BatchDebayer process. can the script test what version of BatchDebayer is actually installed?

Hello, I indeed removed the BatchDebayer script code to convert from color to grayscale. As I expect Juan would release both changes together, I assume there's no compatibility problem unless you accept only script update, but not a module update. New version of the script needs the new module anyway, for VNG method, so I saw no point in keeping it compatible with old module. Is there any?

i had been thinking about superpixel debayering recently and whether or not it's the right thing to do to average both G pixels. on a OIII image captured with an OSC, we are only interested in the G channel. if there is a stuck or hot pixel in one of the 2 green pixels in the bayer matrix that pixel will kind of destroy the other pixel's good value. you mentioned that you were using pixelmath to debayer while you were testing. can you share those expressions so i can experiment with this?

I used pixelmath expression to artifically convert color image to bayered, in order to be able to compare debayered result with original image and to see the difference. However, it should be easy to implement superpixel debayering with single PixelMath expression. Without possibility to verify it (I'm in the office), it could looks something like that (assuming RGGB and color CFA image):

Red channel:
Code: [Select]
$T[0, XPos()*2, YPos()*2]Green channel:
Code: [Select]
($T[1, XPos()*2+1, YPos()*2] + $T[1, XPos()*2, YPos()*2+1])/2Blue channel:
Code: [Select]
$T[2, XPos()*2+1, YPos()*2+1]
You need to switch on "Create new image" and enter width and height as half of the target CFA image.

best regards, Zbynek

Offline NKV

  • PTeam Member
  • PixInsight Guru
  • ****
  • Posts: 677
Re: VNG algorithm added to the Debayer module
« Reply #3 on: 2011 October 18 19:17:32 »
Zbynek, thanks.

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
Re: VNG algorithm added to the Debayer module
« Reply #4 on: 2011 November 06 16:46:08 »
on the superpixel stuff, just to follow up, i had to use the following pixelmath expressions:

Code: [Select]
R

Pixel($T,XPos()*2,YPos()*2,0)

G1

Pixel($T,XPos()*2+1,YPos()*2,1)

G2

Pixel($T,XPos()*2,YPos()*2+1,1)

B

Pixel($T,XPos()*2+1,YPos()*2+1,2)

attached is a process icon set containing the pixelmath setups, but if someone wants to use this they'll have to manually adjust the image width/height to match 1/2 the size of their camera's sensor.

ah phooey, there is a little bug in the process icons - the image is set to RGB but it should be set to greyscale.
« Last Edit: 2011 November 07 10:58:49 by pfile »