Guides ·

How to count objects in a photo automatically

Counting a few hundred small things by hand is slow and easy to get wrong. A photo can be counted automatically, but only as well as it was taken, and only if you check the result. Here is how automatic counting works, how to take a photo that counts well, and a real test: 42 hazelnuts, counted by hand and by the free unmake counter.

Drop your photo on the free unmake object counter, glance over the marks, and fix any miss with a tap.Try it on your own file
Hazelnuts on the unmake counter: 27 objects, orange outlines with numbers on the loose nuts, two nuts with two marks each and the middle of the heap without marks
27 found automatically against 42 counted by hand: the heap and the highlights are where it goes wrong. Photo: Ivar Leidus, CC BY-SA 4.0, via Wikimedia Commons.

How automatic counting works

Most counters, from lab software to phone apps, follow the same recipe. First they separate objects from the background by brightness or colour, a step called thresholding. Then they outline each separate patch and count it. Touching objects form one patch, so a second step splits patches where they narrow into a waist; ImageJ's Watershed command is a well-known version of this.

Last, patches far smaller or larger than the rest are dropped or flagged. A counter like this does not know what a hazelnut is. It counts what stands out, so the photo decides most of the result.

Take a photo that counts well

Shoot from straight above, with the objects and a little background all round. Use a plain background that contrasts with them: dark seeds on white paper, pale beans on black card. Spread the objects out so they don't touch; a heap is the hardest case for any counter.

Light evenly, from a window or two lamps, and avoid shine: glossy things reflect the light in bright patches that look like separate objects. If you also want sizes in millimetres, put a sheet of A4 or US Letter paper, or a bank card, in the photo.

Check the marks, always

A count with a mark on every object is a count you can check in seconds. Look for four things: objects with no mark, two touching objects with one mark, one object with two marks, and marks on things that aren't objects, such as a shadow or a crumb.

Marks are also the fastest way to count by hand: put a dot on each object in a photo editor or on a printout, so you never count one twice or lose your place.

Four cases an automatic counter meets: an object found once, two touching objects marked as one, one shiny object marked twice, and a faint object missed, each compared with a hand count
What to look for when you check the marks.

Fixing the count on the unmake page

The unmake counter counts in the browser; the photo stays on your device unless you press Send under the optional What are these? button. Drop a photo and every object it finds gets an orange outline and a number. Tap a mark to remove it, tap empty space to add one; the panel then says how many were found automatically and how many you added or removed.

Clumps it cannot split are estimated from their size and marked ≈. Under Adjust, Count one kind only counts things like one object you tap, and Sensitivity runs from fewer to more. Details shows the size spread, Objects (CSV) saves one line per object, and Download picture saves the count with its marks.

When to trust the number

Objects lying apart on a plain background are the easy case. On the counter's own sample, 17 buttons on white, it finds all 17, the pale one included.

Heaps, shine and low contrast are where any automatic count needs help, as the hazelnut test shows. The page itself says it is not for dispensing medicines or any count where a mistake can hurt someone.

Seventeen sewing buttons on white on the unmake counter: 17 objects, each with an orange outline and a number
The easy case: buttons apart on white, all 17 found automatically. Photo: Jorge Barrios, public domain, via Wikimedia Commons.

A worked example: 42 hazelnuts, partly in a heap

  1. The photo: 3,840 × 2,560 px, hazelnuts on a pale blue surface, about ten lying apart and the rest in a heap.
  2. We counted by hand first, with a numbered dot on each nut: 42.
  3. Dropped on the counter: 27 objects, with a note that 3 clumps could not be split and were estimated from their size.
  4. The marks show why. Most loose nuts got one mark each, but the middle of the heap got none, two loose nuts got two marks each where a highlight cut them in half, and one single nut was estimated as ≈2.
  5. Count one kind only depends on which nut you tap: our tap on one loose nut gave 48, and taps on other loose nuts gave counts from 24 to 56.
  6. Single taps do work: one tap on a doubled nut removed its extra mark, and the panel read 26 found automatically, 1 removed by you. For a heap like this, though, the real fix is a new photo with the nuts spread out.

Common mistakes

Questions

How accurate is counting objects in a photo?

It depends on the photo. Objects apart on a plain background come out close to exact (all 17 buttons on the page's sample); a shiny heap does not (27 of 42 hazelnuts). Check the marks either way.

Can I count objects in a photo on my phone?

Yes. The unmake counter runs in a phone browser: take the photo from straight above, then tap to fix any marks.

How do I count one kind of object among others?

Open Adjust, tap Count one kind only, then tap one typical object; the page counts only things like it.

Can it measure the objects too?

Yes. With a sheet of paper or a bank card in the photo, sizes come out in millimetres, otherwise in pixels. The CSV lists every object's size.

Sample file: Hazelnuts (Corylus avellana).jpg (3,840 px copy) · CC BY-SA 4.0 (Ivar Leidus)

Sources

Drop your photo on the free unmake object counter, glance over the marks, and fix any miss with a tap.Try it on your own file