Detecting circular shaped fruit in 2D images using circular Hough transform or alternative algorithm
Show older comments
I am trying to detect circular fruits using the circular Hough transform after applying edge detection. However, the circular Hough transform parameters seem to be very sensitive, i.e. the ''Sensitivity'' and ''EdgeTreshold''. A small change in one of these parameters has huge impact on the amount of circles that are detected. How can I avoid this or is there a better algorithm to detect the circular shaped fruits? Moreover, I need to use the Rmax of 85 for optimal results, while the absolute maximum Rmax is 55, after measuring the distance with imdistline.
I am using now the following parameters:
[centers,radii, metric] = imfindcircles(BW_Canny,[30 85],'Sensitivity',0.95,'EdgeThreshold',0.15);
viscircles(centers, radii,'EdgeColor','b');
I have added the original RGB image, the images after color thresholding and edge detection, and beneath my own results.


Answers (1)
Image Analyst
on 10 Jan 2022
0 votes
You don't need to find circular shapes. From your other posts, you're trying to find oranges on a tree. The oranges are almost always overlapping with other oranges so the combined blob is not round, or don't have a circular shape because there is shine on the rind, or leaves are obscuring the shape, making it not round. If you limit your segmentation to only round blobs, you're going to miss the majority of blobs.
That said, there is a 'circularity' property in regionprops that gives you the circularity of blobs. You can also use bwpropfilt() to remove blobs outside the acceptable range of circularity. Again, I recommend not doing that.
10 Comments
S.
on 11 Jan 2022
Image Analyst
on 11 Jan 2022
I don't know what you mean by "tuning". What are your plans if there is a semicircle there? Depending on the settings to imfindcircle(), it might be found or not found.
S.
on 13 Jan 2022
Image Analyst
on 13 Jan 2022
My code gives all orange blobs regardless of what shape they are. It seems weird to call a function that finds circles and then complain that it needs to be tuned to find non-circular shapes. I'm not sure I understand your rationale for using a circle-finding function. Sure the oranges are round in reality, but they don't always appear round in the image so we can't look only for round blobs or else we'll miss some of the oranges. Why not just use color segmentation to find the color(s) you want regardless of their shape? You can then filter them based on size (area), circularity, or whatever you want, for example to get rid of blobs that you consider too small to be of concern with the bwareaopen() function or bwareafilt() function.
S.
on 13 Jan 2022
Image Analyst
on 13 Jan 2022
regionprops() can return the centroid of the blob. It can also return the circularity which is (4*pi*area)/(perimeter squared), which is 1 for perfect circles and lower numbers for non-circles.
There is not a reliable way to tell if two orange blobs separated by green are the result of a single orange obscured by a leaf, or two oranges. That's why I think counting in this situation is never going to be perfect and why I recommend you just go with are fraction, or maybe a model composed of area fraction and blob count to get a model. Train the model by going out and actually physically counting the oranges and then make up a model that gives an estimate of the number of oranges there based on the area fraction and blob count. This will tell you when there are enough oranges to do your harvest.
Image Analyst
on 25 Jan 2022
You should not use regionprops on an edge image. I don't know why you did Canny on your original mask. I cannot say that the centroid of a perimeter image would be the same place as if the outline were filled solid. It probably won't be. Just use the original binary image if you have it. If you only have the original image, then call imfill(cannyImage, 'holes') to fill in those blobs, then call regionprops().
Image Analyst
on 28 Jan 2022
I can see that we're never going to see eye-to-eye on this. For another example you want to measure things that I say don't matter, like the location of the center of an orange, which of course varies tremendously depending on where the photographer was standing and how he was aiming the camera, and literally how the wind was blowing. Things like finding only round blobs, counting blobs, etc. will always be problematic and that's why, based on my 40+ years of image processing, you should look for other things like area fraction for determining when to harvest your crop or how much the oranges have grown.
So good luck to you with your approach.
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

