Centroid

Notes:

Calculate the centroid and slopes for all apertures:
The structure of the return on the function is a row vector of slopes:
[s_x(0,0),.,s_x(0,N),.,s_x(M,0),.,s_x(M,N),s_y(0,0),.,s_y(0,N),.,s_y(M,0),.,s_y(M,N)]

Centroid calculation using thresholding method.

For functionality not a big issue, but if you add this reset at the beginning of the loop, it is easier to read (imho). Then it is more clear what the "state" of the variable mask is when we begin the loop. But that is a personal preference.