MATLAB: Binary image shown in MATLAB GUI Window (can not seen, all black)

binary imagecdatagui

Hi, there. I have a problem in showing the binary image in MATLAB GUI Window by using 'cData'. Codes are shown as follows:
h_Img=handles.h_Img; %the image handle
Img_BW=handles.Img_BW; % the binary image

set(h_Img,'cData',Img_BW,'parent',handles.axes1);
This code lead to a black image. I cannot see the white part. But if I use this code
Img_BW=handles.Img_BW;% the binary image
figure;
imshow(Img_BW,[]);
It will show good image. Anyone can help me? Thank you.

Best Answer

My guess is that Img_BW is actually uint8, not logical so imshow(Img_BW) would show it with gray levels 0 and 1, which essentially appears black, whereas doing imshow(Img_BW, []) will map the 1 to 255 so now it will appear.
The other option is that the white parts are so small that when your image is shrunk down to fit on the screen, they're essentially subsampled away. However in this case you would not see them with the [] option. Show me what this shows in the command window when you put these lines of code before imshow():
whos Img_BW
min(Img_BW(:));
max(Img_BW(:));