Counting different stages of berries

Hello,
I am very new to imageJ, and this whole field, and am trying to figure out how to take an image of fruit, say blackberries, and then count the different berries at the different stages.

Say, for example, I want to determine what berries are black, green, and pink, and then get a count of all the berries in each category. I am willing to manually go through the image and designate each berry in it’s appropriate stage, but don’t then want to have to go back and count each one.

Anyone have any insight on how to do this most effectively? Happy to hope on a google hangout if easier, willing to reward support with giftcards, and desperately looking for some guidance! Thank you.

If you are willing to manually count the berries, you might want to consider the Points tool in QuPath, where you can make a project for all of your images, and get summary information for the whole set of images.
Starting a project: QuPath Intro: Choose your own analysis(adventure)
Information on Points: QuPath Intro: Choose your own analysis(adventure)
Generating summary measurements:QuPath Intro: Choose your own analysis(adventure)
Most of the second link won’t be necessary for you, just the two scripts that generate a CSV for your whole project, generally with one line per image showing class counts.
If you use version 0.1.3 or later, your counts are tracked for you quite easily, though there are some better ways of generating project level summary information. I would still use the first script to convert the spots to detections due to the easier to read output from the whole project.

Thank you so much. I have been diving in and reading this in depth, but was wondering if you’d be willing to show me a quick video demo if I provided the image? I am ok manually counting the berries now, and hopefully can concurrently be training the system for future counts, if possible.

Using the linked image.

I used the points tool to generate some points. Poorly.
image
I used the Annotations tab on the left, right clicked in the list of classes, and used Add class to add Black and NotBlack classes.
image
I selected my set of points and assigned them the class Black through the context menu.

I added another points object (a collection of points) and added some of those points to the image.


I similarly right clicked on those selected points and assigned them to NotBlack

If you are using one of the newer versions of QuPath (0.1.3+), you are basically done, for an image, as you can use the Measurements->Show annotation measurements button to see your totals.
image
If you are using a project, and you should always be using a project, see here why, you can run Pete’s scripts to generate a summary spreadsheet for the project.
Pete script 1 which is needed for Pete script 2.
Pete script 2, to generate a single sheet for a whole project.

Active presenter and Windows are not playing well during the update process today.

This can all be further extended to count individual clusters, by converting the points to detections, and drawing annotations around each berry cluster.

Thank you very much. You have no idea how much I appreciate this.

Quick follow-up: now with these images labeled, is QuPath the system where I can then use these images to train a machine learning system to automatically detect and count the points? Or is there a similar system for that?

I may come back with some more questions, but wow this sets me up well. Thank you!

Automatically doing this would require segmentation, and for that you would likely need some sort of pixel classifier or deep learning algorithm. Segmenting tightly clustered black objects is… very difficult. The other berries might be easier. You could try the Weka pixel classifier in FIJI or Ilastik or others like it, but I don’t know that it will work out very well.

I suspect it would need to be a very well trained deep learning segmenter.

Edit: If you could get away with counting area (assuming most berries were approximately the same size), you could very easily use a pixel classifier to count the area of each type of berry within an image.

Thank you. Really, I appreciate this help so much. I will play around with this tool to do manual counting and see if it gets the job done for now, before I venture down some full-automation path. Thanks again. If you send me your email, would love to send you a starbucks giftcard as a thanks for the help. Much appreciated!!

1 Like

No worries, just glad to help.