Complementing Digital Image Analysis and Laser Distance Meter in Beer Foam Stability Determination

: The aim of this research is to investigate the possibility of applying a laser distance meter (LDM) as a complementary measurement method to image analysis during beer foam stability monitoring. The basic optical property of foam, i.e., its high reﬂectivity, is the main reason for using LDM. LDM measurements provide relatively precise information on foam height, even in the presence of lacing, and provide information as to when foam is no longer visible on the surface of the beer. Sixteen different commercially available lager beers were subjected to analysis. A camera and LDM display recorded the foam behavior; the LDM display which was placed close to the monitored beer glass. Measurements obtained by the image analysis of videos provided by the visual camera were comparable to those obtained independently by LDM. However, due to lacing, image analysis could not accurately detect foam disappearance. On the other hand, LDM measurements accurately detected the moment of foam disappearance since the measurements would have signiﬁcantly higher values due to multiple reﬂections in the glass.


Introduction
Foam stability and retention is an important indicator of beer quality and freshness. Beer foam stability is expressed as a change of foam height over a certain period. Brewing industries are devoted to producing stabile and retentive foam head since many consumers like to see a big and rich head of foam in a glass. Different for every beer type, beer foam can also result in the lacy pattern at the bottom of the finished beer, known as lacing or cling, especially appreciated in Belgian beers [1]. Foam quality is described by several characteristics such as stability, retention, viscosity, whiteness, bubble size, density [2] and many research papers specifically describe, quantify and monitor foam stability via different methods . Foam stability is a result of many factors. Some of them include foam-positive proteins (Z, LTP1, hordein fragments), hop acids, non-starch polysaccharides and metal ions, while lipids and high ethanol levels reduce foam stability [2,26].
Recent scientific advances in image analysis methods have led to the popularization of this method and its ubiquitous application in different fields. Image analysis methods display several setbacks such as camera focusing as well as light reflection off the surface and within the beer glass [25]. This demands that the measuring set-up has to be done under controlled directional light conditions which entail lower illuminance values and automated focusing. In beer foam monitoring via image analysis, an additional setback exists as a result of foam lacing or clinging, which makes it impossible to detect the actual level of foam [27].
In our previous research [27], the use of a RGB camera in foam assessment was portrayed as a low-maintenance, cheap and easy method that requires minimal input from the employees and is applicable in every laboratory. However, if applied alone, it gives inaccurate results when foam lacing is present. With the introduction of a 3D camera [27], the problem of lacing is no longer present, but the automated image analysis method based on the analysis of RGB video images and 3D data for accurate detection of the foam height becomes more complex for everyday usage. The proposed solution identifies the necessity to have two cameras and led to two related analyses being conducted. In order to simplify the procedure of obtaining accurate foam height data from the measurements provided by the 3D camera, it was necessary to replace it with an accurate available device whose output data could be detected by an existing recognition system based on an RGB camera. Previous knowledge of working with solids has imposed the laser distance meter (LDM) as a logical solution. Using one RGB camera and one software [27], it is possible to measure the height of the foam and recognize the measured value on the LDM display by image analysis of the recorded video. For a given frame in the region of interest, color segmentation by filtering thresholding in HSV color space was used to generate a binary image. By performing morphological operations of erosion followed by dilation on the binary image, the average height of foam is measured as well as the value on LDM using optical character recognition.
The initial assumption based on a high level of foam reflectivity did not include the possibility of laser beam penetration into the foam, which proved to be the biggest problem in measurement accuracy. What has proven to be crucial to complete this research is that LDM detects the moment of foam disappearance. Another identified challenge was the inability to recognize digits on the LDM display using optical character recognition, due to the refreshing of the display giving the camera unreadable data.
The aim of this paper was to assess the applicability of a non-invasive, objective, and affordable image analysis method based on one RGB camera and LDM measurements under real conditions, in order to monitor and valorize the foam stability of lager beers.

