# Tip Estimation Method in Phantoms for Curved Needle Using 2D Transverse Ultrasound Images
## 2 Materials and Methods
### Needle Shape Tracking  
As indicated in previous researches [20; 29; 30], Kalman filter has been successfully used for tracking needle in the successive ultrasound images. In this study, the Kalman filter is used to improve the estimation of the needle location in successive frames. As shown in Figure 5, the applied Kalman filter has two processes, prediction and update. The prediction stage intends to locate the needle position previously and set the ROI (red and yellow square in Figure 5) to find the needle precisely with a small window, which is supposed to reduce the computation. The update stage is the result of the needle position after the measurement from the histogram method. Figure 4: Two cases may generate the errors: (**a**) the comet tail of needle with binary method process, histogram method process and the histogram of ROI; (**b**) the poor reflection of the needle with histogram method process and the histogram of ROI. The state prediction \(\hat{t}_{i}\) intends to represent the prediction state of the transverse needle center position \((x,y,z)\) in the reference frame with the change of the needle position \((\triangle x,\triangle y,\triangle z)\) at sample \(i\) according to the state t. \((\triangle x,\triangle y,\triangle z)\) are the difference between the previous needle position and the current needle position. \(t_{i}\) is the result from the previous iteration, which is as follows:  
\[t_{i}= \begin{bmatrix}x_{i}\\ y_{i}\\ z_{i}\\ \triangle x_{i}\\ \triangle y_{i}\\ \triangle z_{i}\end{bmatrix}  \tag{2}\]  
where \(\triangle x_{1}\) and \(\triangle y_{1}\) are set to be 0, while \(\triangle z_{1}\) is equal to the scan interval. The prediction equations are as follows:  
\[\hat{t}_{i}=At_{i-1}, \tag{3}\]  
\[\hat{P}_{i}=AP_{i-1}A^{T}+Q. \tag{4}\]  
The measurement update equations are as follows:  
\[K_{i}=\hat{P}_{i}H^{T}(H\hat{P}_{i}H^{T}+R)^{-1}, \tag{5}\]  
Figure 5: The two steps of the Kalman filter. As the next US image is acquired, the previous state \((x_{previous},y_{previous},z_{previous},\triangle x_{previous},\triangle y_{ previous},\triangle z_{previous})\) is used to predict the needle position \((x_{prediction},y_{prediction},z_{prediction}\), which then will be transformed to \((I_{x_{prediction}},I_{y_{prediction}})\) in the image as the center of ROI. The yellow square is the ROI corresponding to \((I_{x_{prediction}},I_{y_{prediction}})\) and the red one is the update step in KF by using the measurement data from needle detection to locate the needle with its center \((I_{x_{update}},I_{y_{update}})\) as the needle position. Finally, the measurement state \((x_{m},y_{m},z_{m},\triangle x_{m},\triangle y_{m},\triangle z_{m})\) and the current state \((x_{c},y_{c},z_{c},\triangle x_{c},\triangle y_{c},\triangle z_{c})\) can be obtained. \[t_{i}=\hat{t}_{i}+K_{i}(m_{i}-H\hat{t}_{i}), \tag{6}\]  
\[P_{i}=(I-K_{i}H)\hat{P}_{i}, \tag{7}\]  
where A, H, R, and Q are as follows:  
\[A= \begin{bmatrix}1&0&0&1&0&0\\ 0&1&0&0&1&0\\ 0&0&1&0&0&1\\ 0&0&0&1&0&0\\ 0&0&0&0&1&0\\ 0&0&0&0&0&1\end{bmatrix} , \tag{8}\]  
\[H=\left[I_{6\times 6}\right],R=Q=10^{-6}\times\left[I_{6\times 6}\right]. \tag{9}\]  
A is the state transition matrix, H is the measurement matrix. \(\hat{P}_{i}\) and \(P_{i}\) are the priori and posteriori estimate error covariance, and R and Q are the measurement error covariance and processing error covariance, respectively. \(K_{i}\) is the Kalman gain at sample i. \(m_{i}\) is the measurement state from the needle detection. The 3D prediction position \((x_{prediction},y_{prediction},z_{prediction})\) is obtained from the previous state. Before needle detection in the current US image, the 3D prediction position should be transformed on the image plane frame as 2D position \((I_{x\_prediction},I_{y\_prediction})\). After the update, the needle position \((I_{x\_update},I_{y\_update})\) in the image will be transformed into the 3D position \((x_{m},y_{m},z_{m})\).