title: article extraction from newspaper image in python and opencv
body: <p><img src="https://i.stack.imgur.com/Hufw0.jpg" alt="first image: this is the image I tried Run length smoothing algorithm horizontal and vertical with some pixel value depends on the dimension of the image" /></p>
  <p><img src="https://i.stack.imgur.com/BlboX.jpg" alt="second image: Another image to extract article by increasing the pixel value but merging with other articles" /></p>
  <p>I tried extracting articles from the newspaper image, but headings are being separated with rlsa algorithm horizontal and vertical of some pixel value in the first image. If I tried with more pixel value, articles are merging which is showed in second image. Can anyone suggest the best method to separate articles from the image in python and opencv?</p>
  <h1>This loop is for run-length-smoothing-algorithm-horizontal on the image</h1>
  <pre><code>    for i in range(1,a):
          c = 1
          for j in range(1, b):
              if im_bw[i, j] == 0:
                  if (j-c) &lt;= 10:
                      im_bw[i, c:j] = 0
                  
                  c = j
              
          
          if (b - c) &lt;= 10:
              im_bw[i, c:b] = 0
      
  </code></pre>
  <h1>This loop is for run-length-smoothing-algorithm-vertical on the image</h1>
  <pre><code>    for i in range(1, b):
          c = 1
          for j in range(1, a):
              if im_bw[j, i] == 0:
                  if (j-c) &lt;= 9:
                      im_bw[c:j, i] = 0
                  
                  c = j
              
          
          if (b - c) &lt;= 9:
              im_bw[c:b, i] = 0
  </code></pre>
  <p>a is number of rows
  b is number of columns of an binary image</p>
  <p>How algorithm worked on binary image and red mark shows the merging of articles</p>
  <p><img src="https://i.stack.imgur.com/AcVCk.png" alt="" /></p>