Materials and Methods
Sixteen samples of commercially available light lager beers packaged in brown/green glass bottles (0.5 L) underwent analysis using the methods described below. Ten were domestic beers and six others were foreign (Germany, Czech Republic, Denmark, Slovenia and Holland). Beer samples were held at room temperature (23 • C) for two days, in order to reduce the influence of temperature fluctuations, as can been seen from Figure 1. In our previous research [27], the use of a RGB camera in foam assessment was portrayed as a low-maintenance, cheap and easy method that requires minimal input from the employees and is applicable in every laboratory. However, if applied alone, it gives inaccurate results when foam lacing is present. With the introduction of a 3D camera [27], the problem of lacing is no longer present, but the automated image analysis method based on the analysis of RGB video images and 3D data for accurate detection of the foam height becomes more complex for everyday usage. The proposed solution identifies the necessity to have two cameras and led to two related analyses being conducted. In order to simplify the procedure of obtaining accurate foam height data from the measurements provided by the 3D camera, it was necessary to replace it with an accurate available device whose output data could be detected by an existing recognition system based on an RGB camera. Previous knowledge of working with solids has imposed the laser distance meter (LDM) as a logical solution. Using one RGB camera and one software [27], it is possible to measure the height of the foam and recognize the measured value on the LDM display by image analysis of the recorded video. For a given frame in the region of interest, color segmentation by filtering thresholding in HSV color space was used to generate a binary image. By performing morphological operations of erosion followed by dilation on the binary image, the average height of foam is measured as well as the value on LDM using optical character recognition.
The initial assumption based on a high level of foam reflectivity did not include the possibility of laser beam penetration into the foam, which proved to be the biggest problem in measurement accuracy. What has proven to be crucial to complete this research is that LDM detects the moment of foam disappearance. Another identified challenge was the inability to recognize digits on the LDM display using optical character recognition, due to the refreshing of the display giving the camera unreadable data.
The aim of this paper was to assess the applicability of a non-invasive, objective, and affordable image analysis method based on one RGB camera and LDM measurements under real conditions, in order to monitor and valorize the foam stability of lager beers.

Materials and Methods
Sixteen samples of commercially available light lager beers packaged in brown/green glass bottles (0.5 L) underwent analysis using the methods described below. Ten were domestic beers and six others were foreign (Germany, Czech Republic, Denmark, Slovenia and Holland). Beer samples were held at room temperature (23 °C) for two days, in order to reduce the influence of temperature fluctuations, as can been seen from Figure 1. Glasses (0.5 L; generic brand, model Lilith, h = 185 mm, Ø = 0.75 mm) were washed, and degreased then rinsed in demineralized water and dried. All the glasses were identical and left to cool down at room temperature prior to analysis, which can be seen from Figure 2. Values of the thermogram legend are set by the infrared thermal camera, according to the registered radiation. Glasses (0.5 L; generic brand, model Lilith, h = 185 mm, Ø = 0.75 mm) were washed, and degreased then rinsed in demineralized water and dried. All the glasses were identical and left to cool down at room temperature prior to analysis, which can be seen from Figure 2. Values of the thermogram legend are set by the infrared thermal camera, according to the registered radiation. For each experiment, beer was hand-poured according to [28], and as described in Nyarko et al. [27]. Figure 3 shows the experimental setup used in data collection. The basic idea was to develop a complementary method that could provide information about foam stability in cases when foam lacing obstructs visual information for the RGB camera. The optical characteristic of foam to reflect 88% of light (Table 1) [29] led to the idea that LDM could be employed in this research.

Image Analysis of Video
The automated image analysis procedure described and used in [27] for measuring foam height from recorded RGB videos was implemented in this paper as well. A brief description of the procedure is described herein. For each experiment, beer was hand-poured according to [28], and as described in Nyarko et al. [27]. Figure 3 shows the experimental setup used in data collection. The basic idea was to develop a complementary method that could provide information about foam stability in cases when foam lacing obstructs visual information for the RGB camera. For each experiment, beer was hand-poured according to [28], and as described in Nyarko et al. [27]. Figure 3 shows the experimental setup used in data collection. The basic idea was to develop a complementary method that could provide information about foam stability in cases when foam lacing obstructs visual information for the RGB camera. The optical characteristic of foam to reflect 88% of light (Table 1) [29] led to the idea that LDM could be employed in this research.

Image Analysis of Video
The automated image analysis procedure described and used in [27] for measuring foam height from recorded RGB videos was implemented in this paper as well. A brief description of the procedure is described herein. The optical characteristic of foam to reflect 88% of light (Table 1) [29] led to the idea that LDM could be employed in this research.

Image Analysis of Video
The automated image analysis procedure described and used in [27] for measuring foam height from recorded RGB videos was implemented in this paper as well. A brief description of the procedure is described herein.
Video recordings, with a frame rate of 30 fps, were taken of each beer sample over a 5 min period using a Canon G16 RGB camera(Canon PowerShot G16; Ota City, Tokyo, Japan). Determining the height of beer foam using image analysis was performed using seven steps ( Figure 4):

