How to Separate Connected Objects in an Image

18 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Matt J
Matt J il 31 Mag 2021
Modificato: Matt J il 31 Mag 2021

Più risposte (0)

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by