I want to convert a gray scale image (uint16) to a black and white image.
[level, ] = graythresh(I);
I_bw = im2bw(I, level);
I don't understand how is possible that image I_bw result as follows:
Note that level is equal to 0 after calling graythresh(I) .
EDIT: I have uploaded the .mat file containing the original image. file
The reason is: level = 0
load Image.mat
I = z;
figure;imshow(I, []);
[level, ] = graythresh(I); %level = 0
I_bw = im2bw(I, level);
figure;imshow(I_bw);impixelinfo
The following code works:
Convert I
to double
, and normalize it to range [0, 1].
load Image.mat
I = z;
figure;imshow(I, []);
I = double(I)/double(max(I(:))); %Convert to double, and divide by maximum value - set range to [0, 1].
[level, ] = graythresh(I);
I_bw = im2bw(I, level);
figure;imshow(I_bw);impixelinfo
The following code works as well:
load Image.mat
I = z;
figure;imshow(I, []);
I = double(I)/double(max(I(:))); %Convert to double, and divide by maximum value - set range to [0, 1].
I = uint16(I*2^16-1); %Expand range to [0, 2^16-1] and convert to uint16.
[level, ] = graythresh(I);
I_bw = im2bw(I, level);
figure;imshow(I_bw);impixelinfo
Understanding why level = 0, in the original code requires farther investigation...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.