Lung images often have the characteristics of strong noise, uneven grayscale distribution, and complex pathological structures, which makes lung image segmentation a challenging task. To solve this problems, this paper proposes an initial lung mask extraction algorithm that combines threshold and gradient. The gradient used in the algorithm is obtained by the time series feature extraction method based on differential memory (TFDM), which is obtained by the grayscale threshold and image grayscale features. At the same time, we also proposed a lung contour repair algorithm based on the improved convex hull method to solve the contour loss caused by solid nodules and other lesions. Experimental results show that on the COVID-19 CT segmentation dataset, the advanced lung segmentation algorithm proposed in this article achieves better segmentation results and greatly improves the consistency and accuracy of lung segmentation. Our method can obtain more lung information, resulting in ideal segmentation effects with improved accuracy and robustness.