簡體   English   中英

將灰度圖像轉換為黑白圖像

[英]Converting gray scale image to BW image

我想將灰度圖像(uint16)轉換為黑白圖像。

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

在圖片下方 在此處輸入圖片說明

我不明白圖像I_bw的結果如何如下: 在此處輸入圖片說明

請注意,在調用graythresh(I)之后, 級別等於0。

編輯:我已經上傳了包含原始圖像的.mat文件。 文件

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

結果:
在此處輸入圖片說明

以下代碼也可以正常工作:

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

要了解原始代碼中為什么級別= 0,需要進一步研究...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM