Cancer is one of the most serious health problems in the world. Lung Computer-Aided Diagnosis (CAD) is a potential method to accomplish a range of quantitative tasks such as early cancer and disease detection, analysis of disease progression, analysis of pulmonary function and perfusion, and automatic identification and tracking of implanted devices. For identifying the lung diseases, computed tomography (CT) scan of the thorax is widely applied in diagnose. The lung segmentation is the preprocessing step in most CAD systems. However, manually segmenting the lungs is tedious and taking lots of time for the large-sized CT databases. In this paper, we propose a novel lung segmentation technique that can determine the threshold for each CT slice in a patient stack and automatically do the lung segmentation. The accuracy is 98% when the method was tested on five patient stacks that contained 914 slices.