1.
A region of interest (ROI) of known width (w) and height (l) for a given frame of the recorded video is defined. It is imperative the whole height of the foam and part of the beer is covered by the ROI since all the next steps are performed only on this ROI.

2.
The ROI is color segmented in HSV color space by thresholding using previously defined lower and upper values of the foam color in the HSV color space.

3.
A binary image of the thresholded ROI in HSV color space is generated.

4.
Morphological operations of erosion followed by dilation are performed on the binary image to eliminate small white noises or artifacts that appear in the image.

5.
The largest contour on the binary image is determined. This contour marks the boundary of the foam/head. 6.
The area (A) of the region enclosed by the largest contour is determined. 7.
The average height (h) of the beer foam in pixels is then determined using Equation (1): Video recordings, with a frame rate of 30 fps, were taken of each beer sample over a 5 min period using a Canon G16 RGB camera(Canon PowerShot G16; Ota City, Tokyo Japan). Determining the height of beer foam using image analysis was performed using seven steps ( Figure 4): 1. A region of interest (ROI) of known width (w) and height (l) for a given frame of the recorded video is defined. It is imperative the whole height of the foam and part of the beer is covered by the ROI since all the next steps are performed only on this ROI 2. The ROI is color segmented in HSV color space by thresholding using previously defined lower and upper values of the foam color in the HSV color space. 3. A binary image of the thresholded ROI in HSV color space is generated. 4. Morphological operations of erosion followed by dilation are performed on the binary image to eliminate small white noises or artifacts that appear in the image. 5. The largest contour on the binary image is determined. This contour marks the boundary of the foam/head. 6. The area (A) of the region enclosed by the largest contour is determined. 7. The average height (h) of the beer foam in pixels is then determined using Equation (1): The average height of the beer foam in mm can be obtained using the conversion 1 mm = 6.6 px. The procedure was implemented in the Python programming language [30] using the OpenCV library v.3.4.2 [31]. Since the beer glass is always located in the same position the algorithm can be run in either offline or online mode in order to automate the process of determining the beer foam height. In this paper, the height of foam was determined from the recorded videos (offline mode). Every 10 s, 5 consecutive frames were taken and the height of foam determined for each frame. The average height in pixels for these 5 measurements was taken to represent the height of foam every 10 s. The average height of the beer foam in mm can be obtained using the conversion 1 mm = 6.6 px.
The procedure was implemented in the Python programming language [30] using the OpenCV library v.3.4.2 [31]. Since the beer glass is always located in the same position, the algorithm can be run in either offline or online mode in order to automate the process of determining the beer foam height. In this paper, the height of foam was determined from the recorded videos (offline mode). Every 10 s, 5 consecutive frames were taken and the height of foam determined for each frame. The average height in pixels for these 5 measurements was taken to represent the height of foam every 10 s.

Measurement Using a Laser Distance Meter
To measure the decrease in foam height, a BOSCH GLM 80 Laser Distance Meter (Bosch, Gerlingen-Schillerhöhe, Germany) with an available option to search for maximal and minimal value was used ( Figure 5). This option enabled the measurement of foam height decrease during a 5 min interval with a frequency of 1 Hz. This was also recorded by the aforementioned RGB camera in video format. As shown in Figure 3, the LDM measured the distance to the top of the foam head by reflecting off a mirror placed above the beer glass. Hence, with time, the decrease in foam height is measured as an increase in distance by the LDM.

Measurement Using a Laser Distance Meter
To measure the decrease in foam height, a BOSCH GLM 80 Laser Distance Meter (Bosch, Gerlingen-Schillerhöhe, Germany) with an available option to search for maximal and minimal value was used ( Figure 5). This option enabled the measurement of foam height decrease during a 5 min interval with a frequency of 1 Hz. This was also recorded by the aforementioned RGB camera in video format. As shown in Figure 3, the LDM measured the distance to the top of the foam head by reflecting off a mirror placed above the beer glass. Hence, with time, the decrease in foam height is measured as an increase in distance by the LDM. We initially considered automating the readings from the LDM using optical character recognition on each video frame. However, this idea was dropped due to the erratic changes on LDM display during image sampling, as can be seen in Figure 6.

Results and Discussion
RGB video recordings were obtained for 16 samples (denoted by S01…S16), each lasting 5 min. Using the image analysis procedures described in Section 2.1, the estimated height (in mm) was obtained from the RGB video every 10 s. The results of the measurements are displayed in Table 2.

