MATLAB Answers

using greythresh and im2bw

4 ビュー (過去 30 日間)
Douglas Brenner
Douglas Brenner 2016 年 11 月 6 日
編集済み: Image Analyst 2016 年 11 月 6 日
Figure 1 is great but BW is all black. Thoughts? Thanks
figure (1)
scaled = 255 * width/MAX;
imshow(uint8(scaled));
level = graythresh(scaled)
BW = im2bw(scaled,level);
figure(2);
imshow(uint8(BW))

  0 件のコメント

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2016 年 11 月 6 日
BW is logical, just 0 and 1. When you uint8() that, you are creating an image with just uint8(0) and uint8(1), which is too dark to be visible.
You are also doing the grayscale conversion on a double array that is out of range for valid double coefficients, and that is affecting your output.
figure (1)
scaled = 255 * width/MAX;
scaled8 = uint8(scaled);
imshow(scaled8);
level = graythresh(scaled8);
BW = im2bw(scaled8, level);
figure(2);
imshow(BW)

  3 件のコメント

Douglas Brenner
Douglas Brenner 2016 年 11 月 6 日
Figure 1 is now all white but figure 2 is right. However, this works.
figure (1)
scaled = 255 * width/MAX;
scaled8 = uint8(scaled);
imshow(uint8(scaled));
level = graythresh(scaled8)
BW = im2bw(scaled8,level);
figure(2);
imshow(BW)
Doesn't make sense to me.
Walter Roberson
Walter Roberson 2016 年 11 月 6 日
My code worked when I tested it on some test data:
width = ndgrid(0:500,0:50);
MAX = 500;
Image Analyst
Image Analyst 2016 年 11 月 6 日
Douglas, what is "width"? It's not a scalar is it? It's a 2 or 3-D image, right? Otherwise scaled will not be an image - it will just be a single number.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by