title: Extract horizontal and vertical lines from an image
body: <p>I want to extract horizontal and vertical lines in 2 masks for the attached image.</p>
  
  <p>I have tried morphological operations to do this, </p>
  
  <pre><code>horizontalStructure = cv.getStructuringElement(cv.MORPH_RECT, (horizontal_size, 1))
  verticalStructure = cv.getStructuringElement(cv.MORPH_RECT, (1, verticalsize))
  </code></pre>
  
  <p>But the problem, It detects the line as a rectangle and then draws it in a form of 2 lines representing the 2 sides of the rectangle.</p>
  
  <p>Any ideas to fix that? </p>
  
  <p>The image:<br>
  <a href="https://i.stack.imgur.com/jnCvG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jnCvG.jpg" alt="img"></a></p>
  
  <p>The horizontal result:  </p>
  
  <p><a href="https://i.stack.imgur.com/m0Twh.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m0Twh.jpg" alt="h"></a></p>
  
  <p>The vertical result:                  </p>
  
  <p><a href="https://i.stack.imgur.com/VJCyD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VJCyD.jpg" alt="v"></a></p>
  
  <hr>
  
  <p><strong>EDIT:</strong> That's another image I have:</p>
  
  <p><a href="https://i.stack.imgur.com/dHJ4s.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dHJ4s.jpg" alt="img"></a></p>