I would suggest:
1_ loop through the image and whenever you find a pixel whose color is different from the background color, add 4 to the counter(since each pair of lines split the image into 4 parts) and then go through the pair of lines and delete them . Like this the counter will represent number of patches
for the second part where you have to recursively get the colors of lines and arrange them in n*1 image , I'm still thinking about it, Sorry ,>