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.

isn't it a bit confusing in terms of nomenclature to characterise the 2D Gaussian function with a std. dev. $\sigma$? Sigma already denotes the noise.

Besides, rms is usually written in caps (RMS), and I don't know if you have defined the acronym earlier.