MATLAB: Using greythresh and im2bw

greythresh im2bw

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))

Best Answer

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)
Related Question