Split text lines in scanned document
<p>I am trying to find a way to break the split the lines of text in a scanned document that has been adaptive thresholded. Right now, I am storing the pixel values of the document as unsigned ints from 0 to 255, and I am taking the average of the pixels in each line, and I split the lines into ranges based on whether the average of the pixels values is larger than 250, and then I take the median of each range of lines for which this holds. However, this methods sometimes fails, as there can be black splotches on the image.</p>

<p>Is there a more noise-resistant way to do this task?</p>

<p>EDIT: Here is some code. "warped" is the name of the original image, "cuts" is where I want to split the image.</p>

<pre><code>warped = threshold_adaptive(warped, 250, offset = 10)
warped = warped.astype("uint8") * 255

# get areas where we can split image on whitespace to make OCR more accurate
color_level = np.array([np.sum(line) / len(line) for line in warped])
cuts = []
i = 0
while(i &lt; len(color_level)):
    if color_level[i] &gt; 250:
        begin = i
        while(color_level[i] &gt; 250):
            i += 1
        cuts.append((i + begin)/2) # middle of the whitespace region
    else:
        i += 1
</code></pre>

<p>EDIT 2: Sample image added
<a href="https://i.stack.imgur.com/sxRq9.jpg"><img src="https://i.stack.imgur.com/sxRq9.jpg" alt="enter image description here"></a></p>