bwlabel (Bw) function return Wrong number of Connected Objects
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Abdelrahman hussien
el 1 de En. de 2022
Comentada: Abdelrahman hussien
el 1 de En. de 2022
i use bwlabel(Bw) function to returns n, the number of connected objects found in Bw on the following image :

the n that will be returned should be 4 but actually 261 is return and i don`t know why
when i use the code below on the img simillar to the above but there is no rotation in any object it works fine
but in the case of the above image (there is a rotation in one or more object in the image) it not works correctlly
the code :
inputImg = input("one-rotated.jpg")
c = im2gray(inputImg);
figure , imshow(c) , title("gray Image");
z = 255-c;
q = imfill(z,'holes');
figure , imshow(q) , title("binary Image");
[l, n]=bwlabel(q);
0 comentarios
Respuesta aceptada
DGM
el 1 de En. de 2022
Editada: DGM
el 1 de En. de 2022
Try this:
inputImg = imread('money.png'); % the file has to be read
c = rgb2gray(inputImg); % im2gray() is from where?
imshow(c) , title("gray Image");
%z = 255-c; % this just inverts the image
bw = c<250;
bw = bwareaopen(bw,100); % clean up speckles that get counted as objects
bw = imfill(bw,'holes');
imshow(bw) , title("binary Image");
[l, n] = bwlabel(bw);
n
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

