# An Efficient Automatic Midsagittal Plane Extraction in Brain MRI
## 2 Materials and Methods
### Fitting of Plane in Three Dimensions
(**a**) Selected slices based on semi-axes, and (**b**) extracted elliptical area from slices. The midline (principal axis) on each elliptical area slice is extracted using PCA as described in the preceding Section 2.2.2. An array \(A_{r,s}\) is formed from the location coordinates of three points (top, center, and bottom) on each midline (Figure 6f) as:  
\[A_{r,s}=\left[ \begin{array}{cc}x_{r,s}&y_{r,s}&z_{r}.1_{s}\end{array} \right]_{ rs\times 3}\qquad r=1,2,\ldots,N. \tag{26}\]  
where \(r\) denotes the \(r\)th brain slice, \(s\) is the number of points considered on each midline, \(1_{s}\) is a column vector (\(s\)-dimensional) with all its elements equal to one, and \(N\) is equal to the total number of slices used (automatically selected). The first column of \(A_{r,s}\) consists of \(p_{r}\) (offset) values of the symmetric axis and the last column contains the indices of the respective slice. According to Equation (5), this makes an overdetermined set of linear equations in \(p_{r}\) and \(Z_{r}\) as a function of plane parameters \(c\) and \(d\), as displayed in Figure 8. It can be solved by fitting a plane in 3-D Euclidean space to a set of parallel lines (midlines) having the orientation \(\theta_{r}\). 3. Fitting of Plane Using Orthogonal Regression  
Orthogonal regression is employed using PCA to fit a plane to these midlines. PCA minimizes the orthogonal distances from the data point to the fitting plane (fitting model). In the linear case, it is also known as total least squares [42]. It is appropriate when all the variables are measured with errors. In contrary to the usual regression, where the assumption is that the predictor variables are measured precisely, and only the response variables have the component of error. Singular value decomposition (\(svd\)) is used to find the principal components of the PCA. The first step is to center the location data matrix \(A_{r,s}\). This can be achieved by subtracting each data point of the matrix from its column mean. The resultant matrix is labeled as \(B\). Then, the \(svd\) of \(B\) can be expressed as:  
\[B=USV^{T} \tag{27}\]  
where \(U\) is a left-singular vector, \(S\) is a diagonal matrix of singular values, and \(V\) is a right-singular matrix. Figure 8: The relationship between the brain slice position (\(Z_{r}\)) and the symmetric axis offset (\(p_{r}\)). The illustration is adapted from [47]. The columns of \(V\) will be the required principal components. First two columns (first two principal components) of \(V\) define vectors that form a basis for the plane, and the third column (third principal component) is orthogonal to the first two principal components. The coefficients of the third principal component define the normal vector (\(n\)) of the MSP having an orientation of \(\theta_{r}\) (yaw angle). The third coefficient of the normal vector \(n\) can be exploited to estimate the roll angle \(\varphi\) using Equation (7) as:  
\[\varphi=-\tan^{-1}(c) \tag{28}\]  
where \(c\) is the third coefficient of the normal vector. Similarly, the parameter \(d\) of the MSP can be calculated by taking the scalar product of the normal vector \(n\) and the mean of \(A_{r,s}\).