I'd try something like that

1. Check for existing colours in the image

2. For each existing colour,

Hough-transform[

^] the image to get straight lines (could be tricky if colours actually are gradients)

3. You should now have some equations that represent straight lines. An equation should have two parameters. Find a formula that transforms two sets of such parameters into a distance.

4. Every pair of lines whose distance is less than a threshold (experiment for the value) are indeed segments of the same line. You could use a

clustering algorithm[

^].