# Three-Dimensional Magnetic Inversion Based on an Adaptive Quadtree Data Compression
## 2 Methods
### Adaptive Quadtree Data Compression Algorithm  
Adaptive quadtree decomposition is an image segmentation algorithm based on uniformity detection. The segmentation scale of the data area with a large gradient change and uneven value is very small, so more data can be obtained, whereas the segmentation scale of the data region with a small gradient change and uniform value is coarse, so less data is obtained. Compared with the regular sampling method with equal intervals down-sampling, this method retains more detail and achieves the best approximation to the original data with the least amount of data.  
Figure 1 shows the decomposition diagram of the three-level quadtree model. The quadtree decomposition algorithm is used to subdivide the two-dimensional space into four regions by recursion. The first level decomposition divides the region R into four sub-blocks R\({}_{1}\), R\({}_{2}\), R\({}_{3}\) and R\({}_{4}\). In the second decomposition, the region consistency of each sub-block is judged in turn. If R\({}_{2}\) and R\({}_{3}\) meet the regional consistency standard, they are no longer decomposed while if R\({}_{1}\) and R\({}_{2}\) do not meet the regional consistency criteria, they continue to be decomposed into four sub-blocks, namely, R\({}_{1-1}\), R\({}_{1-2}\), R\({}_{1-3}\), R\({}_{1-4}\) and R\({}_{4-1}\), R\({}_{4-2}\), R\({}_{4-3}\), R\({}_{4-4}\).  
The uniformity of the data in the sub-blocks is called regional consistency. In this paper, the regional consistency standard is measured by variance, which is used to measure the magnitude and uniformity of fluctuations in the data. The larger the variance, the greater the difference in the data. Assuming that the amount of data in the segmented sub-block is \(n\times n\), the formula for calculating the variance is shown on the left side of Equation (9).  
\[\frac{1}{n^{2}-1}\sum\
olimits_{i,j=1,n}\left(f(i,j)-\overline{f}\right)^{2}<T \tag{10}\]  
where \(f(i,j)\) represents the value of the point \((i,j)\), \(1\leq i\leq n\),\(1\leq j\leq n\), and \(\overline{f}\) represents the average value of the data in the sub-block. \(T\) is the variance threshold that is used to judge whether the sub-block is uniform. The variance threshold is not fixed, and the selection of threshold affects the error between the compressed data and the original data and the data compression ratio. When the variance threshold is large, it means that more data will be discarded, and the data error will increase and the compression ratio will decrease. By drawing a profile of error and threshold and a profile of the compression ratio and threshold, the intersection of the two sections can be selected as the best threshold.  
Figure 2 shows a flowchart of the adaptive quadtree decomposition for data compression. First, given the segmentation size and variance threshold, when the sub-block size is larger than the minimum size and the variance \(T_{i}\) is greater than the given variance threshold \(T\), the segmentation is continued until all the sub-blocks meet the conditions. In this way, the data from different sub-blocks of various sizes are obtained, and the average value and the coordinates of the center point are calculated, and are then stored as a compressed matrix. The method of using the average value of all data points of a sub-block to replace all of the points in the whole sub-block is called the mean method. It is essentially a low-pass filter that filters out the high-frequency part of the data for de-noising.  
Figure 1: A three-level quadtree decomposition diagram.