أرشيف تطبيقات باريستا هاسل

تحليل طحن القهوة

دليل البدء السريع – The idea of using a picture of coffee grinds to measure the size distribution came from Dr Jonathan Gagné. With generous help from Jonathan and the folks at Barista Hustle, this browser-based version opens up the technique to a wider audience.

The numerics are NOT yet optimized or validated, but you’ll get the general idea. The test image which opens is relatively low resolution so is not representative of a high quality image – but it is useful to show the principles. Its calibrated width is 138mm to get you started.

كيف تعمل هذه التقنية؟

Background explanation – الفكرة بسيطة. التقط صورة للحبوب المطحونة، وحدد تلقائيًا كل جزيء حقيقي في الصورة، ثم قم بعدّ وحدات البكسل في ذلك الجزيء، واحسب كيفية توزيع الحبوب بحسب أحجامها المتنوعة.

It is often imagined that such an “image analysis” technique would be very difficult. In reality, there are two major difficulties that are nothing to do with fancy image analysis:

1 – Getting even lighting, with perfect black/brown beans on a perfect white background is very hard. Any imperfection in the lighting, background, bean colour makes it harder to distinguish particle from background or noise.

2 – Calibration is far trickier than you might imagine. A pre-calibration requires you always to take the image from exactly the same distance. A calibration object in the image (a) takes space away from grinds and (b) needs some mouse-based user identification or a smart algorithm to define.

On the principle of “keep it simple”, the first problem is solved by providing a backlight to the grinds. In my case I used my laptop screen that folds flat – I could equally have used a monitor laying on its back. It helps that I have an excellent hand-held الفراغ cleaner that quickly sucks up the grains after a test.

The other simple approach used here is that somehow you accurately know the full width in mm of your image. My preferred technique is to include a scale along the top or bottom of the image. The app “blobs” it into a single large object which is automatically discarded by the MaxPixel control – or the colour is set so faint that the blobbing ignores it anyway.

ما عليك سوى قراءة المقياس (على سبيل المثال، وضع علامة كل 5 مم وتقريب آخر بضعة ميليمترات) ثم إدخال القيمة. ولأنني هنا أستخدم شاشة كمبيوتر محمول، فيمكنني إنشاء مقياس كصورة جرافيك، وتحسين الحجم والتباعد واللون وما إلى ذلك للحصول على أقصى درجات الدقة مع أقل تأثير على العدّ. 

Size analysis – Load an image. With the Pic-only option selected you can get a good idea of the image quality and can read off the scale and entered a good calibration value. You now have to decide on a Threshold value. Anything less bright that this will be considered as a particle, anything brighter will be ignored. You can move your mouse around the image and get an RGBK value. The K (for blacK) is grey-scale value used to threshold. Move over a few grains and get a feel for their K values (small) compared to the background (large). Then choose a Threshold value that safely includes your grains but excludes odd shadows, marks etc. – as best you can. Jonathan used the value from the Blue channel as this is most sensitive to the brown colour of the coffee grains. You can choose this option if you wish. If you click and drag the mouse over a grain you will get an idea of its size, providing your calibration is correct.

إذا كانت لديك صورة مشوشة تحتوي على الكثير من النقاط بحجم 1-2 بكسل، فقم بتعيين الحد الأدنى لوحدات البكسل Min-Pixels لتكون 5، مثلًا، للتغاضي عن هذا التشويش. وبما أن هذا قد يؤدي إلى حذف بعض الحبوب الحقيقية من الصورة، ولهذا قد تحتاج إلى الوصول إلى قيمة وسطية. غالبًا ما يمكن تعيين قيمة Max-Pixels عند قيمة متوسطة لتتمكن من استبعاد أشياء، مثل علامات المقياس أو القليل من الحافة السوداء التي تظهر في الصورة. ولكن إذا حددت قيمة صغيرة جدًا، فسيتم حذف بعض الحبوب الحقيقية من الصورة. وستتضمن الصورة كمية كبيرة جدًا من التفاصيل غير المرغوب فيها مما سيقلل من مصداقية الحسابات. فكلما ارتفعت جودة الإضاءة والصورة، قلت أهمية هذه التفاصيل إليك.

To analyze the sizes it is customary to place them into “bins”. Everything from 0-0.1mm might be in one bin, everything from 0.1-0.2mm in another etc. N-Bins lets you choose. Too few and you don’t get a sensible analysis. Too many and you probably don’t have enough grains per bin for the data to make statistical sense.

Each time you change your inputs things are re-calculated automatically – speeds seem to be OK if you don’t slide too wildly. You get NGrounds, the number of individual particles identified (within your Min-Max Pixels) and Max the largest one. This box is very useful. If you change Threshold or Min-Max Pixels  

بشرط أن تظل هذه القيم ضمن نطاق معقول وإذا لم يطرأ تغيير كبير عليها، فتُعتبر الآن قد وصلت إلى مرحلة ناجحة من عملية تحليل الصورة، حيث إن قياساتك أدق بكثير من أي مستوى تشويش قد يسببه وجود تفاصيل غير مرغوب فيها بالصورة. أما إذا تغيرت الأرقام بشكل كبير، فستعتمد النتائج النهائية على تقديرك الشخصي بدلاً من الأرقام الواقعية. وكلما خصصت المزيد من الوقت لضبط إضاءة الصور مع عدد قليل من الزخارف، قلت حاجتك إلى التلاعب في متغيرات التحكم.

