CImage:DivFlatFrame
The DivFlatFrame method applies a flat field correction to an image. The result replaces the current image.
bResult = CImage:DivFlatFrame( Flat, pixel_type=nil ) |
Flat is a CImage containing the flat field frame.
The optional pixel_type specifies the output pixel type as a number or string.
On success, this method returns true.
On failure, false . is returned.
This method applies a flat field correction to the image and updates the image header with the appropriate history and other keywords. The pixel type of the image may be changed as part of the flat field correction, for example, to maximize the precision of the calculations. Mira automatically handles mixing different pixel types between the source image and the flat frame. The default value when you do not specify the pixel_type is nil, which causes Mira to process the image without changing its pixel_type.
Before using this method, the flat field frame should have been normalized to a reference value near 1.0 and converted to a real pixel type such as "float" or "double". Usually the normalization reference region is located at or near the center of the image.
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.
The following script loads an image and applies a flat field correction by dividing a flat frame. The output pixel type is changed to "float" to maintain precision of the correction process. In practice you might maintain the flat frame in memory inside a loop where you apply other calibrations in addition to the flat field method.
Assume the file to process is named sPath and the flat field frame is in the file named sFlatPath. We first create a CImage object and open the target file sPath into that object. We do the same for the flat frame in the file sFlatPath. Then we call the CImage class method DivFlatFrame() and save the processed image.
|
-- create a new CImage |
|
-- load the image from file sPath |
|
-- create a new CImage |
|
-- load the flat frame from sFlatName |
|
-- apply the flat field correction to image I |
|
-- save the image |
|
-- delete the image from memory |
|
-- delete the flat frame from memory |
CImage, SetMathErrVal , DivFlatNorm
Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics,
Inc. All Rights Reserved.