THE DIAGNOSTIC OF TWO-PHASE SEPARATION PROCESS USING DIGITAL IMAGE SEGMENTATION ALGORITHMS

The project aimed to develop and implement algorithms to diagnose the phase separation process based on digital images. The image processing techniques and various numerical methods for interpolation and integration were used to identify the process state. The swirl’s volume and diameters at its three different levels can be determined on-line. A consistent diagnostic signal is produced and can be used by the control unit. The program was written in Python using the OpenCV library that allows the analysis of digital images. The article presents the developed procedure that provides reliable results despite the poor quality of the input source video stream. The complete procedure was described with the results’ presentation and discussion at each step.


Introduction
The rapid progress in the development of computer systems has a positive impact on the diagnosis and control instruments for industrial processes [2,6]. Thanks to this, the production may be automated and achieve still greater efficiency and better quality of the final products. An example of this is the phase separation process. It is required to observe and adjust the flow of components to obtain the maximum efficiency. Localization of the sensors inside the chamber (reactor) in which the phase separation takes place, could have a negative effect on the obtained results and interfere with the process. Therefore, non-invasive monitoring is required. To meet such requirements, the video observation with image processing techniques have been applied.
In the case of this project, the process of gas-liquid separation has been observed. The diagnostic output signals of the algorithm are the diameters (taken on three different levels) and the area of the swirl. This information is valuable in further processing to correctly set the phase separation before entering the next part of the pipeline.

Phases separation process and research facility
The phase separation process is a method to separate all or part of the components from each other. The phase separation is when the mixtures are isolated, whose phases are not in the same state of matter (e.g., liquid or gas). This type of separation process is most common in the oil industry, where oil is extracted together with gas. Separation of these elements is required for transport and further processing [8].
Separation is not only used to isolate unwanted gas. In the case of natural gas extraction, removal of unwanted fluids (most often water or seawater) is required. Neglecting this stage may cause plugs occurring in the transport pipelines or increase the corrosion. At the Institute of Applied Computer Science, the phase separator research facility has been built (see Fig. 1). It is a kind of Gas-Liquid Cylindrical Cyclone (GLCC). GLCC is a cheap and straightforward type of separator. Its construction consists of a vertical pipe with the horizontally oriented inlet (bottom part) and outlets for just separated phases (upper part). The pump provides the gas-liquid mixture through the inlet to the main tank. The particular location of the inlet creates a swirl with a rotation speed that generates a centrifugal force stronger than the gravity. In the result of the combined forces, liquid is pushed to the cyclone sides and towards the outlet, while the gas concentrates inside the swirl [4].

Image capturing
A non-invasive measurement method was used to observe the process. It is highly relevant not to interfere with the process behavior. The camera with a resolution of 1280 x 720 pixels and the ability to capture 100 frames per second was used. The camera lens was set to have in a frame only the cyclone. From the collected video streams, 19 images were selected to analyze the most specific types of swirl (Fig. 2), which are numbered for further references and processing.

Image processing and analysis
Image processing is widely applied in numerous computer diagnostic systems based on digital images. This approach allows automation in the monitoring (i.e., find shapes or features). The most common involved technics are segmentation algorithms. In a frame of this project, the swirl was issued from the background (Fig. 3) [5]. In addition, the image was converted from a gray image to a binary image. The thresholding operations ensured this. In Fig. 3, the complete processing schema is presented. It involves image preparation, swirl identification, and features' measurement.

Image preparation
The image preprocessing was developed. The captured frame is held as a three-dimensional matrix. The first two dimensions provide the pixel position, while the third its color level. This format is a commonly used way of image representation in the RGB color space. First, the color information and some parts of the image were removed. To get a grayscale, the arithmetic mean of the color saturation value was calculated. Next, some glares on the cyclone wall were removed. It was done by cropping the edges of the image. Similarly, the images were cropped from the bottom to remove the unformed part of the swirl with random air bubbles.

Image processing
The image segmentation [7] is a process that results in the image division into certain areas. These areas contain a set of pointspixels having similar properties due to previously used criteria. The work involves thresholding and edges detection techniques. Due to the noise in the input image, it was not decided to use the edge detection algorithm exclusively.
The swirl is brighter than the background. Unfortunately, the brightness level of the background is not uniform. Therefore, after thresholding, some light reflections and air bubbles are detected incorrectly. Some areas are misclassified, creating gaps. It is because the light source was set on one side of the cyclone and was not dispersed. As a result, the swirl was not uniformly illuminated.
The correct threshold level has a key impact on further analysis. The small value (here 60) reduces the formation of swirl's gaps in the image but simultaneously produces artifacts, which makes that it is difficult to detect the right swirl edges. Finally, the swirl becomes wider (Fig. 4). This matter is caused by the classifying part of the background as the surface of the swirl. However, setting a higher threshold level (i.e., 80) has the opposite effect. Fewer artifacts can be faced, but the gaps became too large and distort the actual swirl shape (Fig. 4 fourth image). Therefore, a medium level (70) was applied what allowed to generate a small number of defects, while reducing the size and amount of interferences. Before the edge detection, the white points that do not belong to the swirl should be removed. For this purpose, the erosion operator was used. Erosion [7] is a morphological operation used in binary images that make objects narrower. The neighborhood of each pixel is checked, and if only one of the neighboring points has a zero value, then the considered point also gets zero. Otherwise, it remains unchanged. Thanks to this, most of the artifacts were removed from the background, and the edges get smoother (Fig. 5a). Nevertheless, the swirl also became narrower as well as the gaps got larger. However, it does not have any negative impact on further analysis because the gaps will be processed in the next stages.  (Fig. 6), (c) edge filtration (Fig. 7)

