CImage:DivFlatNorm


The DivFlatNorm method applies a flat field correction to an image and normalizes the flat to unit reference signal in the process. The result replaces the current image.

Syntax

bSuccess = CImage:DivFlatNorm( Flat, CRect )

bSuccess = CImage:DivFlatNorm( Flat, CRect, datatype )

where

    Flat is a CImage containing the flat field frame.

    CRect is a CRect rectangle containing the percent bounds of the reference region

    datatype specifies the output data type and is a string.

    bSuccess is the returned success code. On success it is true, otherwise false.

  

This method normalizes the flat field frame during the correction process. The advantage of using this procedure is expedience: you do not need to create a stand-alone master flat field frame that has a real data type and is normalized to a signal level near 1.0. With this method, you specify a reference region and Mira applies a normalization correction during the processing but does not change the flat field frame. For precision work, it is usually best to create separate master flats and use the DivFlatFrame method instead.

Note that the normalization statistic is computed in reference region defined by the CRect argument. In this application, the rectangle position is defined as a percentage of the frame size and not in terms of absolute pixel coordinates. For example, if the reference region is to be the central 10% of columns and rows, then it extends from 45% to 55% of the column dimension and 45 to 55% of the row dimension of the image. In this case, the CRect would be specified using Set( 45, 55, 45, 55 ). Using a percentage protocol allows for a more versatile script that can be simple independent of the actual image size.

This method updates the image header with the history and other keywords appropriate for a flat field correction. A similar mathematical correction can be achieved using other methods including Div, but the same set of keywords would not be used.

The data type of the image may be changed as part of the correction, for example, to increase the precision of the flat field correction. Mira automatically handles mixing different data types between the source image and the flat frame.

Since the flat field correction is a division process, there is a possibility of a divide-by-zero error if the flat frame has a zero value pixel. Mira traps such errors and replaces the output pixel with the value specified using the global SetMathErrVal function. The best strategy is to clean the flat field frame of zero values before applying it to images.

Example

The following script loads an image and applies a flat field correction by dividing an un-normalized flat frame. The frame is normalized during the calculation using the central 10% of columns and rows. The output data type is changed to "float" to maintain the precision of the correction process.

I = CImage:new()

-- create a new CImage

I:Open(sPath)

-- load the image from file sPath

Flat = CImage:new()

-- create a new CImage

Flat:Open(sFlatName)

-- load the flat frame from sFlatName

R = NewRect( 45, 55, 45, 55 )

-- create a rectangle for central 10% of cols, rows

I:DivFlatNorm(Flat,R,"float")

-- apply the flat field correction to image I

I:Save()

 -- save the image

Related Topics

SetMathErrVal

DivFlatFrame

CImage class