Image difference operation is frequently used in automated printed circuit board (PCB) inspection system as well as in many other image processing applications. During the implementation, this operation brings along the unwanted noise due to misalignment and uneven binarization. Thus, this paper proposes a method to eliminate, if possible, or to reduce as much as possible such noise during the computation of defect detection. This paper used a template PCB image and the tested PCB image as the input. Image subtraction operation will be applied between the images. The results of applying the proposed method showed a significant improvement during the real-time inspection of printed circuit boards.