title: How to remove background noise while performing OpenCV Image subtraction?
body: <p>I have two images one is the document image and the other image is the template image. </p>
  
  <p><a href="https://i.stack.imgur.com/AGp6B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AGp6B.png" alt="Document Image"></a></p>
  
  <p><a href="https://i.stack.imgur.com/6xxyZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6xxyZ.png" alt="Template Image"></a></p>
  
  <p>I am performing OpenCV image subtraction between document image and template image.</p>
  
  <pre><code>from matplotlib import pyplot as plt
  import numpy as np
  import cv2
  template_img = cv2.imread('data_3/template.png')
  document_img = cv2.imread('data_3/document.png')
  result_img = cv2.subtract(template_img,document_img)
  plt.imshow(result_img)
  plt.title('Result Image')
  plt.show()
  </code></pre>
  
  <p>The Output of the above Program:</p>
  
  <p><a href="https://i.stack.imgur.com/7rUgP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7rUgP.png" alt="enter image description here"></a></p>
  
  <p>Here the background noise is Apt.no. OpenCV image subtraction has not performed well. </p>
  
  <p>One thing I notice why the image subtraction does not perform well because the quality of both images is not the same. Is there any way to remove the background noise that occurred during image subtraction?</p>