CImage Class


The CImage class encapsulates functionality for working with images. Included in this huge class are tools for working with image files, doing image math operations, changing image geometry, making measurements, and working with header data. Additional methods for combining and merging images are found in the CImCombine class.

Executing Scripts from Image Windows

The Execute Script menu command may be used to open and execute a script directly from a Mira Image Window. When a script is executed from the Execute Script command, it is automatically sent a CImageView object named ParentImageView and a CImage object namedParentImage . The ParentImageView is a CImageView object that provides access to the CImageView CImageSet member and others. The ParentImage is a CImage object attached to the current image in the Image Window. You can use these names directly in the script or you can rename them, like V = ParentImageView and I = ParentImage. You can also get the individual CImage objects from the window's Image Set using CImageView:GetImage. A sample script call to be called from an Image Window is provided named Execute from Image Window test.lua.

Usage

Construction

Object = new_image()

Object = attachlist_image()

Object = CImage:new()

Object = CImage:AttachFromList()

Destruction

Object:delete()

Table of Contents

Creation Functions

Non-class functions that create a new CImage object.

Construction and Destruction

Methods that create, copy, and delete CImage objects

Array Operations

Methods that work directly with image colums, rows, and regions, such as setting pixel values in a row or region.

Coordinates

Methods that work with pixel and world coordinates, distances, and measurements.

Filtering

Methods that perform filtering operations such as smoothing and enhancing.

General Methods

Methods that open files, create, save, and attach images.

Calibration

Methods that perform high level operations for calibrating CCD images.

Geometry

Methods that perform geometric operations such as scaling, rotating, expanding, etc.

Properties

Methods that retrieve image properties such as name, number of columns, exposure time, filter, image type, etc.

Keyword Operations

Methods that work with image headers and retrieve and set header keywords.

Math

Methods that perform mathematical operations between images and image values, including multiplication, exponentiation, etc.

Measurements

Methods that measure features in images including distance, angle, luminance, etc.

Math Operators

Syntax for using CImage objects as variables to simplify the syntax of complex operations, likeI2=I4+5.2 , or I2=I3*I4-17.14

Pixel Operations

Methods that work directly with image pixel values.

Creation - Non-class Functions

These functions are normally used to create and attach a new CImage object as an alternative to the class-based construction methods. A new CImage object is also returned by the GetImage method of the CImageView class.

attachlist_image

Creates a new CImage object attached to an image selected from an image window on the Mira desktop. This is equivalent to the AttachFromList class method.

new_image

Global function that creates a new CImage object.

Construction and Destruction - Class Methods

new

Creates a new instance of the CImage class. Various constructors are available.

delete

Deletes the instance of the CImage object and deletes its image from memory.

Copy

Copies the image to a new image.

AttachFromList

Creates a new CImage and attaches an image selected from the list of images in a CImageView.

General Methods

Close

Closes the image and deletes it from memory.

Create

Creates a new image of specified size and pixel type.

Display

Displays an image in a new image view window.

Open

Opens an image from a file.

Save

Saves the image to its file.

SaveAs

Saves the image to a new file name by prompting the user.

SaveTo

Saves the image to a new file name without prompting.

SaveUndo

Saves an "undo" copy of the image before making changes.

Undo

Restores the "undo" copy of the image.

Image Properties

Axes

Returns the number of image axes.

Bytes

Returns the number of bytes in the image pixel data.

Cols

Returns the number of image columns.

Darktime

Returns the dark integration time for the image.

Date

Returns the date the image was acquired, in days.

DateStr

Returns the date of image acquisition as a string.

DatatypeStr (obsolete)

Returns the image pixel type as a string. The name DatatypeStr is obsolete and should not be used going forward.

Datatype (obsolete)

Returns the image pixel type as a numeric index. The name Datatype is obsolete and should not be used going forward.

Exptime

Returns the image exposure time in seconds.

Filter

Returns the name of the filter used for image acquisition.

Gain

Returns the inverse gain in electrons per ADU.

ImageType

Returns the type of image, usually the value of the IMAGETYP keyword.

IsColor

Returns true if the image is a color pixel type.

IsInteger

Returns true if the image is an integer pixel type.

IsNumeric

Returns true if the image is a numeric pixel type.

IsReal

Returns true if the image is a real (floating point) pixel type.

Object

Returns the object description.

Path

Returns the image file path.

PixelBytes

Returns the number of bytes per pixel.

Pixels

Returns the number of pixels in the image.

PixelType

Returns the image pixel type as a numeric index.

PixelTypeStr

Returns the image pixel type as a string.

Rows

Returns the number of image rows.

Time

Returns the time of image acquisition as a number of seconds.

TimeStr

Returns the time of image acquisition as a string.

Measurements

Angle

Returns the angle formed by the line between 2 pixel coordinates.

AngleWcs

Returns the angle formed by the line between 2 world coordinates.

AreaUnits

Returns the world coordinate units for area measurements.

DistanceWcs

Returns the distance between 2 world coordinates.

Distance

Returns the distance between 2 pixel coordinates.

DistanceUnits

Returns the world coordinate units for distance measurements.