Sample
Time S01 S02 S03 S04 S05 S06 S07 S08 S09 S10 S11 S12 S13 S14 S15 S16  We initially considered automating the readings from the LDM using optical character recognition on each video frame. However, this idea was dropped due to the erratic changes on LDM display during image sampling, as can be seen in Figure 6.

Measurement Using a Laser Distance Meter
To measure the decrease in foam height, a BOSCH GLM 80 Laser Distance Mete (Bosch, Gerlingen-Schillerhöhe, Germany) with an available option to search for maxima and minimal value was used ( Figure 5). This option enabled the measurement of foam height decrease during a 5 min interval with a frequency of 1 Hz. This was also recorded by the aforementioned RGB camera in video format. As shown in Figure 3, the LDM meas ured the distance to the top of the foam head by reflecting off a mirror placed above th beer glass. Hence, with time, the decrease in foam height is measured as an increase in distance by the LDM. We initially considered automating the readings from the LDM using optical charac ter recognition on each video frame. However, this idea was dropped due to the errati changes on LDM display during image sampling, as can be seen in Figure 6.

Results and Discussion
RGB video recordings were obtained for 16 samples (denoted by S01…S16), each last ing 5 min. Using the image analysis procedures described in Section 2.1, the estimated height (in mm) was obtained from the RGB video every 10 s. The results of the measure ments are displayed in Table 2.

Results and Discussion
RGB video recordings were obtained for 16 samples (denoted by S01 . . . S16), each lasting 5 min. Using the image analysis procedures described in Section 2.1, the estimated height (in mm) was obtained from the RGB video every 10 s. The results of the measurements are displayed in Table 2.
Based on the information from Tables 2 and 3 and by applying the algorithm shown in Figure 10, information about lacing, i.e., the time instance of disappearance of foam, can be obtained. In Figure 10, X denotes the sample measurement of foam height determined by image analysis, while Y denotes that determined by LDM. It should be noted that this procedure can be used in both online and offline measurement modes to determine when to end measurement. In this research case, offline analysis was performed. As mentioned earlier, a video lasting for 5 min (300 s) was taken of each beer sample. Starting with t = 0 s, measurements are performed every 10 s. Foam height is automatically determined via image analysis as previously described, while LDM measurements need to be determined manually. In order to synchronize LDM measurements with those obtained by image analysis, the same five consecutive frames used in image analyses are stored and the LDM measurements are read manually ( Figure 6). The instant the current LDM measurement significantly differs from the previous measurement is an indication that the laser has fully penetrated the foam or the foam layer is significantly reduced (marked in bold in Table 3). At this point, the automated measurement procedure via image analyses is stopped and lacing can be denoted as the foam height determined by image analysis (X n ).        By comparing the numerical values from Figure 11 and photos of the last phase of measurement (Figure 12), it can be concluded that the algorithm gave satisfactory results in all cases.

Conclusions
Beer foam stability is easily affected by storage under unfavorable conditions (temperature fluctuations, UV light exposure). The novelty of this paper is the use of a laser By comparing the numerical values from Figure 11 and photos of the last phase of measurement (Figure 12), it can be concluded that the algorithm gave satisfactory results in all cases.   By comparing the numerical values from Figure 11 and photos of the last phase of measurement (Figure 12), it can be concluded that the algorithm gave satisfactory results in all cases.

Conclusions
Beer foam stability is easily affected by storage under unfavorable conditions (temperature fluctuations, UV light exposure). The novelty of this paper is the use of a laser

Conclusions
Beer foam stability is easily affected by storage under unfavorable conditions (temperature fluctuations, UV light exposure). The novelty of this paper is the use of a laser distance meter combined with the application of digital image analysis in beer foam stability measurement. The basic hypothesis, however, was to rely on the laser distance meter to provide more precise measurements compared to that obtained by image analysis. The data obtained by laser distance meter turned out to be significantly lower than the expected values. This could be attributed to the multiple reflections between the foam (bubbles) layers. Nevertheless, the use of the laser distance meter clearly identifies the instant the foam disappears. With this knowledge, it can be determined whether the values obtained in measurements obtained by the implemented automated image analysis procedure are due to lacing or not. However, in order to truly corroborate this method, further examinations involving different beers (wheat, craft, black) with different foam characteristics should take place. The main characteristics of this method are affordability and precision in detection of foam disappearance, which cannot be recorded with the human eye. Moreover, with this method we actually tried to investigate whether the foam matrix can be detected and quantified via optical methods.
Since we depleted all optical methods, future aspects of this research include ultrasound application in foam stability detection and measurement. This could also transpire to be a cheap, precise and available detection method.