How to convert graph to piece wise linear equation?

386 Views Asked by At

In the image processing domain, I come across these graphs.Not sure how these graphs are analysed to derive the constants and the coefficients per the given equation.

Write a function to implement a piecewise linear transform $g(z) = K_1^z+K_2$; $a \le z \le b$.The function takes an input($z$) , coefficients $K_1,K_2$ and intervals $a$,$b$ for each linear segment and produces the transformed output($z$).Produced transformed outputs for the following functions:

enter image description here

1

There are 1 best solutions below

0
On

Suppose you have a line through $(x_1, y_1)$ and $(x_2, y_2)$ and you want to find $m$ and $c$ such that the equation $y = mx+c$ describes that segment.

It's true that $mx_1 + c = y_1$ and $mx_2 + c = y_2$. Solving those two equations for $m$ and $c$ yields $m = \frac{y_2-y_1}{x_2-x_1}$ and $c = y_1 - mx_1$.

So if you have two consecutive vertices $(x_1, y_1)$ to $(x_2, y_2)$ in your graph of some piecewise linear function, then $x \mapsto \frac{y_2-y_1}{x_2-x_1}x + y_1 - \frac{y_2-y_1}{x_2-x_1}x_1$ describes the function in the interval $(x_1, x_2)$.