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 commentaires

Walter Roberson
Walter Roberson le 27 Août 2019
This is exactly what I would expect.
Try using the imbinarize option 'ForegroundPolarity', 'dark'
Stewart Tan
Stewart Tan le 27 Août 2019
@Walter Roberson unfortunately it's still the same as before.
Walter Roberson
Walter Roberson le 27 Août 2019
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
KALYAN ACHARJYA le 27 Août 2019
Modifié(e) : KALYAN ACHARJYA le 27 Août 2019
@Stewart all are correct.
Stewart Tan
Stewart Tan le 28 Août 2019
@Walter Roberson shouldn't the oval at the center be white and the background black? I expect the output to be the third picture, since it's the output produced by one author, where he used logical(not(img)) instead of imbinarize. Or is there no difference between both methods at all?
Walter Roberson
Walter Roberson le 28 Août 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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange

Question posée :

le 27 Août 2019

Commenté :

le 28 Août 2019

Community Treasure Hunt

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

Start Hunting!

Translated by