It is difficult to automatically recognize defects using digital image processing methods in X-ray radiographs of lap joints made from plates of unequal thickness. The continuous change in the wall thickness of the lap joint workpiece causes very different gray levels in an X-ray background image. Furthermore, due to the shape and fixturing of the workpiece, the distribution of the weld seam in the radiograph is not vertical which results in an angle between the weld seam and the vertical direction. This makes automatic defect detection and localization difficult. In this paper, a method of X-ray image correction based on invariant moments is presented to solve the problem. In addition, a novel background removal method based on image processing is introduced to reduce the difficulty of defect recognition caused by variations in grayscale. At the same time, an automatic defect detection method combining image noise suppression, image segmentation, and mathematical morphology is adopted. The results show that the proposed method can effectively recognize the gas pores in an automatic welded lap joint of unequal thickness, making it suitable for automatic detection.