title: Increase space between text lines in image
body: <p>I have an input image of a paragraph of text in single line spacing. I'm trying to implement something like the line spacing option to increase/decrease space between text lines in Microsoft Word. The current image is in single space, how can I convert the text into double space? Or say <code>.5</code> space? Essentially I'm trying to dynamically restructure the spacing between text lines, preferably with an adjustable parameter. Something like this:</p>
  
  <p>Input image</p>
  
  <p><img src="https://i.stack.imgur.com/bq9X5.png" width="725"></p>
  
  <p>Desired result</p>
  
  <p><img src="https://i.stack.imgur.com/ZkWvS.png" width="725"></p>
  
  <p>My current attempt looks like this. I've been able to increase the spacing slightly but the text detail seems to be eroded and there is random noise in between lines. </p>
  
  <p><img src="https://i.stack.imgur.com/Ci0gO.png" width="725"></p>
  
  <p>Any ideas on how to improve the code or any better approaches?</p>
  
  <pre><code>import numpy as np 
  import cv2
  
  img = cv2.imread('text.png')
  H, W = img.shape[:2]
  grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  threshed = cv2.threshold(grey, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
  
  hist = cv2.reduce(threshed, 1, cv2.REDUCE_AVG).reshape(-1)
  spacing = 2
  delimeter = [y for y in range(H - 1) if hist[y] &lt;= spacing &lt; hist[y + 1]]
  arr = []
  y_prev, y_curr = 0, 0
  for y in delimeter:
      y_prev = y_curr
      y_curr = y
      arr.append(threshed[y_prev:y_curr, 0:W])
  
  arr.append(threshed[y_curr:H, 0:W])
  space_array = np.zeros((10, W))
  result = np.zeros((1, W))
  
  for im in arr:
      v = np.concatenate((space_array, im), axis=0)
      result = np.concatenate((result, v), axis=0)
  
  result = (255 - result).astype(np.uint8)
  cv2.imshow('result', result)
  cv2.waitKey()
  </code></pre>