To achieve an automatic and accurate segmentation of lungs and improve the clinical efficiency of computer‐aided diagnosis, the authors present a lung segmentation algorithm based on the random forest method and a multi‐scale edge detection technique. The algorithm carries a first step of lung region extraction and a second step of lung nodule segmentation. By combining texture information, the improved superpixel generation method can better deal with initial segmentation on lung computed tomography images with inhomogeneous intensity. Then, the lung region is further extracted by using the random forest classifier on the superpixel features, and the lung contours are corrected with a proposed circle tracing technique. Finally, the segmentation is further refined by employing a multi‐scale edge detection technique, which enables their method to detect suspicious nodules with various intensities and sizes adaptively. The effectiveness of the proposed approach is demonstrated on a group of datasets by comparing with the corresponding ground truths as well as the classical algorithms. Experimental results show that the proposed method has a higher precision than the compared algorithms in a fully automatic fashion.