0

I have a situation where I have a 2D List of indices that each row represent a line.

For example the indices are example of the following:

[[157, 157], [157, 158], [157, 159], [161, 161], [161, 162], [190, 190], [190, 191], [197, 197], [197, 198], [197, 199], [197, 200], [201, 201], [201, 202], [240, 240], [240, 241], [240, 242], [326, 326], [326, 327], [326, 328], [329, 329], [329, 330], [333, 333], [333, 334]]

I convert them to lines using a dictionary using the following, so I detect if there is a jump, I make a new line

char = defaultdict(list)
    coord = ()
    ii = 0
    prev = char_list[0][0]
    for i, j in enumerate(char_list):
        if prev < j[0]:
            prev = j[0]
            ii = ii+1
        else:
            char[ii].append(j)

Then now I have a dictionary of key and lines.

Now I want to make rects out of these lines, I think or I guess that two lines can make a rect.

But don't know the algorithm for that.

I thought about it 1. Min Max of each line ? 2. X location of each line 3. Create rects I think these are the steps... but don't know how to code it for example or prove that's correct ?

That's a picture that I wanna show for visualization of the problem

enter image description here

I grouped the green lines into a dictionary and I want to make rects out of these lines, so that I can cut the original signal image using those rects.

andre
  • 731
  • 2
  • 13
  • 27

0 Answers0