How to find the center of rows in a grayscale image of a data table

I have such images I want to draw a red line in every line content like this: If I accumulate the pixel value for every line, I can get the red curve line:

black = ImageRotate[ColorNegate[Import["https://i.stack.imgur.com/skpSZ.png"]]];
data = Plus @@ ImageData[black];
Show[black, ListLinePlot[data, PlotStyle -> Red]] I think the position of the yellow arrow is what I want to find... But how to find it? Of course, I know the number of the line must be 10 in every column. Because the digits are always from 0 to 9. And I have another such images to do such thing..

image2 image3 image4 Not as succinct as I'd hoped, but here it is:

highlight[img_] := Module[
{binary, pixelsPerRow, clusters, diffs, occupied, empty, intervals,
means, imgw, imgh},
pixelsPerRow = Total[ImageData[binary], {2}];
clusters = FindClusters[
pixelsPerRow -> Range@Length[pixelsPerRow], 5,
Method -> "KMeans"
];
diffs = Differences[First[clusters]];
occupied = DeleteCases[diffs, 1];
empty = SequenceCases[diffs, {seq : 1 ..} :> Length[{seq}]];
intervals = Partition[Accumulate@Riffle[empty, occupied], 2];
means = Pick[Mean /@ intervals, EuclideanDistance[##] > 15 & @@@ intervals];
{imgw, imgh} = ImageDimensions[img];
HighlightImage[img, InfiniteLine[{0, imgh - # + 1}, {1, 0}] & /@ means]
]

The basic idea is that rows where there is no text always have the same, or almost the same, number of white pixels. They also have fewer pixels than any other rows. This means that if we cluster the pixel counts per row then the first cluster will consist of the empty rows. We can then use those row numbers to figure out where to put the red lines.

There is a magic number, 15, in this algorithm. Without any correction, this algorithm would have drawn red lines through horizontal white lines because they aren't empty. What the number 15 denotes is that if non-empty sequences of rows are shorter than fifteen rows then they shouldn't be highlighted with red lines.

Examples:

img1 = Import["https://i.stack.imgur.com/aJbkm.png"];
img2 = Import["https://i.stack.imgur.com/hetHU.png"];
img3 = Import["https://i.stack.imgur.com/7CU49.png"];

GraphicsColumn[highlight /@ {img1, img2, img3}, ImageSize -> 400] • How about this? – yode Oct 14 '18 at 6:19
• @yode Doesn't it work, or what? – C. E. Oct 14 '18 at 6:24
• Yes, I will get this result – yode Oct 14 '18 at 6:26
• @yode ok, I see. It was easily fixed by padding the image. I've updated the function. – C. E. Oct 14 '18 at 6:46
• Then img2 will have an extra red line... – yode Oct 14 '18 at 7:10

Just a start to try,

img = Import["https://i.stack.imgur.com/hoCAX.png"] whiteCount = Total /@ ImageData[Binarize@img];
median = Median[whiteCount];
tmp = SplitBy[whiteCount, Sign[# - median] &];
pos = Pick[Accumulate[Length /@ tmp] - 1/2 Length /@ tmp,
Length[#] > 5 && #[] < median & /@ tmp];
dims = ImageDimensions[img];
HighlightImage[img,
Line[{{1, dims[] - #}, {dims[], dims[] - #}} & /@ pos]] But this code cannot success to use in other images.. Because I have use the median as a threshold here...