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

bResult = CImage:DivFlatNorm( Flat, CRect, pixel_type=nil )

bullet.gif    Flat is a CImage containing the flat field frame.

bullet.gif    CRect is a rectangle containing the percent bounds of the reference region (see Remarks)

bullet.gif    The optional pixel_type specifies the output pixel type as a number or string.

bullet.gif    On success, this method returns true.

bullet.gif    On failure, false. is returned.

Remarks

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 pixel 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 pixel 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 pixel 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 pixel type is changed to "float" to maintain the precision of the correction process.

I = new_image()

-- create a new CImage

I:Open(sPath)

-- load the image from file sPath

Flat = new_image()

-- create a new CImage

Flat:Open(sFlatName)

-- load the flat frame from sFlatName

R = new_rect( 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

I:delete()

 -- delete the image from memory

Flat:delete()

 -- delete the flat frame from memory

R:delete()

-- delete the CRect from memory

Related Topics

CImage class, SetMathErrVal, DivFlatFrame


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.