2.11.3 Exporting Matrices

Matrices can store image data as well as non-image data in Origin. In fact, all images in Origin are stored as matrices, whether or not they are rendered as a picture or displayed as pixel values. A matrix can be exported no matter which type of content it holds.

Exporting matrices with script is achieved with two X-Functions: expMatAsc for a non-image matrix and expImage for an image matrix.

Exporting a Non-Image Matrix

To export a matrix that holds non-image data to an ASCII file use the expMatAsc X-Function. Allowed export extenstions are *.dat (type:=0), *.txt (type:=1), *.csv (type:=2), and all file types (type:=3).

// Export a matrix (in Matrix Book 1, Matrix Sheet 1) to a file of 
// the *.csv type named TEST.CSV with xy-gridding turned on.

expMatASC im:=[MBook1]MSheet1 type:=2 path:="D:\TEST.CSV" xygrid:=1;

See the page Export Graphs/Data/Videos, for more data export examples.

Exporting an Image Matrix

Matrix windows in Origin can contain multiple sheets, and each sheet can contain multiple matrix objects. A matrix object can contain an image as RGB values (default, reported as three numbers in a single matrix cell, each matrix cell corresponds to a pixel), or as gray-scale data (a single gray-scale number in each matrix cell).

For example, a user could import an image into a matrix object (as RGB values) and later convert it to gray-scale data (i.e., the gray-scale pixel values) using the Image menu. Whether the matrix object contains RGB or gray-scale data, the contents of the matrix can be exported as an image file to disk, using the expImage X-Function. For example, the following script command exports the first matrix object in Sheet 1 of matrixbook MBook 1:

// Export the image matrix as a *.tif image:
expImage im:=[MBook1]1!1 type:=tif fname:="c:\flower"

When exporting to a raster-type image format (includes JPEG, GIF, PNG, TIF), one may want to specify the bit-depth as well as the resolution (in dots-per-inch, DPI). This is achieved with the expImage options tree, tr. The X-Function call specifying these options might look like this:

expImage im:=[MBook1]MSheet1! type:=png fname:="D:\TEST.PNG"
tr.PNG.bitsperpixel:="24-bit Color"

All nodes of the tree tr, are described in the online or product (CHM) help.