How to use blob analysis and morphological operations to improve detection of occluded fruit?

I am trying to detect fruits using machine vision and I am now removing the noise and keep only the (occluded) fruit. So far I used on the resulting binary images morphologic operations to remove the noise and keep the fruit. Using the disk element only the clear rounded fruits are detected and the rest is removed. Even if a part of the pixels is a disk only that part is kept and the other white pixels are removed (see picture below). However, I want that this part is also kept, as it is part of the fruit.
For example using a disk element with a radius of 4 pixels (3rd subplot) or with a radius of 7 pixels (4rd subplot) results in:
diskElem = strel('disk',4);
BW_clean = imopen(BW_Image, diskElem);
How is it possible to keep after applying the disk element with a radius of 4 pixels the complete occluded fruit (so not as in the 4rd subplot) and remove the other noise? I have added these subplots and another example as attachement (.fig file) if you want to try. I have tried multiple morphologic operations, but didn't succeed. Or does anybody know a better way of noise removal of the binary image?
Moreover, for these occluded fruits I want to recognize them (first goal) and detect the centre/approximate the shape if possible (second goal).
Lastly, how is it possible to show an image after applying blobanalysis as I did below? And whats the difference between doing morphologic operations and blobanalysis?
Hblob = vision.BlobAnalysis('MinimumBlobArea', 315, ...
'MaximumBlobArea', 10000);
[objArea,centroid,bbox] = step(Hblob, BW_clean);

1 Comment

yes,sir,may be consider regionprops to get Circularity and Solidity property to analysis

Sign in to comment.

Answers (1)

I don't know how you're doing your segmentation but it looks like you might be making the typical beginner mistake of using edge detection. That's not good -- there are edges all over the place.
Since you know your fruit have a different, and very specific color, you'd be best off using color segmentation by using the Color Thresholder on the Apps tab of the tool ribbon. That way you can be sure you you get orange and only orange blobs. You can do further clean up by using bwareaopen() or bwareafilt() to extract blobs only in a certain size range.
Attach your original full size image if you still need more help.

3 Comments

I didn't use edge detection, but indeed color segmentation. However, I only tuned the hue value and not the saturation value. After tuning the saturation value, most of the edges are removed. However, the bounds should be relaxed, as it should work for not only one image, but for a lot of images from the same fruit. I didn't tune the value parameter as the effect is minimal.
After using bwareopen() and bwarefilt(), I get the following results:
I don't know whether these results are optimal or you can do it better.
Not sure what you're going to do with that binary image. Are you just going to get the area to know how much fruit is on the tree? If so, then that is probably good enough. Why? Well consider that if you just swing around the tree to look at the same oranges from a slightly different angle, then you'll get a vastly different result. So obviously accuracy is not really needed here. But if you were doing something like driving past your orchard snapping pictures adjacent to each other in the scene, you would have some rough idea of how many oranges you now have in your orchard and that might give you some idea of the optimal time to go in and harvest the trees.
Hello good, what is your email? I would like to ask you about a particular exercise that I have some doubts. Greetings and excuse me

Sign in to comment.

Categories

Asked:

S.
on 16 Dec 2021

Commented:

on 14 May 2022

Community Treasure Hunt

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

Start Hunting!