Threshold function

كيف نبرمج هذه الخوارزميه بماتلاب

Selecting an initial estimate for the global threshold, T.

Segmenting the image using g(x,y) =
f(x)=1 if f(x,y)>T
Or f(x)=1 if f(x,y)<=T
which will produce two groups of pixels G1 consisting of all pixels with intensity values > T,
and G2 consisting of all pixels with values <=T.
. Calculating the mean intensity values m1 and m2 for pixels
in G1 and G2.
( Compute a new threshold value: T =1/2*(m1 + m2
. Repeat steps 2-4 until the mean values and in successive iterations do not change.