[英]Converting gray scale image to BW image
I want to convert a gray scale image (uint16) to a black and white image. 我想将灰度图像(uint16)转换为黑白图像。
[level, ] = graythresh(I);
I_bw = im2bw(I, level);
I don't understand how is possible that image I_bw result as follows: 我不明白图像I_bw的结果如何如下:
Note that level is equal to 0 after calling graythresh(I) . 请注意,在调用graythresh(I)之后, 级别等于0。
EDIT: I have uploaded the .mat file containing the original image. 编辑:我已经上传了包含原始图像的.mat文件。 file 文件
The reason is: level = 0 原因是:级别= 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]. 将I
转换为double
,并将其规格化为[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... 要了解原始代码中为什么级别= 0,需要进一步研究...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.