title: Morphing Operation in OpenCV Python
body: <p>I have the following image bearing handwritten text and lines of the page. I want to extract to remove the lines from the image, so that only the handwritten text is left.
  I tried implementing it, using <code>opencv</code> in <code>Python</code>. But, I don't get the best results. Please help!</p>
  
  <pre><code>import numpy as np
  import cv2
  image = cv2.imread('image.jpg')
  gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
  (gray,50,150,apertureSize = 3)
  cv2.imwrite('edges-50-150.jpg',edges)
  minLineLength=100
  lines = cv2.HoughLinesP(image=edges,rho=1,theta=np.pi/180, threshold=100,lines=np.array([]), minLineLength=minLineLength,maxLineGap=80)
  a,b,c = lines.shape
  for i in range(a):
      x = lines[i][0][0] - lines [i][0][2]
      y = lines[i][0][1] - lines [i][0][3]
      if x!= 0:
          if abs(y/x) &lt;1:
              cv2.line(gray, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (255, 255, 255), 1, cv2.LINE_AA)
  se = cv2.getStructuringElement(cv2.MORPH_ELLIPSE , (3,3))
  gray = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, se)
  cv2.imwrite('houghlines.jpg', gray)
  cv2.imwrite('another.png', gray)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/rzu5I.jpg" alt="Image being tested on"></p>
  
  <p><img src="https://i.stack.imgur.com/4VB77.png" alt="Results I get with the code"></p>