In order to improve detection efficiency of casting bolster and side frame of railway freight car, the method to automatically detect railway casting porosity and shrinkage cavity using watershed transformation based on X-ray digital radiography is presented. Firstly, while castings of a bolster and a side frame are scanned by 9Mev X-ray digital radiography system, the DR images are obtained. Then one of interested regions is selected in an image. Defects segmentation is implemented by using watershed transformation algorithm in this paper. Lastly, defects area and occupy rate are acquired by analyzing and computing, so that we can judge the casting quality. The experimental results show that defect regions and contours can be accurately acquired. This method has high robustness and practicality. It improves the efficiency of automated inspection of railway castings.