# RD-SLAM: Real-Time Dense SLAM Using Gaussian Splatting
## 3 Materials and Methods
### Mapping  
RD-SLAM aims to create a coherent, high-fidelity 3D map. The 3D Gaussian scene representation is updated and optimized at each selected keyframe for stable mapping. We first use an adaptive densification strategy in the mapping thread to add new 3D Gaussians to the entire scene representation for differentiable rendering to obtain color and depth images. The updated 3D Gaussian scene representation is then optimized by minimizing the input and rendered images' color, depth, and regularization loss. Finally, anomalous 3D Gaussian is removed using the 3D Gaussian pruning strategy.  
The Gaussian densification process is closely related to the keyframe selection strategy. We use all pixels of the first frame to initialize new 3D Gaussians. For each pixel, we add a new 3D Gaussian function with the color of that pixel, centered on the spatial position of that pixel, and an opacity of 0.1. When the tracking thread uses G-ICP for position estimation, the system can simultaneously obtain the matching relationship between the current frame's spatial points and the map's spatial points. If the matched spatial points are below a certain threshold, the current frame is added as a tracking keyframe, and the unmatched spatial points are set to new Gaussians. When the current frame is detected  
Figure 4: Dual keyframe selection strategy. By dividing the keyframes into tracking and mapping keyframes, RD-SLAM can accomplish the densification strategy while guaranteeing tracking accuracy and, simultaneously, allowing the 3D Gaussian to be fully trained.  
as a mapping keyframe using the dual keyframe selection strategy, the spatial points on which the current frame matches the map are set as new 3D Gaussians.  
After 3D Gaussians splatting to the image plane, the color loss between the input color image and the rendered image is calculated. We calculated the color loss using a weighted combination of \(L_{1}\) and structural similarity index measure (SSIM) [33] losses:  
\[L_{\text{color}}=(1-\lambda)\cdot\big{|}\hat{I}-I\big{|}_{1}+\lambda\big{(}1- \text{SSIM}\big{(}\hat{I},I\big{)}\big{)}, \tag{10}\]  
where \(I\) is the original color image, and \(\hat{I}\) is the rendered color image. Deep optimization is achieved using \(L_{1}\) loss:  
\[L_{\text{depth}}=\big{|}\hat{D}-D\big{|}_{1}, \tag{11}\]  
where \(D\) is the original depth image, and \(\hat{D}\) is the rendered depth image.  
To prevent scale explosion of the 3D Gaussian and to highly elongate in the camera viewing direction, we add the regularization loss \(L_{\text{reg}}\) of the scale. It can effectively compensate for the 3D Gaussian scale distortion caused by the insufficient observation viewpoint during SLAM. We use \(L_{1}\) loss for scale optimization:  
\[L_{\text{reg}}=|\hat{S}-\overset{\sim}{S}|_{1}, \tag{12}\]  
where \(\overset{\sim}{S}\) is the average of the scale, and \(\hat{S}\) is the scale before 3D Gaussian optimization. Finally, the depth, color, and regularization loss are optimized together:  
\[L=\alpha L_{\text{depth}}+\beta L_{\text{color}}+\gamma L_{\text{reg}}, \tag{13}\]  
where \(\alpha\), \(\beta\), and \(\gamma\) are predefined hyperparameters that are weighted values of depth, color, and scale regularization loss.  
For each keyframe, we perform a fixed number of iterations. First, we iteratively compute using the current keyframe to fully optimize the 3D Gaussian for the current viewpoint. Then, the first n frames in the list of keyframes that overlap with the current keyframe so far are selected, and one of them is randomly chosen in each iteration to ensure that the whole map is fully optimized while avoiding falling into local minima. After a certain number of map iterations, some anomalous Gaussians appear due to the instability of the adaptive control of the Gaussian. We follow the pruning strategy in [18] while removing 3D Gaussians whose locations are not near the scene surface.