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

4 views (last 30 days)
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.

Accepted Answer

Image Analyst
Image Analyst on 12 Jun 2017
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(:));
  8 Comments
Image Analyst
Image Analyst on 12 Jun 2017
1000 is not a problem (anymore). With old versions of MATLAB, all those images would pile on top of one another and you'd have to call cla between calles to imshow(), but now it seems like only one image is there. If you need to do several per second, then you might use cData, but if it's just like displaying a new image every second or slower, then that's fine and you won't notice any speed difference.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 10 Jun 2017
colormap(gray(2))
  2 Comments
Penny
Penny on 12 Jun 2017
Hi, thanks Walter Roberson. It doesn't work. I put the code like this:
Colormap(h_Img,gray(2));
set(h_Img,'cData',Img_BW,'parent',handles.axes1);
But it still shows nothing.
Penny
Penny on 12 Jun 2017
Oh,sorry, my updated code is:
Colormap(handles.axes1,gray(2));
set(h_Img,'cData',Img_BW,'parent',handles.axes1);
But it still shows nothing.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!