Railway plug defects impact the safety of a railway system. To detect railway plug defects, we establish the framework of a visual inspection system (VIS), which is the first system that can perform railway plug inspection automatically and intelligently. Using the idea of change detection, the framework includes three algorithm modules, which are named the object location, image alignment and similarity measurement modules. After the image acquisition system captures a rail image as the input, the three algorithm modules process the image in order. First, in the object location module, a deep convolutional neural network is used to perform plug location. Second, in the image alignment module, a simple and fast method is designed to align key images using histogram of oriented gradients features. Third, in the similarity measurement module, the χ2 distance is used to compute the similarity between the two plug regions in an inspection image and in an aligned ground-truth image. The results of the similarity measurement are sorted when all inspection images are processed. Therefore, the inspection images with smaller similarity values are ranked higher and the plugs in the images have larger probabilities of defects. The framework has passed the practice tests, and the visual inspection system using this framework has already been authorized by the China Railway Corporation and will be equipped in many inspection trains belonging to local railway corporations.