# 2D/3D Multimode Medical Image Alignment Based on Spatial Histograms
## 2 Materials and Methods
The second-order spatial histogram of image \(I\) can be expressed by Formula (1) by dividing the histogram interval according to the value \(v\). \[h_{I}{}^{(2)}(b)=\langle n_{b},\mu_{b},\sum_{b}\rangle,b=1,\cdots,B \tag{2}\]  
\[h_{I}{}^{(0)}(b)=n_{b},b=1,\cdots,B \tag{3}\]  
where \(B\) represents the number of bins in the spatial histogram, \(n_{b}\) is the number of \(b\) pixels belonging to the bin, and \(\mu_{b}\) and \(\sum_{b}\) are the coordinate mean value and coordinate variance of \(b\) pixels in the bin, respectively. Function (3) is a simple histogram of an image. By comparing Function (2) with Function (3), the spatial histogram extracts the mean and variance of pixel coordinates while extracting frequency information, which is beneficial for calculating the similarity between the two histograms. The similarity between two spatial histograms can be expressed in the form of a weighted sum, as shown in Formula (4):  
\[\rho\big{(}h,h^{\prime}\big{)}=\sum_{b=1}^{B}\psi_{b}\rho_{n}\big{(}n_{b},h_{b }{}^{\prime}\big{)} \tag{4}\]  
where \(\rho_{n}\) is the distance measure, which is used to measure the similarity between the same bin in the histograms \(h\) and \(h^{\prime}\), while \(\psi_{b}\) is the weighted coefficient. When calculating the similarity between simple histograms, \(\psi_{b}=1\); \(\rho(h,h^{\prime})\) degenerates to the common histogram similarity calculation method. For the second-order spatial histogram, \(\psi_{b}\) is determined by the product of two probability distributions related to the coordinate mean value and coordinate variance--that is, the Gaussian distribution described by \(\mu_{b}\) obeying \(\big{(}\mu_{b},\sum_{b}\big{)}\). The Gaussian distribution described by \(\mu_{b}{}^{\prime}\) obeying \((\mu_{b},\sum_{b})\), \(\psi_{b}\) is shown in Formula (5):  
\[\psi_{b}=\eta\ exp\bigg{\{}-\frac{1}{2}\big{(}\mu_{b}-\mu_{b}{}^{\prime}\big{)} ^{T}\overleftarrow{\sum_{b}}^{-1}\big{(}\mu_{b}-\mu_{b}{}^{\prime}\big{)} \bigg{\}} \tag{5}\]  
\[\sum_{b}^{-1}=\sum_{b}{}^{-1}+\big{(}\sum_{b}{}^{\prime}\big{)}^{-1} \tag{6}\]  
\[\eta=\frac{1}{2\pi|\sum_{b}|^{\frac{1}{2}}}-\frac{1}{2\pi|\sum_{b}{}^{\prime} |^{\frac{1}{2}}} \tag{7}\]  
where \(\eta\) is the Gaussian normalization constant, and its definition is shown in Formula (7). The exponential part in Formula (5) is the average of the Mahalanobis distance between \(\mu_{b}\) and \(\mu_{b}{}^{\prime}\), as well as between \(\mu_{b}{}^{\prime}\) and \(\mu_{b}\). A spatial histogram can be considered to be a geometric model. It makes up for the gap between the typical histogram and more specific models (such as translation, rotation, affine,projection, or B-spline). Like simple histograms, spatial histograms are computationally efficient and compared between corresponding image blocks. However, a spatial histogram retains some geometric information between pixels, unlike a simple histogram. More specifically, the spatial histogram captures the global positional information of pixels. We propose using a spatial histogram instead of the simple histogram to extract the statistical characteristics of image gradient direction information and gradient amplitude information, to solve the registration algorithm's problem based on the gradient direction histogram. Specifically, when constructing the weighted histogram of the reference image and the DRR image, each bin's coordinate mean value and coordinate variance in the weighted histogram of gradient directions should be calculated. The new statistical histogram is called the weighted spatial histogram of gradient directions (WSHGD). The expression is shown in Formula (8):  
\[h(d)=\langle n_{d},\mu_{d},\sum_{d}\rangle,d=0,1,\cdots,359 \tag{8}\]  
Figure 1:0  
Figure 1:1  
The WSHGD still takes gradient direction as the division basis of the histogram interval. Here, every 1 degree is a bin, for a total of 360 bins.