将灰度图像转换为BW图像

时间:2016-07-20 13:22:25

标签: image matlab

我想将灰度图像(uint16)转换为黑白图像。

[level, ] = graythresh(I);
I_bw      = im2bw(I, level);

图片 I 下方: enter image description here

我不明白图像 I_bw 的结果如何可能如下: enter image description here

请注意,在调用 graythresh(I) level 等于0。

编辑:我上传了包含原始图片的.mat文件。 file

1 个答案:

答案 0 :(得分:1)

原因是: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

以下代码有效:
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

结果:
enter image description here

以下代码也适用:

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

理解为什么level = 0,在原始代码中需要进一步调查......