Find the center of positive plateaus of rectangular function If I have a rectangular function with irregular positive parts, is there a clever way of finding the center of each positive "plateau"?

The application is, that I threshold a continuous function and want to find the center locations of each segment that is greater than the threshold.
Assume $x(t)$ is your original continuous function. The rectangular function $\pi(t)$ is generated by thresholding, something similar to

$$\pi(t)=1_{x(t)&gt;\gamma}$$

where $\gamma$ is the threshold. Consider one of the rectangular segments of $\pi(t)$ which is between $t=t_a$ and $t=t_b$, where there is an upward edge at $t_a$ and a downward edge at $t_b$. The center point is at $$t_m=t_a+\frac{1}{2}(t_b-t_a)$$
So the problem reduces to finding the upward and downward edges of each rectangular segment. This can be done by looking at the first derivative (or if the functions are discrete, the first difference) of $\pi(t)$. The derivative has positive and negative impulses that correspond to upward and downward edges. In vector notation:

$$\mathbf{t}_a=\{t:\pi'(t)&gt;0\}$$

$$\mathbf{t}_b=\{t:\pi'(t)&lt;0\}$$
$$\mathbf{t}_m=\mathbf{t}_a+\frac{1}{2}(\mathbf{t}_b-\mathbf{t}_a)$$