DistanceWcsStr

Returns as a string the distance between 2 world coordinates.

Coordinates

CoordUnits

Returns the coordinate units for an image axis.

GetAxisLabel

Returns the coordinate label for an image axis.

GetImageScale

Returns the image scale in world coordinates per pixel.

GetImageScaleXy

Returns the x and y axis image scale of the x and y axis in world coordinates per pixel.

PtInside

Returns true if a pixel coordinate is inside the image.

GetWcsType

Returns an integer code for the type of world coordinate system ("WCS") calibration used by the image.

WcsIsEq

Returns true if the image has an equatorial world coordinate calibration.

WcsToXy

Returns the pixel coordinates for world coordinates specified in decimal degrees.

WcsStrToXy

Returns the pixel coordinates for world coordinates specified as strings in units of "HH:MM:SS.SSS" and "-DD:MM:SS.SSS".

XyToWcs

Returns the world coordinate in degrees for pixel coordinates.

XyToWcsStr

Returns the world coordinate as strings in units of "HH:MM:SS.SSS" and "-DD:MM:SS.SSS" for pixel coordinates.

Pixel Operations

PixGE

Returns the coordinate of the first pixel with value >= target value.

PixGELE

Returns the coordinate of the first pixel with value >= value or <= value 2.

GetVal

Returns the pixel value at a pixel coordinate in the form of a number.

GetValStr

Returns the image value at a pixel coordinate in the form of a string.

SetVal

Sets the pixel value at a pixel coordinate.

SetRegionVal

Sets the pixels inside a rectangular region to a specified value andnoise.

SetRegionValExclude

Sets the pixels outside a rectangular region to a specified value and noise.

Array Operations

ColToTable

Returns the data from an image column as a 1-dimensional array.

RowToTable

Returns the data from an image row as a 1-dimensional array.

RectToTable

Returns the data from an image rectangle as a 1-dimensional array.

ToTable

Returns the image data as a 1-dimensional array.

TableToCol

Replaces an image column with values in a 1-d 1-dimensional array.

TableToRow

Replaces an image row with values in a 1-d 1-dimensional array.

TableToRect

Replaces a rectangular image region with values in a 2-d 1-dimensional array.

ExtractByte

Extracts an image consisting of a specific byte plane.

ExtractChan

Creates an image consisting of a color channel from an RGB image.

Math Operations

Abs

Computes the absolute value of the image pixels.

Add

Adds an operand image.

AddNoise

Adds Gaussian random noise to a region.

Addx

Adds a numeric value.

Blend

Blends the values of the image with an operand image.

Blendx

Blends the image values with a numeric value.

Byteswap

Swaps the byte order of the pixels.

Chs

Changes the sign of the image values.

Div

Divides by an operand image.

Divx

Divides by a numeric value.

Exp

Raises base e to powers specified by the image pixels.

ExtractByte

Extracts an image consisting of a specific byte plane.

Log

Computes the base-e logarithm of the pixel values.

Log10

Computes the base-10 logarithm of the pixel values.

Mod

Calculates the remainder of division by an operand image.

Modx

Computes the remainder of division by a numeric value.

Mul

Multiplies by an operand image.

Mulx

Multiplies by a numeric value.

PixGE

Returns the coordinate of the first pixel with value >= target value.

PixGELE

Returns the coordinate of the first pixel with value >= value or <= value 2.

PolyFitSub

Fits and subtracts a polynomial from the image.

PolyFitDiv

Fits and divides a polynomial into the image.

PolyFitImage

Fit a polynomial and evaluate it in the image.

Pow

Raises the image values to a power.

Powa

Raises a base value to powers specified by the image pixels.

Powab

Raises the image pixels to the power defined by the pixels of an operand image.

Recip

Computes the reciprocal of the pixel values.

ExtractChan

Creates an image consisting of a color channel from an RGB image.

ScaleLinVal

Applies a linear scaling to the pixel values.

ScalePolyVal

Applies a polynomial intensity correction.

SetPixelType

Changes the image Pixel Type.

Sqrt

Computes the square root of the image values.

Sub

Subtracts an operand image.

Subx

Subtracts a numeric value.

Xdiv

Divides the image values into a numeric value.

Xsub

Subtracts the image values from a numeric value.

Image Geometry

Affine

Applies an affine transformation of shift, scale, and rotation.

BlockAvg

Averages pixel values into m x n super-pixels.

BlockSum

Sums pixel values into m x n super-pixels.

Crop

Crops a smaller piece from the image.

DimEq

Tests whether 2 images have the same dimensions.

Expand

Expands the image into a larger canvas with specified border value and optional random noise.

Hflip

Flips the image horizontally.

Imbed

Imbed the image at a specific location in another image.

Reorient

Reorients the image in various quadrant transformations.

Rot180

Rotates the image 180 degrees.

Rot270

Rotates the image 270 degrees.

Rot90

Rotates the image 90 degrees.

Rotate

Rotates the image by an angle about its center.

RotatePt

Rotates the image by an angle about a point.

Scale

Scales the image by a magnification factor.

ScaleXy

Scales the image independently by magnification factors in the x and y directions.

