Lung segmentation is a prerequisite for lung cancer diagnosis with computer-aided diagnosis systems. However, correct lung segmentation is a challenging task due to image noise, diseases, different lung nodule presences, unique morphological variations, and other factors. In this study, we present a novel algorithm for lung segmentation of thoracic Computed Tomography (CT) images based on a dilated U-Net model and a multi-scale gray correlation-based approach. Lung regions were first extracted from CT images with a double dilated U-Net model for generating accurate lung contours with juxta-pleural nodules included. Then, initial nodule contours were captured using a novel multi-scale gray correlation-based segmentation approach for reducing the computational burden and improving lung segmentation accuracy in lung nodule segmenting. Finally, lung nodule contours were refined with a level set method. A collection of thoracic CT scans with nodules from two public databases are employed for algorithm testing. Experimental results show that the proposed algorithm creates an average Dice similarity coefficient of 72.14% compared with ground truth, and it also outperforms a number of existing lung segmentation techniques. The accurate lung segmentations generated by the proposed algorithm are helpful for assisting radiologists in evaluating lung nodules and subsequently developing focused treatment strategies.