COFFEE DATA SCIENCE

Measuring Fines in Coffee Grounds using Advanced Image Processing

Using image processing to understand grinder performance Part 3

Robert McKeon Aloe
Towards Data Science

--

Previously, I explored how to use a few sieves combined with imaging to give decent looking particle distributions to help examine grinders. Now, I will dive back into the images to see what could be improved and cleaned. I noticed in some of the images a few issues, and one troubling issue was fines clumping together or sticking to larger particles.

Quick Review

I take an image, determined the measurement ground truth (pixels to mm²) using the piece of paper, then took a threshold to find the particles.

All images by author

Connected Components

After I convert an image of coffee grounds to a binary image, I then find all the individual particles using connected components:

  1. 8-connectivity: a pixel is connected to another if it is in any of the 8 surrounding pixels.
  2. 4-connectivity: a pixel is connected to another if it is above, below, right, or left but not diagonal. 4-Connectivity is a subset of 8-connectivity.
All images by author

In this close up view of some coffee particles, I noticed some particles were connected in such a way.

False color for particle intensity

So I switched to 4-connectivity when finding connected components, and it seemed to gain me a few percentages of particles across the board.

Overlapping Particles

Then I looked at some overlapping particles. So I looked at some images in false color.

There were some strange shapes. Below, it seems most of the pieces have multiples particles overlapping.

There are a lot of ways the particles could overlap especially if they are different sizes as illustrated below:

Removing Particles based on Shape

So I looked at the perimeter of the shape vs the equivalent diameter. If these are more or less equal, then the particle is a circle. In the very best case, coffee grounds are spherical, but as we have previously seen, coffee is not round. There seemed to be quite a few particles that weren’t round as I show below:

I focused on particles that were more than a few pixels wide, and I wanted to investigate particles with this ratio of Perimeter/Pi : Equivalent Diameter greater than 1.1. This number was arbitrary, but I thought I would start off as such. The number of interesting particles varied by how I was looking at the coffee in Normal and Zoom pictures, across sieves, and across grind settings.

So I looked a few examples:

It is possible that these particles could be separated using image intensity, but I figured I would just throw them out. Why worry about them when they aren’t that large of the total number of particles imaged.

Sub-pixel Approximation of Particle Size

The difficult of coffee particles is that they can be very small. Once you get down to a 1 x 1 pixel particle, it is around 100um, and you don’t know if it is actually smaller. So I used the average pixel intensity to estimate smaller particles.

A single 1 pixel diameter pixel could be at the maximum intensity or less. Usually, a good particle of more than a few pixels has the maximum intensity for the center, but not at the side edges. This allows a bit more resolution considering there are no other aggressors in the image that could be causing confusion.

Effects on Particle Distributions

Let’s start by looking at the original 8-Connected:

Here we have 4-Connected, and I removed particles lacking circularity, and computing diameter by intensity as a sub pixel approximation:

Here is a comparison, but it can be difficult to see:

If we look at the images of the grounds without using the sifting knowledge, we can apply these extra techniques as well. These get more reasonable, but 15 and 30 are hard to distinguish here. I think using the sifter for the small amount of grounds is still important for a more accurate measurement.

Left: 8-Connected from images of grounds, Right: 4-Connected of the same images using intensity and throwing out bad data

Imaging individual coffee particles is more complex because they don’t always play nice. Using a sifter with two screens does greatly improve this calculation, and it is makes determining particle distribution more accessible. However, it would not be the preferred method.

--

--

No responses yet