I want to meaning of this code, I do not understand
1 view (last 30 days)
Show older comments
IA = im2uint16(mat2gray(A, [Tmin Tmax]));
imwrite(IA,'A.tiff','tiff');
12 Comments
Hiro Yoshino
on 15 Jun 2022
I = mat2gray(A,[amin amax]) converts the matrix A to a grayscale image I that contains values in the range 0 (black) to 1 (white). amin and amax are the values in A that correspond to 0 and 1 in I. Values less than amin are clipped to 0, and values greater than amax are clipped to 1.
Note that this is a copy of the documentation.
matrix A is something like:
A = rand(10)
I = mat2gray(A,[0 1])
If you show this A as an image, it goes ....
imshow(I)
Answers (2)
Siraj
on 15 Jun 2022
Hi,
It is my understanding that you want to understand what this code is doing.
As per my understanding, in first line of code the matrix ‘A’ is converted to a grayscale image that contains values in the range 0 (black) to 1 (white). ‘Tmin’ and ‘Tmax ’ are the values in A that correspond to 0 and 1 in image matrix. Values less than ‘Tmin’ are clipped to 0, and values greater than ‘Tmax’ are clipped to 1.
After this ‘im2uint16’ will convert the image matrix to a 16-bit unsigned integer, rescaling and offsetting the image matrix.
The second line of the code will write the matrix ‘IA’ to a graphics file ‘A.tiff’, the third argument to the function ‘imwrite’ that is ‘tiff’ makes sure that the format of the file is .tiff no matter what extension you give in the file name.
Please refer to mat2gray, im2uint16 and imwrite documentation for more information about these functions.
Hope it helps!
0 Comments
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!