bwlabel (Bw) function return Wrong number of Connected Objects
조회 수: 4 (최근 30일)
이전 댓글 표시
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
채택된 답변
DGM
2022년 1월 1일
편집: DGM
2022년 1월 1일
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