Shift

Shifts the image horizontally and vertically.

Transpose

Flips the image about its main diagonal.

Vflip

Flips the image vertically.

Header Keyword Operations

KwdDelete

Deletes a keyword from the image header.

KwdExists

Returns true if the named keyword exists in the image header.

KwdGetDMS

Returns a properly formatted angle string for a keyword value given in degrees, minutes, and seconds. Use this for keywords not in the standard format using : as a field delimiter.

KwdGetDmsEx

Returns a DMS angle for a string keyword plus a boolean flag indicating that the keyword is in the image header.

KwdGetHMS

Returns a MHS time string for a string keyword value given in hours, minutes, and seconds. Use this for keywords not in the standard format using : as a field delimiter.

KwdGetHmsEx

Returns an HMS time for a string keyword plus a boolean flag indicating that the keyword is in the image header.

KwdGetNum

Returns a numeric value keyword.

KwdGetNumEx

Returns a numeric value keyword plus a boolean flag indicating that the keyword is in the image header.

KwdGetSect

Returns the 4 column and row limits stored in a region section keyword, like BIASSEC.

KwdGetSectEx

Returns the 4 column and row limits stored in a region section keyword (e.g., BIASSEC), plus a boolean flag indicating that the keyword is in the image header.

KwdGetStr

Returns a string value keyword.

KwdGetStrEx

Returns a string value keyword plus a boolean flag indicating that the keyword is in the image header.

KwdGetVal

Returns the value of a keyword in any format (string, number, etc.) as a string.

KwdGetValEx

Returns the value of a keyword in any format (string, number, etc.) as a string and also a boolean flag indicating that the keyword is in the header.

KwdSetBlank

Adds a blank keyword to the image header.

KwdSetBlankStr

Adds a blank keyword with string value to the image header.

KwdSetBool

Sets the value of a boolean T/F keyword or adds the keyword to the image header.

KwdSetComment

Adds a comment keyword to the image header.

KwdSetDate

Sets the value of a date keyword or adds the keyword to the image header.

KwdSetHistory

Adds a history keyword to the image header.

KwdSetNum

Sets the value of a numeric keyword or adds the keyword to the image header.

KwdSetSect

Sets a region section keyword (e.g., BIASSEC) using the 4 column and row limits passed as numbers

KwdSetStr

Sets the value of a string keyword or adds the keyword to the image header.

KwdSetTime

Sets the value of a time keyword or adds the keyword to the image header.

KwdSetVal

Sets the value of a keyword or adds the keyword to the image header.

Image Calibration

ApplyPixelMask

Applies a pixel mask to repair image blemishes.

CreatePixelMask

Creates a mask file for pixels above or below threshold values.

CreatePixelMaskHigh

Creates a mask file for pixels above a threshold value.

CreatePixelMaskLow

Creates a mask file for pixels below a threshold value.

SetMaskedValue

Sets pixel values at coordinates identified in a pixel mask.

SubBiasFrame

Subtract a bias frame from the image.

SubBiasVal

Subtract a bias value from the image.

SubBiasRef

Subtract a reference bias value stored in a header keyword.

SubBiasCol

Compute and apply a column bias correction.

SubBiasRow

Compute and apply a row bias correction.

SubDarkFrame

Subtracts a dark frame from the image.

SubDarkScaled

Subtracts a time-scaled dark frame from the image.

SubDarkOpt

Subtracts a statistically optimized dark frame from the image.

DivFlatFrame

Divides the image by a flat field frame.

DivFlatNorm

Divides the image by a flat field frame while normalizing the flat during the calculation.

Filtering Methods

FiltBinomial

Smooths the image using a binomial weight rectangular kernel.

FiltBlockAvg

Block averages pixels in m x n rectangle groups, similar to binning a digital detector.

FiltBlockSum

Block sums pixels in m x n rectangle groups, similar to binning a digital detector.

FiltClipHigh

Replaces pixel values above a threshold value.

FiltClipLow

Replaces pixel values below a threshold value.

FiltEllips

Smooths the image using an equal weight elliptical kernel.

FiltGaussian

Smooths the image using a Gaussian weight elliptical kernel.

FiltGradient

Applies a directional derivative gradient filter.

FiltKernel

Applies a user-defined kernel.

FiltLaplacian

Applies a Laplacian filter, usually for edge detection.

FiltLine

Applies a directional line selection kernel.

FiltMax

Applies a maximum value filter.

FiltMedian

Applies a median filter.

FiltMin

Applies a minimum value filter.

FiltPrewitt

Applies a Prewitt directional gradient mask.

FiltRank

Applies a rank value filter.

FiltRect

Smooths the image using an equal weight rectangular kernel.

FiltRotGrad

Applies a rotational gradient filter to enhance rotational or "spoked" features.

FiltSharpen

Sharpens the image using a crispening filter.

FiltSobel

Applies a Sobel edge filter.

FiltUnsharpMask

Sharpens the image using unsharp masking.

Related Topics

Script Classes, CImageSet class, CImageView , CImCombine class, Image Coordinate System, Subpixel Coordinate Definition


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