title: Remove parts of image by thickness using opencv and python
body: <p>Due to prior processing steps i have the following image:
  <a href="https://i.stack.imgur.com/GrtDw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GrtDw.png" alt="enter image description here" /></a></p>
  <p>And my task is to remove the parts of the image having thickness under a certain value. To remove those vertical lines, of course, keeping only the text box. Note that <strong>those line can be horizontal as well, but not obliques</strong>.</p>
  <p>I've tried with <code>cv2.erode</code>, but if affects, obviously, every part of the image:</p>
  <pre><code> cv2.erode(masked_text_box, cv2.getStructuringElement(cv2.MORPH_RECT, (2,2) ))
  </code></pre>
  <p>and the text in particular. Being the next step of the pipeline a OCR script, i cannot allow the text to lose sharpness, so maybe a more geometry-based approach could be a better choice.
  Is there a smart way to filter out pixels that have less than <code>N</code> not black pixel in their neighbourhood? <em>Smart</em> meaning not the <code>bruteforce</code> way: for every pixel on the image, check the color of the neighbours, etc...</p>
  <h2>Edit</h2>
  <p>As suggested in the comments box, given that the borders are all in (0, 255, 0) green, for this specific case the simplest solution is to transform those greens in black (0,0,0). Something like this will do the trick:</p>
  <pre><code>masked_text_box[np.all(masked_text_box == (0, 255, 0), axis=-1)] = (0,0,0)
  </code></pre>
  <p>But i'll leave the question open in case of more general or different solution.</p>