1

I will collect a dataset consisting of blackberries with and without defects. For this purpose, before I venture into this business I want to make sure that I can detect and extract blackberries from an image.

So I have this image

enter image description here

With the otsu method, morphology opening and closing I'm able to obtain a masked version of the image: enter image description here

Now I want to obtain a bounding box or extract every blackberry from the image. What tool should I use? A trained neural network? Are there other non neural network technique for this purupose?

Results:Thanks to Kevin M

enter image description here enter image description here

Girigio
  • 63
  • Search the documentation of your image processing library of choice for the term "connected component labelling". – cdalitz Jan 18 '22 at 14:44

1 Answers1

3

In Python, there's a function called regionprops under the sci-kit learn package. You first have to use skimage.measure.label on your image before inputting it into regionprops. The result after regionprops contains a list of regions and bounding box coordinates for each region in your image (after using .bbox).

Example (taken and edited from reginoprops documentation):

from skimage import data, util
from skimage.measure import label, regionprops
img = util.img_as_ubyte(data.coins()) > 110
label_img = label(img, connectivity=img.ndim)
props = regionprops(label_img)
props[0].bbox

>>> (0, 0, 102, 376)

regionprops also exists in MATLAB, though there's some slight differences. There are many different versions of the regionprops algorithm. Hope this helps!

Kevin M
  • 46