# Tip Estimation Method in Phantoms for Curved Needle Using 2D Transverse Ultrasound Images
## 2 Materials and Methods
### Tip Estimation  
Before tip estimation, 2D points should be transformed into 3D points based on the relationship of each frame. The relationship among the reference frame, probe frame, marker frame, and image frame are specified in Figure 6.  
As shown in Figure 6, the image has one plane with 2 axes (axis x and axis y) and axis z is vertical to the image. Moreover, the probe has the same frame with image, except that the probe frame is designed in millimeters and the image frame is set in pixels. Equation (9) implies the transformation from image to reference:  
\[Point_{1}=T_{marker}^{ref}\times T_{probe}^{marker}\times T_{image}^{probe} \times Point_{2} \tag{11}\]  
where \(Point_{1}\) and \(Point_{2}\) are the points on the reference frame and image frame, respectively, \(T_{marker}^{ref}\) is the transformation from the reference frame to the marker frame, \(T_{probe}^{marker}\) is the transformation from the marker frame to the probe frame, \(T_{image}^{probe}\) is the transformation from the probe frame to the image frame. Through this transformation, the needle position in the image can be directly re-defined in the reference frame for the needle tracking and curve fitting.  
The tip estimation has two steps: curve fitting and tip estimation. In this study, the third-order curve line is used for the shape construction where the equations can be written as:  
\[f(x)=\sum_{k=0}^{3}a_{k}x^{k}, \tag{12}\]  
\[g(x)=\sum_{k=0}^{3}b_{k}x^{k}, \tag{13}\]  
where \(f(x)\) and \(g(x)\) are the equations to fit the line along the x, which is the axis with the same direction of the insertion. \((a_{0},a_{1},a_{2},a_{3})\) and \((b_{0},b_{1},b_{2},b_{3})\) are the free parameters of the needle shape model.  
After sample points of the inflected needle have been obtained, the least-square curve fitting method will be used to fit these points as a cubic line. The target functions to fit the cubic line can be defined as follows:  
\[F(a_{0},a_{1},a_{2},a_{3})=\min\sum_{i=1}^{n}(f(x_{i})-y_{i})^{2}=\min\sum_{i=1 }^{n}(\sum_{k=0}^{3}a_{k}x_{i}^{k}-y_{i})^{2}, \tag{14}\]  
\[G(b_{0},b_{1},b_{2},b_{3})=\min\sum_{i=1}^{n}(g(x_{i})-z_{i})^{2}=\min\sum_{i=1 }^{n}(\sum_{k=0}^{3}b_{k}x_{i}^{k}-z_{i})^{2}, \tag{15}\]  
Figure 6: The relationship of the frames.  
where \(n\) is the number of the points \((n\geq 4)\) and \((x_{i},y_{i},z_{i})\) is the position of point \(i\). By applying the \(l_{2}\) norm minimization in the two-dimensional Euclidean space, it can be formulated as:  
\[\underset{t\in R}{\arg\min}\,\|X\mathbf{a}-Y\|_{2}, \tag{16}\]  
where \(\mathbf{a}=[a_{0},a_{1},a_{2},a_{3}]^{\prime}\), \(Y=[y_{1},y_{2},\ldots,y_{n}]^{\prime}\) and \(X\) can be written as:  
\[X=\begin{bmatrix}1&x_{1}&{x_{1}}^{2}&{x_{1}}^{3}\\ 1&x_{2}&{x_{2}}^{2}&{x_{2}}^{3}\\ \vdots&\vdots&\vdots&\vdots\\ 1&x_{n}&{x_{n}}^{2}&{x_{n}}^{3}\end{bmatrix}. \tag{17}\]  
The solution can be estimated as follows:  
\[\mathbf{a}=\left(X^{T}X\right)^{-1}X^{T}Y. \tag{18}\]  
From this solution, \(f(x)\) and \(g(x)\) can be obtained to construct needle shape. The tip position can then be estimated by the following optimum solutions based on the length of the needle:  
\[\begin{split}\min&\|\int_{tail_{x}}^{tip_{x}}\sqrt{1+f^{ \prime}(x)^{2}+g^{\prime}(x)^{2}}dx-L\|_{2},\\ \text{s.t.}&tip_{x}>tail_{x}\end{split} \tag{19}\]  
where \(tail_{x}\) is the measured value of the tail position from the optical tracker, \(tip_{x}\) is the expected value of the tip position in axis \(x\), \(L\) is the length of the needle.