Sandeep
Sandeep

Reputation: 21144

MATLAB image processing of small circles

I have an image which looks like this:

Bottle

I have a task in which I should circle all the bottles around their opening. I created a simple algorithm and started working it. My algorithm follows:

I did according to the algorithm above and but I have some portion of the image around which I draw a circle. This is because I have selected the area since the area of the mouth of bottle and the remained noise is almost same. And so I yielded a figure like this.

The processing applied on the image look like this:

Enter image description here

And my final image after plotting the circle over the original image is like this:

Enter image description here

I think I can deal with the extra circle, that is, because of some white portion of the image remained as shown in the figure 2 below. This can be filtered out using regionproping for eccentricity. Is that a good idea or there are some other approaches to this? How would I deal with other bottles behind the glass and select them?

Upvotes: 10

Views: 1985

Answers (2)

Jeb
Jeb

Reputation: 3799

I've used the same approach as midtiby's third suggestion using the ratio between area and perimeter called shape factor:

4π * Area /perimeter^2

to detect circles from a contour traced image (from the thresholded image) to great success;

http://www.empix.com/NE%20HELP/functions/glossary/morphometric_param.htm

Regarding the 4 unfound bottles, this is rather tricky without some a priori knowledge of what it is you're looking at (as discussed using the 4 x 5 grid, then looking from the centre of each cell). I did think that from the list of contours, most would be of the bottle tops (which you can test using the shape factor stuff), however, one would be of a large rectangle. If you could find the extremities of the rectangle (from the largest contour in terms of area), then remove it from the third image, you'd be left with partial circles. If you then contour traced those partial circles and used a mixture of shape factor/curve detection etc. may help? And yes, good luck again!

Upvotes: 2

midtiby
midtiby

Reputation: 15116

Nice example images you provide for your question!

One thing you can use to detect the remaining bottles (if there are any) is the well defined structure of the placement of the bottles. The 4 by 5 grid of the bottle should be relatively easy to locate, and when the grid is located you can test if a bottle is detected at each expected bottle location.

With respect to the extra detected bottle, you can use shape features like

  • eccentricity,
  • the first Hu moment
  • a ratio between the perimeter length squared over the area (which is minimized for a circle) details here

If you are able to detect the grid, it should be easy to located it as an outlier (far from an expected bottle location) and discard accordingly.

Good luck with your project!

Upvotes: 5

Related Questions