Are you looking for an algorithm to perform the conversion?
The easiest way is to compare each pixel value with a fixed threshold: if the pixel value is less than the threshold value, the corresponding output pixel is black (0), otherwise it is white (1).
If you want to automatically determine the threshold, you can implement the Otsu method. This method does the job as a whole when you cannot make too many assumptions about the distribution of pixels in your image.
http://en.wikipedia.org/wiki/Otsu%27s_Method
As a reference, what it looks like in Mathematica: Binarize[image, threshold] and Binarize[img] for the Otsu method.

source share