# Accurate Needle Localization in the Image Frames of Ultrasound Videos
## 2 The Proposed Method
### Phase II: Analyzing the QUS Image to Identify the ROI That Includes the Needle  
The pixels in the QUS image associated with the needle are expected to have high intensity values. Therefore, an initial prediction of the needle trajectory can be obtained by processing the QUS image using RT analysis. Particularly, the RT of the QUS image was calculated using integration angles between \(1^{\circ}\) and \(360^{\circ}\), incrementing by \(1^{\circ}\). The bright line cues in the QUS image appear as peaks in the sinogram computed using RT, where the heights of these peaks reflect the brightness and length of the line cues in the image plane. The longest and brightest line in the QUS image is identified by extracting the highest peak in the sinogram and projecting this peak back to the image plane using inverse RT [17]. This process provides an initial prediction of the needle trajectory. Figure 1h,i presents the initial prediction of the needle trajectory (shown as a red line) overlayed on the QUS image and the ultrasound image, respectively. The accuracy of the initial prediction of the needle trajectory might be slightly degraded since other line cues in the QUS image can overlap with the needle. Consequently, the initial prediction of the needle trajectory is used only to obtain an approximate localization of the ROI that includes the needle. This ROI is defined as a rectangular region that extends across the ultrasound image and has a central axis that aligns with the initial prediction of the needle trajectory. The width of the ROI is set to ten times the diameter of the needle. The ROI is processed as described in Section 2.3 to accurately localize the needle trajectory and tip. Figure 1j shows the ROI in the ultrasound image that includes the needle. Phase III: Analyzing the ROI That Includes the Needle to Accurately Localize the Needle Trajectory and Tip  
The process of accurately localizing the needle trajectory is performed by processing the ROI using a customized RanT [33], followed by RT analysis. RanT provides an intensity-invariant, orientation-specific approach to analyze the input image. Specifically, RanT employs a rank-based square kernel. Let \(w\) be the width of the kernel in pixels and \(N=w\times w\) be the total number of pixels within the kernel. The pixels within the kernel are split into two equal subsets, denoted as the test subset (\(T\)) and the control subset (\(C\)). These two subsets are defined based on the orientation under consideration. Figure 2 shows conventional kernels that are used to detect the image cues along the vertical, horizontal, and diagonal orientations. The pixels within the kernel are ranked based on their gray-level intensities. For each kernel, RanT coefficients can be computed for the \(T\) and \(C\) subsets as follows [33]:  
\[R_{T}=\frac{\sum_{p\in T}\pi(p)-\frac{N}{4}(\frac{N}{2}+1)}{\frac{N^{2}}{8}}-1, \tag{2}\]  
\[R_{C}=-R_{T} \tag{3}\]  
In Equations (2) and (3), \(R_{T}\) and \(R_{C}\) are the RanT coefficients of the \(T\) and \(C\) subsets, respectively. \(\sum_{p\in T}\pi(p)\) represents the sum of the ranks of the pixels located within \(T\)Assume the input image contains a horizontal edge, in which the bright side is located below the dark side. In this case, the horizontal kernel can be applied to the image to detect the edge. When the kernel is placed on the horizontal edge, the value of \(R_{T}\) will be maximized since the ranks of the pixels within \(T\) are higher compared to those within \(C\). Conversely, if the bright side is located above the dark side, then the value of \(R_{C}\) will be maximized since the ranks of the pixels within \(C\) are higher compared to those within \(T\). In the current study, a customized RadT kernel is proposed to detect the needle trajectory. Figure 2(a) illustrates the structure of the proposed RadT kernel that can be used to detect the needle trajectory when the needle is aligned along the horizontal direction. The needle detection kernel has a square shape with a width equal to twice the needle diameter.