*2.4. Image Processing*

The pictures of the probe and the microscope were evaluated with an existing MATLAB routine [69]. Based on the difference in contrast between the crystals and the background, the crystals could be isolated through contrast enhancement and binarization. In addition, a dynamic background subtraction out of a picture series was carried out to eliminate scratches or immobile adherent particles. The KH2PO4 crystals, especially, have large bright areas in the crystal center (see Figure 3a) that would lead to erroneous object identification. Therefore, morphological closing and region filling was utilized to fill the empty areas within the crystals.

The evaluation focuses on single crystals only, assuming agglomerates are of negligible number. Therefore, two shape descriptors, the numerical eccentricity, ε, (Equation (4)) of an ellipse, and solidity, s, for the description of the convexity (Equation (5)), were used to exclude agglomerates from further evaluation.

$$
\varepsilon = \frac{\sqrt{\mathbf{a}^2 + \mathbf{b}^2}}{\mathbf{a}} \tag{4}
$$

$$\mathbf{s} = \frac{\mathbf{A}}{\mathbf{A}\_{\text{conv}\mathbf{x}}} \tag{5}$$

The use of these parameters was based on experience and was successfully applied for single crystals of KH2PO4 in the past. Particles are classified as single crystals if the eccentricity was within 0.4 to 1, and the solidity from 0.95 to 1, respectively. As a result, gas bubbles and overlapping crystals were excluded in the data evaluation. This was manually crosschecked by comparing the crystal detection results with the original images. Furthermore, crystals touching the image border were not considered in the evaluation, since incomplete objects lead to erroneous size calculations. More details about the algorithm are reported in the literature [69].

In order to evaluate the geometry of the observed objects and to calculate meaningful distributions, it is necessary to choose a reasonable characteristic length. For slightly elongated bipyramidal crystals with a square prism body, the width of the square cross-sectional area can be used as a characteristic length, L, to describe its size. This length can be obtained by the minimal Feret's diameter, LFmin of

the projected area of the crystal, but the orientation of the crystal to the picture must be considered. The relevant orientation for the representation of the minimal Feret's diameter is given by the rotation around an axis, passing the two pyramid tips along the elongated direction of the crystal. Imaging a rotation around this axis, while constantly measuring the minimal Feret's diameter, gives values between a minimum and a maximum value, *<sup>L</sup>* and <sup>√</sup> 2*L* for *LFmin*. Assuming that the orientation of the particles is normally distributed, for the probability of all rotations between the two extreme values, an arithmetic mean *L*<sup>1</sup> can be described according to:

$$L \approx L\_1 = \frac{2 \, L\_{\text{Fwin}}}{1 + \sqrt{2}} \tag{6}$$

Based on this averaged crystal width of the square prism body, the distributions can be compared with the sieving analysis, where *L*<sup>1</sup> is measured. There are advanced methods for the correction of the crystal orientation reported in the literature [36], but for the sake of simplicity and computational effort, this approach was chosen.

The single crystals detected and measured by the image analysis were sorted in 400 size classes between 1 and 2000 μm, based on their corrected crystal size, and normalized by the class width, giving the number distribution, *f*(*L*). Normalization by the integral *fj*(*L*)*dL* yields the density distribution *qj* of dimension *j*:

$$q\_{\bar{j}} = \frac{f \bar{j}(L)}{\int f\_{\bar{j}}(L) dL} \tag{7}$$

Additionally, the percentiles, *p*, were utilized for the comparison of the online microscope and the shadowgraphic probe's results according to:

$$Q\_{\dot{j}}(L\_p) = \int\_0^{Lp} q\_{\dot{j}}(L) dL = p \tag{8}$$

The results were depicted and evaluated in terms of number distribution (*j* = 0) and mass distribution (*j* = 3), mainly, but other characteristic values of distributions can be used, as well [70,71].

Thiamin hydrochloride crystals were characterized utilizing the same algorithm, but without any correction of the Feret's diameter for the orientation. The minimal and maximal Feret's diameter were interpreted as the width and the length of the needles.

Further, for both substance systems an optical density was calculated based on the acquired and binarized images of the shadowgraphic probe and the QICPIC. For this purpose, the number of all black pixels in an image was divided by its resolution. This ratio was used in the following, called optical suspension density, and helps to interpret the results.
