# Deep Learning-Based Algorithms for Real-Time Lung Ultrasound Assisted Diagnosis
## 2 Methods
### Dataset
#### 2.2.2 Neural Network Output Data  
Labelling Tools  
One of the limitations of the used dataset [24] is that it was labeled by an expert physician at video level, while for training a segmentation network, it must be labeled at frame level. While asking a physician to label such a large dataset frame-by-frame is usually impractical, a semi-automated algorithm was developed for this task, based on the initial label of the presence of each artifact in the video. Depending on the type of artifact, this process is fully automated or requires to identify a key frame where the artifact is visible and manually segment it, being then automatically followed in the subsequent frames in the video. These algorithms are explained in the following subsections. Pleural Line Labelling  
One of the most important indications to identify in a lung ultrasound image is the pleura, because it defines the zone where the artifacts must be looked for. Correctly identifying the pleura helps to discard zones that do not have to be analyzed, like the  
Figure 3: Comparison between sectorial image (**a**) and B-Scan (**b**). ribs and their shadows and the muscle and fat area above it. Giving this information to the neural network could improve the results, as it will learn that the B-Lines and consolidations are located bellow the pleura, and not in other areas of the image. The algorithm for automatically segmenting the pleura is based on the fact that when the ultrasound probe remains stationary, the image above the pleura (fat and muscle) remains basically unchanged between frames, while variations in the image occur below the pleura due to the respiratory cycle. Then, by subtracting consecutive frames, an auxiliary image is formed, where the upper region is almost black and the lower part is bright. Furthermore, if several of these images are averaged, the random nature of the speckle in the lower part generates a quite homogeneous region that can be more easily distinguished from the upper region. The frontier between these regions can be considered a first approximation of the pleura line. Given a video \(V\), formed by \(K\) frames with \(B\) defined by:  
\[V=\{B_{1},B_{2},\ \ldots,\ B_{K}\} \tag{1}\]  
where  
\[B_{i}=[b_{i}(m,n)]\in\mathbb{R}^{MxN}for\ 1\leq i\leq K,\ 1\leq m\leq M\ and\ 1\leq n\leq N \tag{2}\]  
and \(b_{i}\) (\(m\),\(n\)) is the pixel intensity of image \(i\) at position (\(m\),\(n\)), the output of the proposed algorithm is:  
\[\bar{V}=\left\{\widetilde{B}_{1},\widetilde{B}_{2},\ldots,\widetilde{B}_{K- L}\right\} \tag{3}\]  
where  
\[\widetilde{B}_{i}=\frac{1}{L}\sum_{k=i}^{k=i+L-1}\lvert B_{i+1}-B_{i}\rvert \tag{4}\]  
with \(L\) being the length of the averaging filter. Figure 4 shows an example output of the algorithm. On the left is the original \(B_{i}\) image of a frame, and on the right is its filtered version \(V_{i}\), showing the two formerly mentioned dark and bright zones. For detecting their boundary, a dynamic threshold was applied to each vertical line of the filtered image, calculated from the average amplitude of the upper part of the image:  
\[\widetilde{P}_{j}=min\big{\{}i\ \lvert\ A_{j}(i)>th_{j}\big{\}} \tag{5}\]  
where \(A_{j}\) is the vertical line of the filtered image at column \(j\), \(\widetilde{P}_{j}\) is the vertical index to the pleura guess for that line, and \(th_{j}\) the applied threshold. Figure 4b shows, with green dots, an example of this set of initial pleura raw guess points \(\widetilde{P}_{n}\), which are then used to fit a second order polynomial to obtain a smooth representation \(P_{n}\) of the initial guess (red line in Figure 4b). Figure 4: First pleura approximation example. (**a**) original B-scan image; (**b**) filtered image. It is worth mentioning that directly applying a threshold to the original image (Figure 4a) is very prone to misdetections, as other horizontal bright lines in the upper region of the image are present, with pixel intensity values even larger than those of the pleura.