Image: Conversion: Convert to Image
Convert data matrix to grayscale image
Command Line Usage
1. m2img bits:=16;
2. m2img min:=0.5 max:=1;
X-Function Execution Options
Please refer to the page for additional option switches when accessing the x-function from script
Specifies the numeric matrix object to be converted. By default, it is the active matrix object.
Specifies the output image. By default, a new image will be created and used for output.
See the syntax here.
Specifies the bits per pixel for the output image. The default value is 8.
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.
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.
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.
In this example, we create a numeric matrix and use the m2img function to convert it to an 8-bit image:
- Create a new matrix with the New Matrix button on the Standard toolbar.
- When this matrix is active, select Matrix: Set Values from the menu.
- 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.
- 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.
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.