CImage:new


The new method constructs a new instance of a CImage object. To create a new CImage object initialized to values in a lua array (table), use the newarray constructor.

Syntax

The default constructor creates an empty image with no dimensions and containing no data. Following this method, use Create, Open, or another method to place data into the image:

CImageNew = CImage:new()

CImageNew = CImage:new( CImage2 )

CImageNew = CImage:new( CMatrix )

CImageNew = CImage:new( nDim[], sDataType )

The following 2 constructors are deprecated in this version of MX Script and should not be used in future scripts. Instead of these methods, use the general form for nDim[] dimensions:

CImageNew = CImage:new( nCols, sDataType )

CImageNew = CImage:new( nCols, nRows, sDataType )

where

    CImage2 is an existing CImage object.

    CMatrix is a CMatrix object having 1 or 2 dimensions.

    nDim[] is an array containing the lengths of the image axes. The number of axis must be between 1 and the maximum number supported by Mira. For example, {1024,512,64} creates a 3-D image having 1024 columns, 512 rows, and 64 planes.

    sDataType is a string specifying the datatype of the image (e.g., "byte", "float", etc.).

    nCols is the number of columns in a 1-D or 2-D image (deprecated).

    nRows is the number of rows in a 2-D image (deprecated).

    CImageNew is the return value, a new CImage object.

  

Other contructors are provided to create a new image with a specified dimension and datatype. The new image can be filled in various ways such as by using the Create method, setting values using the Set method, or using Open on a file. Also see the "=" operator and Copy method as a way to create a new CImage from another CImage.

If you pass no arguments, a default CImage is created with 1 pixel of type "double". Whithout further extending the default CImage class, it can be useful if there are CImage methods you want to apply to a numeric value. Use CImage:Set to set the value, then perform the operations on it.

Examples

The following script creates a CImage object and loads an image into it. Then it creates a new CImage that is a duplicate of the first one. This makes 2 images loaded into memory:

A = CImage:new()

-- create a new CImage object

A:Open( sPath )

-- load an image from a file

B = CImage:new( A )

-- create a new CImage with a copy of A

Printf("A name: %s\n", A:Path(60))

-- print the name of image A

Printf("B name: %s\n", B:Path(60))

-- print the name of image B (is same as A)

The following script creates a 3 dimensional image of "float" data type and sets all pixels to value 1000.0:

A = CImage:new( {100,256,10}, "float" )

-- create a new 3-D CImage object of "float" type

I:Set( 1000 )

-- assign the value 1000 to all pixels

Printf("Axes = %d\n", I:Axes() )

-- prints "Axes = 3"

for n=1,I:Axes() do

-- for each image axis

  Printf("Len[%d]=%d ", I:Len(n) )

-- prints Len[1]=100 Len[2]=256 Len[3] =10

end

 

Related Topics

newarray

Axes

Copy

Dup

Create

delete

Math Operators

CImage class