# Which algorithm or tool to use for object detection and extraction?

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

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

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

• Search the documentation of your image processing library of choice for the term "connected component labelling". Jan 18 at 14:44

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!

• It worked. Thank you! Jan 17 at 18:57
• Your welcome! Since it helped, was wondering if you could select my answer as accepted? Helps in the future I believe on both our ends. Jan 17 at 19:04