The results – Suppose you have 99 particles each of diameter 1 and 1 particle of diameter 100. You can correctly say “My grind is 99% size 1” and you might be very happy – till you taste the coffee. Another way of thinking about it is to say that those 99 particles will weigh, say, 1 unit each so their combined weight is 99. Because weight depends on volume which depends on diameter³, the one large particle will weigh 1,000,000. Therefore, in weight terms your 99 particles are insignificant and effectively you only have a single large lump of coffee, which won’t extract efficiently.

So when we show the size distribution we could show it in Number terms, how many are at each diameter (or are in the bin with that diameter range). This matches our intuition when we look at the image – we see all those small grains and hardly notice the large ones. We can also show them in Area terms which expresses how much of the surface area comes from various particle sizes. And we can show them in Volume terms which tells us where the volume or mass of coffee really lies. I’ve chosen to plot all three. We can also plot them in a cumulative manner so you can readily see at which sizes interesting things happen. Some like to see them in logarithmic scale. The arithmetic of the calculations is discussed below.

إذا كان لديك جزيء كبير شاذ، فقد تكون صناديقك العلوية فارغة، مع تغيير مفاجئ في الصندوق (الحجم) النهائي. حاول إنقاص الحد الأقصى لوحدات البكسل إلى أقل من القيمة القصوى الموضحة في صندوق المعلومات بالأعلى. وسوف يختفي الصندوق الشاذ وسيبدو رسمك أكثر منطقية. بالطبع، إذا كان هذا الجزيء الشاذ حقيقيًا وحجمه أكبر بكثير، فعندها (كما سترى في رسم الحجم التراكمي) سيسيطر هذا الجزيء الكبير على عملية استخلاص القهوة!

Spreading the grinds – The app doesn’t get tired of counting. So the more particles you can pack into the image, the better the statistics for analysing the particle size. The problem is that if any two particles are touching, they will be counted as one larger particle. Finding a way to spread the maximum number of particles with the minimum number touching is one of your big challenges. Jonathan suggests sprinkling with your fingertips – an idea I found to be surprisingly good. He also has an option for you to delete touching particles from the image, but it requires you to make the judgement call and zap them with your mouse.

Your camera – With coffee grind analysis, as with everything else, it’s garbage in, garbage out. You can easily get a picture with your smartphone camera, but you will tend to find that the “smart” part of the phone is a real nuisance. It might autofocus on something important to it, and not to you. It might decide that your stark contrast really is unpleasant so will automatically smooth out your lighting. Who knows what “smart” algorithms it will invoke. Smartphones were not designed by people whose interests were primarily taking accurate, high contrast,

وعالية التباين لأغراض التحليل. فإذا كنت "ذكيًا" بما يكفي لمعرفة كيفية إيقاف تشغيل خصائص الكاميرا الذكية على هاتفك، فقد بدأت بذلك البداية الصحيحة.

My experience is that with my fairly good Canon camera, I need to turn off auto everything. By trying a few manual settings, I could get a التوازن of resolution, contrast, focus that time after time gave me the same results. When I allowed it to take over with automatic features, I never knew what I would get – to the level of detail required for good coffee grind analysis.

To make things even simpler (in the long run), set up a rig for the camera so it is always nicely square to your backlit source, with the scale clear at the top, at an optimum distance. In the image you see that I have my camera on a sturdy tripod and use a “hot shoe spirit level” (the yellow-green blob) to get everything square.

The Calculations – لا تقدم الصورة ثنائية الأبعاد معلومات كافية عن الحبوب ثلاثية الأبعاد تمكننا من تحليل أحجامها بدقة. لذا، فإن الحسابات ستعتمد على اختيار التقديرات.

وقد اختار جوناثان أسلوبًا أكثر تعقيدًا يستخدم معلومات الشكل ثنائي الأبعاد. لكنني اخترت نهجًا مختلفًا لغايات السرعة والبساطة، وربما ستحاول النسخة المستقبلية اتباع طريقة أكثر تعقيدًا.

All I know after the image processing is the number of pixels making up a “blob”. I can call this an area, A, so I know that if this was a circle, the radius would be given by Α=πr². Now I have the pseudo-radius, r=√(A/π), of each blob. I can then say that the surface area of the grain is 4πr² and its volume is 4/3πr³. This allows me, for each radius bin (though I plot it as the more comfortable diameter), to know the Number of particles in that bin, the Area of those particles and their Volume.

To report the results, for simplicity I give a Number, Area and Volume mean value to capture an “average”. For those familiar with the topic, these values are D[1,0], D[2,1] and D[3,2]. There is also a D-x which you define as D90, D80 etc. via the slider. This is the diameter below which 90%, 80% etc. of the grains are found. Other “average” values are available and further options might be added later.

من إعداد البروفيسور ستيفن أبوت خصيصًا لباريستا هاسل!

This app was made especially for Barista Hustle and our subscribers by Professor Steven Abbott. His extraordinary career has taken him all around the world, with gigs that have included working with banana growers in the Philippines, printing companies in Colombia and a coffee bag valve company in the USA. Prof Abbott is a world expert on drying science and انتشار. His of apps and ebooks are a go-to for anyone serious about the science of extraction.

شاهد مجموعة كتب البروفيسور ستيفن أبوت هنا!