Lung segmentation, a prerequisite step of lung disease detection in computer‐aided diagnosis system, is a challenging task because of noises, complex structures, as well as large individual differences of lung CT scans. Here, an automatic algorithm for segmenting lungs from thoracic CT images accurately is presented. This scheme consists of three principal steps: image preprocessing, lung extracting and contour correcting. To cope with inhomogeneous intensities of CT images, a novel preprocessing approach based on empirical mode decomposition and bilateral filter is proposed, which has abilities of denoising, smoothing and edge keeping. Lung region is then extracted with a novel gray correlation‐based clustering approach. A new lung contour correction technology is finally employed to repair the concave regions caused by pulmonary nodules, vessels and so on. Experimental results show that the preprocessing approach outperforms other methods on image denoising and smoothing. Meanwhile, the lung segmentation algorithm is tested on a group of lung CT images affected with interstitial lung diseases and achieves a high segmentation accuracy. Compared with several existing lung segmentation methods, this algorithm exhibits a better performance on lung segmentation.