1. A method of performing ribcage segmentation in a chest image, the method comprising: classifying a top of the chest image as having lungs adjacent to the top or not adjacent to the top; segmenting the top of the ribcage, based on the result of said classifying, to obtain a top mask; and segmenting at least one outer side of the ribcage, after the top of the ribcage is segmented, by using an endpoint of the top mask as a starting point, wherein at least one of said segmenting the top of the ribcage or said segmenting at least one outer side of the ribcage comprises: obtaining a local cost image based on the chest image; and applying a dynamic programming algorithm to the local cost image.