I want to meaning of this code, I do not understand

2 views (last 30 days)
IA = im2uint16(mat2gray(A, [Tmin Tmax]));
imwrite(IA,'A.tiff','tiff');
  12 Comments
Hiro Yoshino
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)
A = 10×10
0.3652 0.4990 0.3570 0.3250 0.3703 0.5165 0.8567 0.2700 0.1969 0.8427 0.8319 0.2490 0.1477 0.6183 0.9103 0.1187 0.4691 0.8416 0.4145 0.7285 0.9673 0.6516 0.9929 0.3241 0.5617 0.0003 0.2381 0.2597 0.4023 0.5245 0.7304 0.0957 0.9250 0.8422 0.8263 0.2492 0.1015 0.5149 0.2128 0.4669 0.7243 0.7869 0.9687 0.0662 0.1619 0.7467 0.5655 0.8295 0.7168 0.1069 0.3287 0.5197 0.3206 0.4551 0.9049 0.9328 0.7855 0.6742 0.5931 0.6717 0.1940 0.6067 0.9649 0.5605 0.4305 0.7505 0.0101 0.1553 0.7246 0.6485 0.5959 0.5432 0.2770 0.7318 0.3027 0.7476 0.0562 0.5653 0.3915 0.3219 0.7238 0.9491 0.8121 0.3357 0.2622 0.9480 0.2159 0.5600 0.5243 0.5905 0.5313 0.6811 0.4309 0.0528 0.2952 0.7032 0.2883 0.7997 0.1039 0.9802
I = mat2gray(A,[0 1])
I = 10×10
0.3652 0.4990 0.3570 0.3250 0.3703 0.5165 0.8567 0.2700 0.1969 0.8427 0.8319 0.2490 0.1477 0.6183 0.9103 0.1187 0.4691 0.8416 0.4145 0.7285 0.9673 0.6516 0.9929 0.3241 0.5617 0.0003 0.2381 0.2597 0.4023 0.5245 0.7304 0.0957 0.9250 0.8422 0.8263 0.2492 0.1015 0.5149 0.2128 0.4669 0.7243 0.7869 0.9687 0.0662 0.1619 0.7467 0.5655 0.8295 0.7168 0.1069 0.3287 0.5197 0.3206 0.4551 0.9049 0.9328 0.7855 0.6742 0.5931 0.6717 0.1940 0.6067 0.9649 0.5605 0.4305 0.7505 0.0101 0.1553 0.7246 0.6485 0.5959 0.5432 0.2770 0.7318 0.3027 0.7476 0.0562 0.5653 0.3915 0.3219 0.7238 0.9491 0.8121 0.3357 0.2622 0.9480 0.2159 0.5600 0.5243 0.5905 0.5313 0.6811 0.4309 0.0528 0.2952 0.7032 0.2883 0.7997 0.1039 0.9802
If you show this A as an image, it goes ....
imshow(I)
Muhammad Waheed AZAM
Muhammad Waheed AZAM on 15 Jun 2022
@hero IA = im2uint16(mat2gray(A, [Tmin Tmax])); in that code now I want to know how im2uint16 implement

Sign in to comment.

Answers (2)

Muhammad Waheed AZAM
Muhammad Waheed AZAM on 15 Jun 2022
@KSSV @Konrad @Hiro I read the document but did not understand please help

Siraj
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!

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!