# 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 within the \(T\) subset form a rectangular structure at the center of the kernel, with a length that extends across the kernel and a width equal to the needle diameter. High values of \(R_{T}\) will be obtained when the kernel is positioned along the needle axis, such that the needle pixels are covered by the \(T\) subset. In this case, the ranks of the pixels within \(T\) (i.e., the needle pixels) are expected to be higher than those of the surrounding tissue pixels covered by the \(C\) subset. The proposed needle detection kernel can be generalized to detect the needle in the ROI containing the needle in the ultrasound image, regardless of needle orientation. Particularly, the initial prediction of the needle trajectory, which is obtained as described in Section 2.2, is used to approximately estimate the needle angle \(\Theta\). The rectangular structure within the proposed needle detection kernel, which represents the \(T\) subset, is rotated to match the estimated value of \(\Theta\). For example, Figure 2(b) shows the rotated needle detection kernel when the estimated value of \(\Theta\) is equal to \(45^{\circ}\). RanT is then employed to process the ROI in the ultrasound image using the rotated needle detection kernel. The process of applying RanT is carried out based on the \(R_{T}\) coefficient, as described in [33]. Figure 2(k) shows the transformed ROI that is obtained using the customized RanT. As shown in the figure, the needle appears in the transformed ROI as a bright linear structure that can be differentiated from the surrounding tissue. The transformed ROI is then processed using RT analysis, as described in Section 2.2, to accurately localize the needle trajectory. Figure 2(l) shows the accurately localized needle trajectory overlaid on the transformed ROI. Figure 2: The (a) vertical, (b) horizontal, and (c) diagonal kernels that are used in conventional RanT transform analysis. Figure 3: The RadT kernel proposed in the current study to detect the needle when (a) the estimated value of \(\Theta\) is equal to \(0^{\circ}\) and (b) the estimated value of \(\Theta\) is equal to \(0^{\circ}\). Moreover, Figure 1m presents the accurately localized needle trajectory overlaid on the ultrasound image. After detecting the needle trajectory, the location of the needle tip along the detected trajectory is determined based on the speckle variations feature. As explained in Section 2.1.1, needle insertion leads to variations in ultrasound speckle patterns along the needle insertion axis, where these variations are detected by the speckle variations feature. The highest magnitudes of the speckle variations feature occur at the needle tip, as shown in Figure 1c. Therefore, the needle tip can be detected by identifying the location along the needle trajectory that has the highest magnitudes of the speckle variations feature. The needle tip location is identified by calculating the moving mean of the speckle variations feature magnitude along the detected needle trajectory. The point along the detected needle trajectory that has the highest mean value is identified as the needle tip. The moving mean is computed using a sliding window procedure that scans the needle trajectory starting from the needle entry point to the end of the needle trajectory. The window has a square shape, with a side length equal to two times the needle diameter. The window is iteratively shifted along the needle trajectory by a distance equal to one-tenth the needle diameter. At each window position, the mean magnitude of the speckle variations feature is calculated. The window position with the highest mean magnitude is used to identify the needle tip. Figure 1n shows the detected needle tip (presented as an orange circle) overlaid on the ultrasound image.