Edge detection
Edge detection [7] is one of the basic techniques of image analysis. The purpose of it is to find these points where luminance changes rapidly. In scientific literature, the basic operator of edge detection is based on the Sobel operator. The principle of operation is to use a discrete central difference to obtain the intensity gradients. In this work, it was decided to develop another solution. There is no need to calculate gradients. The object identification in the image is focused on finding the value 1 in the given row and column. Next, other points have assigned value 0. Note, that in this processing, only the outer edges should be identified, but the common edge detection algorithms like Sobel would detect also the edges inside the swirl. Keeping this in mind, the first occurrence of a non-zero value in each row in the image matrix needs to be found. The principles of the proposed solution are depicted in the block diagram below (Fig. 6). The procedure depends on the considered side of the swirling edge. For this being on the left side, the algorithm analyses the raw forward and differently for edges on the right. Then, it processes backward. The edges can be found for each side separately. However, still it is possible to observe some white points which do not belong to the swirl (Fig. 5b). These are artifacts not removed by the erosion. Besides, there is an edge in the middle of the swirl that does not reflect its correct shape. In the next processing steps, this may lead to incorrect determination of the interpolation polynomial. For this reason, it was decided to design an algorithm for these points' filtration ( Fig. 7), which additionally examines the local point deviation. For two points, a vector is created. Then, the rake angle is calculated. If the value of this angle is lower than the applied criterion, the point is not rejected. This approach allowed utterly to eliminate the artifacts (see Fig. 5c). Most edge points that could cause irregularities while the interpolation, also were removed. The established procedure for swirl area identification reflects its shape and location. It is also fully controllable through a threshold criterion that can be adapted to the needs. Under better scene lighting conditions, more precise results would be expected.
The solution has been tested on a workstation equipped with a third-generation Intel Core i5 processor. The average total computation time for edge detection for a 1080x720 image was only 12 milliseconds. This gives us 83 processed images per second. The algorithm's running time will increase together with the image resolution. However, for the present conditions, it can be considered to work in real-time systems.
Moreover, the implemented algorithm has an advantage in comparison to the standard implementations of common edge detection algorithms. It works independently for both swirl sides and can be processed within separate threads what additionally can reduce the processing time. In the future, the optimization at higher resolutions, up to 8K (7680 x 4320 pixels), will be implemented based on the massive parallel computations (nVidia CUDA [3]). It would be possible to divide the image matrix to rows for each swirl side and to run all such slices on separate GPU cores.

Swirl identification
The procedure for swirl identification is as follow: 1. Determination of interpolation polynomial, 2. Calculation of two integrals to determine the swirling surface, 3. Determination of the swirl diameter at three levels.
The swirling surface, however, does not provide adequate knowledge about the process. By monitoring the process at selected levels, it is possible to estimate the swirl type. If the process is running correctly, these values should be constant.

Interpolation of the edge points
Numerical interpolation was used to obtain functions describing the swirl edges. Interpolation [1] is a method of creating new points in a range regarding the known points. The interpolation determines a function that returns known values in given points called nodes. In the considered solution, the known values are the edges points. The numerical method applied to solve this problem uses a two-dimensional Cartesian coordinate system and cannot take negative values. Therefore, the interpolation function should be in the first quarter of the coordinate system. This imposes to consider the point (0,0) in the lower-left corner of the image. Next, the numbers of image's columns can be mapped on the Y-axis, and numbers of rows on the X-axis (Fig. 8). Next, the function poly1d is called. The input argument is the polynomial coefficients vector. As a result, the interpolant can be obtained (Fig. 9) that can be joined with the source image (Fig. 10).

Calculation of the surface and diameter of the swirl
With the functions describing the edges, it is possible to calculate the surface of the swirl. Numerical integration by the Simpson method has been implemented [1]. The Simpson rule for calculating the value uses equidistant points symmetrically settled in the range [a, b]. The integration range is divided into n smaller intervals. The value n must be even. The resolutions of the digital images meet the condition of divisibility by two. Next, the areas under both functions, as integration results, can be subtracted from each other to determine the swirling surface (Fig. 11).  The three levels where the swirl diameter is going to be calculated, are in the upper, lower and middle parts of the swirl (Fig. 10). The distance between two selected points from the two interpolated edges is calculated in pixels. This is calibrated regarding the real cyclone radius that is equal to 17.9 cm. The obtained results are listed in Table 1. The values 0mm for diameter are in case of superimposition of two edges. It happens for very thin swirls.

Summary
The project aimed to develop and implement the complex procedure of image processing and analysis algorithms with the numerical methods to determine the features of the swirl in the two-phase separation process. The low quality of source input images forced to develop some new algorithms for edge detection and noise filtration. The specificity of these algorithms allows us to implement them to be run within different threads or on multi-core GPU units.
The interpolation technique was applied and verified by the superposition of the results and source images. By changing the order of the interpolation polynomial it is possible to reflect the swirl shape better. Obtained measurements of characteristic features of the separation process can now be used as an input signal to a control unit. The swirl properties were successfully determined as surface and diameters at three different levels.