# Deep Learning-Based Algorithms for Real-Time Lung Ultrasound Assisted Diagnosis
## 2 Methods
### Dataset
#### 2.2.2 Neural Network Output Data
On the other hand, the auxiliary image filtered by the proposed method is very suitable for a simple threshold detection because of its stepped nature. This first approximation does not take into account that a bright line has to be seen in the image to be considered part of the pleura line. Then, the \(P_{n}\) indexes are used as the center of a vertical window with \(W\) samples, where to look for the maximum amplitude of the original image. If this amplitude is larger than a global threshold \(T\), it is considered that the pleura is present in the window. Then, a \(-3\) dB signal drop criteria is used to find the high amplitude zone around the maximum, and those pixels are labeled as belonging to the pleura in a binary mask called \(M\). The mathematical formulation of this part of the algorithm is as follows:  
\[M_{i}(m,n)=\left\{ \begin{array}{cc}1,&if\ b_{i}(m,n)\geq A_{max}(m)\cdot 10^{ -\frac{3}{20}}\ ;&for\ n\in\left[\bar{P}_{j}-W,\ \ \bar{P}_{j}+W\right]\\ &0,&other\end{array} \right. \tag{6}\]  
Keeping the previous nomenclature, this condition checks if the amplitude at position (\(m\),\(n\)) remains within 3 dB of the maximum amplitude at \(\bar{P}_{j}\)\((A_{max})\), which corresponds to an approximate 29% drop in amplitude. If this condition is met, the pixel is considered part of the pleura and is marked as 1 in the binary mask. Otherwise, it is marked as 0. For this particular dataset, the approximation is applied in a searching window \(W=20\) samples around the pleura maximum amplitude identified in each scan line, but \(W\) should be adjusted according to the image resolution to include a region of about 6 mm around the pleura. Finally, morphological opening and closing filters sized at 3 \(\times\) 3 are applied to refine and smooth the pleura labeling mask (Figure 5c), eliminating outliers and giving a more precise representation of the higher amplitude line. For each video, a set of \(K\)-\(L\) pleura binary mask images are generated, to be used during the training process of the network. Figure 6 summarizes the workflow for the pleural line automatic annotation algorithm. Figure 5: Post-processing adjustment of automatic pleural annotation. (**a**) B-scan image; (**b**) initial pleural annotation approximation; (**c**) final pleura annotation. Figure 6: Automatic pleural line annotation flowchart. A-Line Labelling  
In case of A-lines, the developed algorithm detects these patterns as echoes of the pleura occurring at depths that are multiples of the probe-to-pleura distance. A search window \(W\)\([w_{1},w_{2}]\) is applied at those depths to find signal peaks that cross a threshold, and then verify their validity by comparing with the average amplitude in consecutive lines:  
\[a_{j}=\arg\max_{x\in[w_{1},w_{2}]}A_{j}(x) \tag{7}\]  
where \(a_{j}\) corresponds to the index in the A-scan signal \(A_{j}\) where the maximum amplitude is located within the window \([w_{1},w_{2}]\), which corresponds with an initial guess of the A-Line position. As in the case of the pleura line, to define the ground truth mask, a \(-3\) db signal drop criteria equivalent to the Formula (6) is used, followed by the application of opening and closing morphological filters sized at \(3\times 3\) to refine the mask and eliminating outliers. Figure 7 summarizes the workflow for the A-lines automatic annotation algorithm. B-Lines Labelling  
The approach employed to recognize these pneumonia indicators involves fitting each A-scan line \(A_{j}\) within the image to a linear function \(y(x)\) that initiates from the identified pleural line representing the amplitude of the signal at a depth \(x\):  
\[y(x)=m\cdot x+d \tag{8}\]  
where \(m\) is the slope and \(d\) is the intercept. Then, several thresholds are established to confirm the detection of the B-line based on a maximum slope \(S_{th}\), standard deviation \(\sigma_{th}\), and average amplitude of the signal \(A_{avg\;th}\) after the pleural line detected.