Problem with using imbinarize in matlab
7 views (last 30 days)
Show older comments
I want to convert this image to a binary image
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/235395/image.png)
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()
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/235396/image.png)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/235397/image.png)
Why is it so? Am i using imbinarize wrongly?
6 Comments
Walter Roberson
on 28 Aug 2019
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
Answers (0)
See Also
Categories
Find more on Gravitation, Cosmology & Astrophysics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!