필터 지우기
필터 지우기

"vislabels" detecting background as an object

조회 수: 2 (최근 30일)
Abdul Hannan Qureshi
Abdul Hannan Qureshi 2022년 4월 18일
댓글: Image Analyst 2022년 4월 18일
I want to detect number of lines in the image below:
However, I am getting following output:
Why it is picking background as object count. Can someone advise me what I am missing?.
"bwconncomp" outcome is shown below.
cc =
struct with fields:
Connectivity: 8
ImageSize: [5023 5036]
NumObjects: 9
PixelIdxList: {1×9 cell}
I am using following simple code:
a = imread ('Image.png');
b = rgb2gray(a);
d=im2bw(b);
vislabels(d);
cc=bwconncomp(d)

채택된 답변

Image Analyst
Image Analyst 2022년 4월 18일
You need to call imclearborder since your image has a white frame surrounding the black background.
rgbImage = imread ('Image.png');
grayImage = rgbImage(:,:,1); % Take red channel (faster than rgb2gray).
binaryImage = grayImage > 128;
% Get rid of white frame around the lines.
binaryImage = imclearborder(binaryImage);
imshow(binaryImage)
% Count lines
[labeledImage, numLines] = bwlabel(binaryImage);
caption = sprintf('Found %d lines.', numLines);
title(caption, 'FontSize',16)
  댓글 수: 2
Abdul Hannan Qureshi
Abdul Hannan Qureshi 2022년 4월 18일
Thank you, issue resolved.
Image Analyst
Image Analyst 2022년 4월 18일
You're welcome. Can you then click the "Accept this answer" link to let everyone know it's resolved? Thanks in advance. 🙂

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by