How to Separate Connected Objects in an Image

18 ビュー (過去 30 日間)
Hannah Faustyn
Hannah Faustyn 2021 年 5 月 31 日
編集済み: Matt J 2021 年 5 月 31 日
I am trying to count the number of objects in a picture using bwconncomp, but the results are incorrect because some of the regions blend together. I used the image from https://www.publicdomainpictures.net/pictures/290000/velka/field-of-flowers-1553807209QZG.jpg to illustrate my problem.
This is the original image, and I'd like to write code that counts the total number of flowers in the picture.
I used the following code:
image = imread(fileName);
%Convert to grayscale
imageGray = rgb2gray(image);
%Remove noise
SE = strel('disk', 5);
afterOpening = imopen(image, SE);
%Convert to binary image and filter out small objects
imageBin = imbinarize(afterOpening);
imageBin = bwareaOpen(imageBin, 300);
%Count the number of objects
CC = bwconncomp(imageBin);
numObjects = CC.NumObjects;
I am pretty sure that bwconncomp will count the three flowers highlighted above as one region, thereby skewing the count in numObjects. Is there a way that I can get Matlab to recognize the highlighted box as having 3 objects instead of 1?

採用された回答

Matt J
Matt J 2021 年 5 月 31 日
編集済み: Matt J 2021 年 5 月 31 日

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by