The SGM algorithm was weak in matching the occluded area and parallax discontinuity area in stereo matching, and it was easy to produce more voids. To address this question, the paper proposes a parallax optimizati-on algorithm based on SGM algorithm combined with flood filling and median smoothing. The algorithm fills the missing parallax values based on the parallax values at the edges of the voids and achieves the repair of the missing parallax in the parallax map without raising a large computational effort. The proposed algorithm has also been qua-ntitatively analyzed on the Middlebury stereo matching dataset using three evaluation metrics: root mean square error (RMSE), peak signal-to-noise ratio (PSNR), and structural similarity (MSSIM). The experimental results show that the improvement and optimization of the SGM algorithm can effectively fill the voids in the parallax map and reduce the noise of the image, and the matching accuracy of parallax maps is improved by an average of 9%.