Bi-linear Debayer MaximDL Plugin

The built in debayer tool of MaximDL (ConvertRGB) uses a derivation of the Nearest Neighbor Replication algorithm. This is fast, but fairly simplistic in its results, producing artifacts around the edges of bright stars.

The algorithm is described below:

Nearest Neighbor Replication

• In this interpolation method, each interpolated output pixel is assigned the value of the nearest pixel in the input image. The nearest neighbor can be any one of the upper, lower, left and right pixels.
• An example is illustrated below in Figure 2 for a 3x3 block in green plane. Here we assume the left neighboring pixel value is used to fill the missing ones. There are several well known alternative algorithms and the plugin below implements the bi-linear interpolation algorithm, also described below:

Bilinear Interpolation • Interpolation of green pixels : the average of the upper, lower, left and right pixel values is assigned as the G value of the interpolated pixel. For example : G8 = (G3+G7+G9+G13) / 4
• Interpolation of red/blue pixels :
• Interpolation of a red/blue pixel at a green position : the average of two adjacent pixel values in corresponding color is assigned to the interpolated pixel. For example : B7 = (B6+B8) / 2 ; R7 = (R2+R12) / 2
• Interpolation of a red/blue pixel at a blue/red position : the average of four adjacent diagonal pixel values is assigned to the interpolated pixel. For example : R8 = (R2+R4+R12+R14) / 4 ; B12 = (B6+B8+B16+B18) / 4

My plugin implementation of the bilinear interpolation debayer algorithm is available for download from the link below.

The new COM interface support allows one to programmatically set the parameters normally set through the dialogue box during interactive execution.

Four methods are exposed:

plugin.SetOffset X, Y – allows one to specify the axis offset values to either 1 or 0. Defaults to zero.

plugin.SetCompensate bool – enables or disables compensation for typical CCD response characteristics. Defaults to false.

plugin.SetAutoBalance bool – enables or disables automatic background colour balance. Defaults to false.

plugin.Debayer doc – Initiates the plugin execution on the specified MaximDL document.

An example script to allow drag-and-drop processing of files is shown below.

Simply paste the text into a file with a .vbs name extension (e.g. “debayer.vbs”) then drag FITS files or a directory containing files from windows explorer onto the icon to have them processed by the plugin.

There is a limit of 255 characters on the list of file/dir names you drag onto the icon.

------------------------------------------------------------------

Dim plugin

Dim doc

Set plugin = CreateObject("Bilinear_debayer.PlugIn")

Set fso = CreateObject("Scripting.FileSystemObject")

Set doc = CreateObject( "MaxIm.Document" )

If wscript.Arguments.Count = 0 Then

MsgBox "No argument filenames were provided"

wscript.Quit

End If

If wscript.Arguments.Count = 1 Then

'Assume only one argument means it is a folder

If fso.FolderExists(wscript.Arguments(0)) Then

Set folder = fso.GetFolder(wscript.Arguments(0))

Set fc = folder.Files

For Each f1 in fc

ProcessIt(f1.path)

Next

Else

'Folder does not exist, so process argument as a file

ProcessIt(wscript.Arguments(0))

End If

Else

'Multiple arguments = files

For I = 1 To wscript.Arguments.Count

ProcessIt(wscript.Arguments( I - 1 ))

Next

End If

Function ProcessIt(file)

doc.OpenFile file

plugin.SetOffset 0,1

plugin.SetCompensate true

plugin.SetAutoBalance true

plugin.Debayer doc

doc.SaveFile file, 3, false, 1, 1

End Function

------------------------------------------------------------------

Release notes:

V1.0 - Initial release - includes optional CCD spectral response compensation.

V1.1 – Provides COM interface for scripted execution support.

V1.2 – Adds optional automatic background colour balance processing.

Bilinear debayer v1.2

If you use this plugin, please give me feedback via the MaximDL yahoo group, or by email to winfij_AT_gmail_DOT_com

Regards,

John

(Algorithm descriptions courtesy of Ting Chen)