I have found numerous questions asking about how to find the largest contiguous rectangle in a 2D array, and some that ask for the number of rectangles, but only one that deals with finding the coordinates, width, and height of all of the rectangles required to cover an area of 1s in a 2D of 1s and 0s.
The question (Finding rectangles in a 2d block grid) has a solution but is difficult to follow since it references an external code block.
I am dealing with 2D arrays that make up the pixels of letters:
0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0
0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0
0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0
0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0
0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0
0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0
0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0
0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0
0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0
The desired output here would be something like:
[[4,0,6,17],[7,0,16,2],[7,7,15,9],[7,15,15,17]]
Where each array contains the upper left hand coordinate and lower right hand coordinate (any method that gets upper left and width and height also works).
Could someone provide the psudocode (or Javascript) for either the question previously asked or another algorithm that works, or provide a more in-depth explanation of the steps required?