title: OpenCV python Stamp filter photoshop
body: <p>I am new to opencv. I have multiple images. One of sample image as shown below at top left corner. Basically I want to separate background and foreground so that edges are clear and I can detect contours properly. </p>
  
  <p>I have tried many filter and of course thresholds using various parameters. </p>
  
  <p><a href="https://i.stack.imgur.com/IbOEW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IbOEW.jpg" alt="enter image description here"></a></p>
  
  <p>Finally when I was looking on photoshop filters gallery I noticed a filter called Stamp which is giving me desired result(top-right corner). It makes edges clear and I guess use some amount of blur to soft corners. </p>
  
  <p>I am not sure how I can obtain same operation as photoshop's stamp filter using python CV2? </p>
  
  <p>Any help or suggestions will be grateful. </p>
  
  <p><strong>Original Untouched Image</strong></p>
  
  <p><a href="https://i.stack.imgur.com/cQMgT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cQMgT.png" alt="enter image description here"></a></p>
  
  <p>Attempt 1: -- Code</p>
  
  <pre><code>import cv2
  import numpy as np
  from matplotlib import pyplot as plt
  
  input_img = cv2.imread('images/Tas/t3.bmp')
  desired_img = cv2.imread('images/stamp.jpg')
  
  # gray scale
  gray = cv2.cvtColor(input_img, cv2.COLOR_BGR2GRAY)
  
  kernel = np.ones((3,3),np.uint8)
  
  thresh1 = cv2.threshold(input_img,80,255,cv2.THRESH_BINARY)[1]
  erosion1 = cv2.erode(thresh1,kernel,iterations = 1)
  dilation1 = cv2.dilate(erosion1,kernel,iterations = 1)
  
  thresh2 = cv2.threshold(input_img,120,255,cv2.THRESH_BINARY)[1]
  erosion2 = cv2.erode(thresh2,kernel,iterations = 1)
  dilation2 = cv2.dilate(erosion2,kernel,iterations = 1)
  
  titles = ['Original', 'Desired','thresh1', 'erosion1','dilation1','thresh2','erosion2','dilation2']
  images = [input_img, desired_img, thresh1, erosion1,dilation1, thresh2,erosion2, dilation2]
  for i in xrange(8):
    plt.subplot(2,4,i+1),plt.imshow(images[i])
    plt.title(titles[i])
    plt.xticks([]),plt.yticks([])
  
  plt.show()
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/hY2R2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hY2R2.png" alt="enter image description here"></a></p>