This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Convert matrix to grayscale image


I = mat2gray(A, [amin amax])
I = mat2gray(A)
gpuarrayI = mat2gray(gpuarrayA,___)


I = mat2gray(A, [amin amax]) converts the matrix A to the intensity image I. The returned matrix I contains values in the range 0.0 (black) to 1.0 (full intensity or white). amin and amax are the values in A that correspond to 0.0 and 1.0 in I. Values less than amin become 0.0, and values greater than amax become 1.0.

I = mat2gray(A) sets the values of amin and amax to the minimum and maximum values in A.

gpuarrayI = mat2gray(gpuarrayA,___) performs the operation on a GPU. This syntax requires the Parallel Computing Toolbox™.

Class Support

The input array A can be logical or numeric. The output image I is double.

The input gpuArray gpuarrayA can be logical or numeric. The output gpuArray image gpuarrayI is double.


collapse all

Read an image and, for this example, turn it into a numeric matrix.

I = imread('rice.png');
J = filter2(fspecial('sobel'),I);
Convert the matrix into an image.
K = mat2gray(J);
Display the original image and the result of the conversion.
imshow(I), figure, imshow(K)

Introduced before R2006a

Was this topic helpful?