What is the right algorithm to detect segmentations of a line chart?
One way to do what you're talking about is called "change point analysis." There is an R package for this called changepoint that you might want to check out. 

In Python, you could try changefinder.