# Accurate Needle Localization in the Image Frames of Ultrasound Videos
## 2 The Proposed Method
### Phase I: Generating the QUS Image
#### 2.1.1 Features Extraction  
The ultrasound image is processed to extract three feature groups that characterize the pixels associated with the needle. These feature groups are the speckle variations feature [34], the local phase feature [35], and the GLCM texture features [36]. Below is a summary of the three feature groups. **The speckle variations feature**:  
Needle insertion in the tissue induces variations in the ultrasound speckle patterns of the image frames of the ultrasound video [37; 38]. These variations are attributed to the fact that needle insertion leads to movements and deformations in the tissue along the insertion direction of the needle. The speckle variations feature is used to quantify the variations in ultrasound speckle patterns that are induced around the inserted needle. The speckle variations feature is computed using the subpixel motion estimation algorithm [39]. This algorithm tracks the speckle pattern variations between the current image frame and the subsequent image frame. The subpixel motion estimation algorithm is composed of two stages. In the first stage, a block-matching algorithm [40] is employed to obtain a coarse estimate of the speckle pattern variations between the two image frames. In the second stage, the coarse estimation of the speckle pattern variations is refined using an optical flow algorithm [41]. Figure 1a,b presents two ultrasound images acquired at a given image frame and the subsequent image frame. Figure 1c shows the speckle variations feature that is obtained by applying the subpixel motion estimation algorithm on these two images. **The local phase feature**:  
The local phase feature is computed using the phase congruency (PC) edge detection technique proposed by [PERSON] [35]. The PC provides an intensity-invariant detection of the edges that are aligned along a predefined set of orientations. The PC is calculated as described in [42]. In particular, the ultrasound image is filtered using a group of multi-scale log-Gabor filters. Each filter is applied independently along all predefined orientations. After applying the filters, the PC is calculated using Equation (1):  
\[PC(x,y)=\frac{\sum_{o=1}^{O}\sum_{s=1}^{S}\Bigl{(}W_{o}(x,y)\left|F_{so}(x,y) \cdot\Delta\Gamma_{so}(x,y)-\gamma_{o}\right|\Bigr{)}}{\sum_{o=1}^{O}\sum_{s=1 }^{S}\Bigl{(}F_{so}(x,y)+\varsigma\Bigr{)}} \tag{1}\]  
In the above equation, \(O\) is the number of orientations, \(S\) is the number of log-Gabor filter scales, \(W_{o}(x,y)\) is the weighting function employed for orientation \(o\), \(F_{so}(x,y)\) is the filter output at scale \(s\) and orientation \(o\), \(\Delta\Gamma_{so}(x,y)\) is the phase deviation at scale \(s\) andorientation \(o\), \(\gamma_{o}\) is the noise compensation term employed for orientation \(o\), and \(\varsigma\) is a small scalar that prevents the division by 0. The edges associated with the needle are detected by configuring the PC to compute the edges that are close to the needle angle, denoted as \(\Theta\). However, the value of \(\Theta\) in the first image frame of the ultrasound video is not known in advance. Therefore, the operator is requested to provide an initial estimation of \(\Theta\) for the first image frame. In the subsequent image frames of the ultrasound video, the initial estimation of \(\Theta\) is set to match the needle angle that is computed for the previous image frame, as described in Section 2.3. After obtaining the initial estimation of \(\Theta\), the PC is configured to detect the edges within the angle range \(\hat{\Theta}-20^{\circ}\) to \(\hat{\Theta}+20^{\circ}\), incrementing by \(5^{\circ}\), where \(\hat{\Theta}\) is the initial estimation of the needle angle. Figure 1d shows the local phase feature that is computed for the ultrasound image presented in Figure 1a. **The GLCM texture features**:  
The GLCM [36] quantifies the gray-level statistics between pairs of pixels at a given angle and offset. The angle specifies the direction in which the pixels are analyzed and the offset specifies the distance between pixels.