How to Separate Connected Objects in an Image

18 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Computer 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