Is there something that will detect/count circles in a photo?
February 17, 2011 11:49 AM   Subscribe

How can I detect circles/ovals in a photo, and ideally count them automatically?

I'm trying to shortcut a process that takes too much relatively unproductive time...counting the ends of logs in a stack (inventorying in the lumber industry). Is there software (preferably free/open-source) that will detect circles (or slight ovals) in a photo and count them?

Thanks!
posted by swimming naked when the tide goes out to Computers & Internet (11 answers total) 1 user marked this as a favorite
 
If you are willing to imagine a cross-section of a log as analogous to a red blood cell on a glass slide, you can use the free ImageJ package to count particles.
posted by Blazecock Pileon at 11:54 AM on February 17, 2011 [2 favorites]


Not software, but you could outsource this work to Mechanical Turk. To ensure accuracy, you could submit each picture to the workers more than once and then re-examine only those that resulting in conflicting counts.
posted by carmicha at 12:05 PM on February 17, 2011


OpenCV, but it's got a bit of a learning curve.
posted by SweetJesus at 12:14 PM on February 17, 2011


Also, it looks like circle detection with OpenCV is a well-tread area.
posted by SweetJesus at 12:17 PM on February 17, 2011 [1 favorite]


Another vote for OpenCV. Its the go-to computer-vision framework for anything that's not exotic or requiring extreme performance. Also free.
posted by tempythethird at 12:51 PM on February 17, 2011


Thanks all. As soon as B_P posted about ImageJ, I downloaded it and gave it a try. It's so-so...it tended to not be fine-grained enough to determine the different between two logs that are right next to each other because it's based on colour difference and for the most part there isn't enough of a difference for it to determine separate "particles".

I'll give OpenCV a try next!
posted by swimming naked when the tide goes out at 1:02 PM on February 17, 2011


I've done a certain amount of image analysis in the past.

One thing that's worth considering is that pre-processing the image can really help.

By that I mean if you just grab an image (with different light levels and angles on different days/times) and chuck it at a circle detection algorighm you may find your results are patchy - by contrast (ha-ha) if you do stuff to the image (basically remove unnecessary information) before applying circle detection you may end up with a reasonably robust result.

Are you able to post some sample images online ?
posted by southof40 at 1:57 PM on February 17, 2011


Try masking and contrast enhancement to help eliminate areas that aren't of interest, and to maximize difference between elements of interest.
posted by Blazecock Pileon at 2:49 PM on February 17, 2011


Yeah, what southof40 says, if you can perform some sort of adjustments to make the log ends pure white and everything else black that might mean you can use ImageJ.
posted by Brainy at 2:50 PM on February 17, 2011


Even with openCV you're going to need a nicely binarized image to start with.

You might want to convert the image to gray scale, use an adaptive threshold command and go from there.

It could help to run morpho thinning on the output of the adaptive threshold or the canny edge detector.

openCV uses the Hough transform to find circles. The good news is that when it works, it works pretty well. The bad news is that the Hough transform, done exhaustively is slow-ish. For your task it might not be so bad.
The good news is that I devised a straightforward way to speed up the Hough transform by about a factor of 20. The bad news is that my company holds the patent on it.

I write image processing code for a living, FYI. My company's toolkit has most of the image prep tools, but not the circle detector (I have it prototyped, but frankly, we don't get a lot of demand for it, so it's not public).
posted by plinth at 4:46 PM on February 17, 2011 [1 favorite]


Followup: After struggling for quite a while, I just could not get OpenCV to compile (running on Linux Mint 9). It's asking for libraries that don't exist within the standard repository, and enough of those that I don't want to hunt down each just to see if this will work.

ImageJ might have some promise if I can define the initial image nicely and decide on a set of workable initial parameters. Unfortunately, if I have to do substantial image manipulation before circle detection this ends up not being worth the effort. Mechanical Turk would be a far cheaper and faster option I would guess.
posted by swimming naked when the tide goes out at 11:58 AM on February 21, 2011


« Older Muscianship at work?   |   How export list of sent emails? Newer »
This thread is closed to new comments.