Problem with using imbinarize in matlab
显示 更早的评论
I want to convert this image to a binary image

I tried the following:
img = imread('Oval_H.png');
img = rgb2gray(img);
img = imbinarize(img);
imshow(img)
however, I'm getting the same picture shown after running imbinarize()

The image is now 250x250 logical as shown in the workspace area however, if i try using logical(not()) instead of imbinarize:
img = logical(not(img));
imshow(img)
I get:

Why is it so? Am i using imbinarize wrongly?
6 个评论
Walter Roberson
2019-8-27
This is exactly what I would expect.
Try using the imbinarize option 'ForegroundPolarity', 'dark'
Stewart Tan
2019-8-27
Walter Roberson
2019-8-27
I am not clear as to what you expect for output?
You have a dark object on a white background. imbinarize defaults to the same as other routines -- namely most routines assume that high values indicate the presence of an object and that low values (especially 0) indicate the absence of an object. imbinarize() is returning correctly under that assumption: the white around the edge is converted to true and the black in the center is convert to false.
KALYAN ACHARJYA
2019-8-27
编辑:KALYAN ACHARJYA
2019-8-27
@Stewart all are correct.
Stewart Tan
2019-8-28
Walter Roberson
2019-8-28
No, imbinarize assumes that black is background. Your image has a white object in the foreground that has a hole in it, as far as imbinarize is concerned. That changes if you use 'adaptive' and 'foregroundpolarity', 'dark'
logical(not(img)) is the same as not(img) which is the same as ~img which is the same as img==0
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!