# 2.6.4.12 m2img

Image: Conversion: Convert to Image

## Brief Information

Convert data matrix to grayscale image

## Command Line Usage

 

1. m2img bits:=16; 

2. m2img min:=0.5 max:=1; 

## Variables

Display
Name
Variable
Name
I/O
and
Type
Default
Value
Description
Input Matrix im

Input

MatrixObject

<active>

Specifies the numeric matrix object to be converted. By default, it is the active matrix object.

Output Image om

Output

MatrixObject

<new>

Specifies the output image. By default, a new image will be created and used for output. See the syntax here.

Bits/Pixel bits

Input

int

8

Specifies the bits per pixel for the output image. The default value is 8.

Black Value min

Input

double

<auto>

Specifies the value to be mapped to the black color. The default input is <auto>, which corresponds to the minimum cell value of the input matrix object.

White Value max

Input

double

<auto>

Specifies the value to be mapped to the white color. The default input is <auto>, which corresponds to the maximum cell value of the input matrix object.

## Description

This X-Function converts a numeric matrix object to a grayscale image with mapping. The values in the matrix are mapped to [0, ], where bpp is the specified bits per pixel. The matrix values that are not greater than the specified Black Value will be mapped to 0, which represent the black color; the matrix values that are not less than the specified White Value will be mapped to, which represent the white color; the other values are mapped to the output range linearly.

Note that the grayscale levels in the output image must be integers. Thus, rounding might be performed after mapping, causing some details to be dropped.

## Examples

In this example, we create a numeric matrix and use the m2img function to convert it to an 8-bit image:

1. Create a new matrix with the New Matrix button on the Standard toolbar.
2. When this matrix is active, select Matrix: Set Values from the menu.
3. In the Set Values dialog, enter "sin(i)+sin(j)" in the textbox and click the OK button. This fills the matrix with some numeric values.
4. Keep this matrix active. Select Image: Conversion: Convert to Image from the menu to open the dialog of m2img. Change the settings as the screenshot below and click OK to close the dialog.

A new image like the one below is created.

## Algorithm

Let x be a cell value of the input matrix and f(x) be the gray level of the image pixel that correspond to the cell. The linear mapping of x onto f(x) can be expressed as follows:

where bpp is the bits per pixel of the output image, BlackValue and WhiteValue are specified by the values of the variables, Black Value and Black Value, respectively.