Otsu thresholding is a scheme for segmenting a greyscale image into objects and background. You might have dark objects on a light background or light objects on a dark background. The algorithm works out the best cut-off value for separating the two.
int getOtsuthreshold(unsigned char *grey, int width, int height);
The input is a greyscale image. The output is the best vlaue to use for thresholding.
The algorithm works by making a histogram of all 256 possible values. Then it tries each possible threshold value, choosing the one that maximises between-group variance whilst minimising within-group variance.
Here the result of applying thresholding to Lena. In a complex image like Lena it's not so clear which areas are foreground and which are background. But we've got her hat and her skin.
Genrally you will need to further process a thresholded image, by filling in small holes, and smoothing edges.